From d46dd663bf0997d842f6d4c286c97d7ad18ec39b Mon Sep 17 00:00:00 2001 From: Alex Lovell-Troy Date: Tue, 29 Oct 2024 12:04:03 -0400 Subject: [PATCH 1/5] Build Improvements * Simpler multiarch builds * use AMD64 v4 rather than v1 * Add packages, rpm, deb, apk * Simplify Dockerfile * Improve clarity of Github actions --- .github/workflows/PRBuild.yml | 7 ++++- .github/workflows/Release.yml | 7 ++++- .goreleaser.yaml | 52 +++++++++++++++++++++++++++-------- Dockerfile | 6 ++-- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/.github/workflows/PRBuild.yml b/.github/workflows/PRBuild.yml index e6dbed2..bfb8e08 100644 --- a/.github/workflows/PRBuild.yml +++ b/.github/workflows/PRBuild.yml @@ -10,7 +10,12 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Set up Go 1.23 + - name: Install cross-compilation tools + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - name: Set up latest stable Go uses: actions/setup-go@v5 with: go-version: 1.23 diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 78efbcb..efa2c2b 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -11,7 +11,12 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Set up Go 1.23 + - name: Install cross-compilation tools + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - name: Set up latest stable Go uses: actions/setup-go@v5 with: go-version: 1.23 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index de74958..708ba95 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,7 +1,4 @@ -# This is an example .goreleaser.yml file with some sensible defaults. -# Make sure to check the documentation at https://goreleaser.com version: 2 - project_name: smd before: hooks: @@ -30,34 +27,47 @@ builds: goos: - linux - darwin + - windows goarch: - amd64 - arm64 - tags: - - musl - + goamd64: + - v4 + env: + - CGO_ENABLED=0 + - id: smd-init main: ./cmd/smd-init/ binary: smd-init goos: - linux - darwin + - windows goarch: - amd64 - arm64 - tags: - - musl + goamd64: + - v4 + + env: + - CGO_ENABLED=0 + + - id: smd-loader main: ./cmd/smd-loader/ binary: smd-loader goos: - linux - darwin + - windows goarch: - amd64 - arm64 - tags: - - musl + goamd64: + - v4 + + env: + - CGO_ENABLED=0 dockers: - image_templates: @@ -73,6 +83,7 @@ dockers: - "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.version={{.Version}}" goarch: amd64 + goamd64: v4 extra_files: - LICENSE - CHANGELOG.md @@ -134,7 +145,26 @@ archives: - CHANGELOG.md - README.md - +nfpms: + - id: smd + formats: + - deb + - rpm + - apk + maintainer: "Alex Lovell-Troy " + description: "SMD is a tool for managing the inventory of an HPC system. Read more at https://www.openchami.org" + homepage: "https://www.openchami.org" + license: MIT + section: utils + priority: optional + contents: + - src: dist/smd_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else }}{{ .Arch }}{{ end }}/smd + dst: /usr/local/bin/smd + - src: dist/smd-init_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else }}{{ .Arch }}{{ end }}/smd-init + dst: /usr/local/bin/smd-init + - src: dist/smd-loader_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else }}{{ .Arch }}{{ end }}/smd-loader + dst: /usr/local/bin/smd-loader + checksum: name_template: 'checksums.txt' snapshot: diff --git a/Dockerfile b/Dockerfile index f9d1394..c58bc44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,10 @@ RUN apk add --no-cache tini # Include curl in the final image. RUN set -ex \ - && apk -U upgrade \ - && apk add --no-cache curl + && apk update \ + && apk add --no-cache curl tini \ + && rm -rf /var/cache/apk/* \ + && rm -rf /tmp/* COPY smd / COPY smd-loader / From 72974dd0ca52e38bf16d3c685a77d6a52f64c192 Mon Sep 17 00:00:00 2001 From: Alex Lovell-Troy Date: Tue, 29 Oct 2024 10:54:13 -0600 Subject: [PATCH 2/5] Adding golangci-lint --- .github/workflows/GolangCI-Lint.yml | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/GolangCI-Lint.yml diff --git a/.github/workflows/GolangCI-Lint.yml b/.github/workflows/GolangCI-Lint.yml new file mode 100644 index 0000000..c854481 --- /dev/null +++ b/.github/workflows/GolangCI-Lint.yml @@ -0,0 +1,41 @@ +name: golangci-lint + +on: + pull_request: + push: + branches: + - "main" + +env: + GO_VERSION: stable + GOLANGCI_LINT_VERSION: v1.60 + +jobs: + detect-modules: + runs-on: ubuntu-latest + outputs: + modules: ${{ steps.set-modules.outputs.modules }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - id: set-modules + run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT + + golangci-lint: + needs: detect-modules + runs-on: ubuntu-latest + strategy: + matrix: + modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: golangci-lint ${{ matrix.modules }} + uses: golangci/golangci-lint-action@v6 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + working-directory: ${{ matrix.modules }} \ No newline at end of file From 1ae7c919689c5cd7dc1ade0c6508612cf94eddc8 Mon Sep 17 00:00:00 2001 From: Alex Lovell-Troy Date: Tue, 29 Oct 2024 10:57:24 -0600 Subject: [PATCH 3/5] removing the linter because we're not ready --- .github/workflows/GolangCI-Lint.yml | 41 ----------------------------- 1 file changed, 41 deletions(-) delete mode 100644 .github/workflows/GolangCI-Lint.yml diff --git a/.github/workflows/GolangCI-Lint.yml b/.github/workflows/GolangCI-Lint.yml deleted file mode 100644 index c854481..0000000 --- a/.github/workflows/GolangCI-Lint.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: golangci-lint - -on: - pull_request: - push: - branches: - - "main" - -env: - GO_VERSION: stable - GOLANGCI_LINT_VERSION: v1.60 - -jobs: - detect-modules: - runs-on: ubuntu-latest - outputs: - modules: ${{ steps.set-modules.outputs.modules }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - id: set-modules - run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT - - golangci-lint: - needs: detect-modules - runs-on: ubuntu-latest - strategy: - matrix: - modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - name: golangci-lint ${{ matrix.modules }} - uses: golangci/golangci-lint-action@v6 - with: - version: ${{ env.GOLANGCI_LINT_VERSION }} - working-directory: ${{ matrix.modules }} \ No newline at end of file From ceeb77a19ce4d15433e0f88d4ddb22c8bb7bf0c9 Mon Sep 17 00:00:00 2001 From: Alex Lovell-Troy Date: Fri, 8 Nov 2024 08:54:40 -0500 Subject: [PATCH 4/5] chore: update goreleaser and add relevant notes --- .goreleaser.yaml | 11 +++++++---- README.md | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index b3f856b..26d7ffc 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,4 +1,4 @@ -version: 2 +version: 2.4 project_name: smd before: hooks: @@ -32,6 +32,7 @@ builds: - arm64 goamd64: - v4 + env: - CGO_ENABLED=0 @@ -85,6 +86,7 @@ builds: goamd64: - v4 + env: - CGO_ENABLED=0 @@ -103,6 +105,7 @@ dockers: - "--label=org.opencontainers.image.version={{.Version}}" goarch: amd64 goamd64: v4 + extra_files: - LICENSE - CHANGELOG.md @@ -177,11 +180,11 @@ nfpms: section: utils priority: optional contents: - - src: dist/smd_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else }}{{ .Arch }}{{ end }}/smd + - src: dist/smd_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else if eq .Arch "arm64" }}{{ .Arch }}_{{ .Arm64 }}{{ else }}{{ .Arch }}{{ end }}/smd dst: /usr/local/bin/smd - - src: dist/smd-init_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else }}{{ .Arch }}{{ end }}/smd-init + - src: dist/smd-init_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else if eq .Arch "arm64" }}{{ .Arch }}_{{ .Arm64 }}{{ else }}{{ .Arch }}{{ end }}/smd-init dst: /usr/local/bin/smd-init - - src: dist/smd-loader_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else }}{{ .Arch }}{{ end }}/smd-loader + - src: dist/smd-loader_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else if eq .Arch "arm64" }}{{ .Arch }}_{{ .Arm64 }}{{ else }}{{ .Arch }}{{ end }}/smd-loader dst: /usr/local/bin/smd-loader checksum: diff --git a/README.md b/README.md index 7b7728e..4300a7a 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,13 @@ Once the environment variables are set, you can build the project locally using Follow the installation instructions from [GoReleaser’s documentation](https://goreleaser.com/install/). -1. Run GoReleaser in snapshot mode with the --snapshot and --skip-publish flags to create a local build without attempting to release it: +1. Run GoReleaser in snapshot mode with the --snapshot flag to create a local build without attempting to release it: ```bash - goreleaser release --snapshot --skip-publish --clean + goreleaser release --snapshot --clean ``` 2. Check the dist/ directory for the built binaries, which will include the metadata from the environment variables. You can inspect the binary output to confirm that the metadata was correctly embedded. +__NOTE__ If you see errors, ensure that you are using the same version of goreleaser that is being used in the [Release Action](.github/workflows/Release.yml) The rest of this README is unchanged from the HPE version. From 737bf72d7c780ee7c4d294b9b61f649349cf278c Mon Sep 17 00:00:00 2001 From: Alex Lovell-Troy Date: Thu, 14 Nov 2024 09:34:33 -0500 Subject: [PATCH 5/5] switch from amd64_v4 to amd64_v3 for compatibility --- .github/workflows/Release.yml | 12 ++++++------ .goreleaser.yaml | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index f2560a7..edf31f3 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -66,32 +66,32 @@ jobs: - name: Attest smd binary linux_amd64 uses: actions/attest-build-provenance@v1 with: - subject-path: dist/smd_linux_amd64_v1/smd + subject-path: dist/smd_linux_amd64_v3/smd - name: Attest smd-init binary linux_amd64 uses: actions/attest-build-provenance@v1 with: - subject-path: dist/smd-init_linux_amd64_v1/smd-init + subject-path: dist/smd-init_linux_amd64_v3/smd-init - name: Attest smd-loader binary linux_amd64 uses: actions/attest-build-provenance@v1 with: - subject-path: dist/smd-loader_linux_amd64_v1/smd-loader + subject-path: dist/smd-loader_linux_amd64_v3/smd-loader - name: Attest smd binary linux_arm64 uses: actions/attest-build-provenance@v1 with: - subject-path: dist/smd_linux_arm64/smd + subject-path: dist/smd_linux_arm64_v8.0/smd - name: Attest smd-init binary linux_arm64 uses: actions/attest-build-provenance@v1 with: - subject-path: dist/smd-init_linux_arm64/smd-init + subject-path: dist/smd-init_linux_arm64_v8.0/smd-init - name: Attest smd-loader binary linux_arm64 uses: actions/attest-build-provenance@v1 with: - subject-path: dist/smd-loader_linux_arm64/smd-loader + subject-path: dist/smd-loader_linux_arm64_v8.0/smd-loader - name: generate build provenance of docker container uses: actions/attest-build-provenance@v1 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 26d7ffc..6025b45 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -31,7 +31,7 @@ builds: - amd64 - arm64 goamd64: - - v4 + - v3 env: - CGO_ENABLED=0 @@ -57,7 +57,7 @@ builds: - amd64 - arm64 goamd64: - - v4 + - v3 env: - CGO_ENABLED=0 @@ -84,7 +84,7 @@ builds: - amd64 - arm64 goamd64: - - v4 + - v3 env: @@ -104,7 +104,7 @@ dockers: - "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.version={{.Version}}" goarch: amd64 - goamd64: v4 + goamd64: v3 extra_files: - LICENSE