diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..91600da --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,78 @@ +name: Artifacts + +on: + pull_request: + branches: + - main + push: + tags: + - v* + branches: + - '**' + +jobs: + artifacts: + name: Goreleaser release + runs-on: ubuntu-latest + permissions: + packages: write + contents: write + container: + image: docker.io/goreleaser/goreleaser-cross:v1.22.4 + options: --privileged + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out the code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # https://github.com/actions/checkout/issues/766 + - name: Add repository directory to the git global config as a safe directory + run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Fetch all tags + run: git fetch --force --tags + + - name: Login to registry + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/') + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Login to registry + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Run Goreleaser release + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + run: goreleaser release --clean --verbose + + - name: Run Goreleaser snapshot + run: | + goreleaser release --clean --verbose --snapshot + + - name: Set snapshot tag + id: vars + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/') + run: | + echo "tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "git_tag=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT + + - name: Push snapshot images + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/') + run: | + docker tag ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.git_tag }}-amd64 ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64 + docker tag ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.git_tag }}-arm64 ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-arm64 + docker push ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64 + docker push ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-arm64 + docker manifest create ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }} --amend ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64 --amend ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-arm64 + docker manifest annotate ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }} ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-arm64 --os linux --arch arm64 + docker manifest annotate ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }} ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64 --os linux --arch amd64 + docker manifest push ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..13e2eb4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Test + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Check out the code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Run Tests + run: go test -race -v ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..128f1b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/dist/ +/gpu-metrics-agent diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..d4ccc27 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,89 @@ +version: 2 +builds: + - id: linux-amd64 + main: ./ + binary: gpu-metrics-agent + goos: + - linux + goarch: + - amd64 + flags: + - -mod=readonly + - -trimpath + - -v + ldflags: + # https://goreleaser.com/customization/build/#reproducible-builds + # {{.CommitDate}} is the date of the commit to make builds reproducible. + - -X main.version={{.Version}} -X main.commit={{.FullCommit}} -X main.date={{.CommitDate}} -X main.goArch=amd64 + tags: + - osusergo + - netgo +archives: + - name_template: >- + {{ .ProjectName }}_ + {{- trimprefix .Version "v" }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "arm64" }}aarch64 + {{- else }}{{ .Arch }}{{ end }} + format: binary + format_overrides: + - goos: windows + format: zip + files: + - 'LICENSE*' + - 'README*' +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Branch }}-{{ .ShortCommit }}" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +release: + github: + owner: polarsignals + name: gpu-metrics-agent + prerelease: auto + draft: false + name_template: '{{ .Tag }}' +dockers: +- image_templates: ["ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-amd64"] + dockerfile: Dockerfile + use: buildx + build_flag_templates: + - --pull + - --platform=linux/amd64 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://polarsignals.com + - --label=org.opencontainers.image.source=https://github.com/polarsignals/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Tag }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=Apache-2.0 +- image_templates: ["ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-arm64"] + goarch: arm64 + dockerfile: Dockerfile + use: buildx + build_flag_templates: + - --pull + - --platform=linux/arm64 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://polarsignals.com + - --label=org.opencontainers.image.source=https://github.com/polarsignals/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Tag }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=Apache-2.0 +docker_manifests: +- name_template: ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }} + image_templates: + - ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-amd64 + - ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-arm64 +- name_template: ghcr.io/polarsignals/{{ .ProjectName }}:latest + image_templates: + - ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-amd64 + - ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-arm64 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..26122b7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM cgr.dev/chainguard/static:latest +USER root + +COPY ./dist/linux-amd64_linux_amd64_v1/gpu-metrics-agent /gpu-metrics-agent + +ENTRYPOINT ["/gpu-metrics-agent"]