Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic CI for running tests and building containers #2

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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=v0.0.0" >> $GITHUB_OUTPUT
# Use this again once we have a frist release
# 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 push ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64
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
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 }}
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/dist/
/gpu-metrics-agent
73 changes: 73 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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
docker_manifests:
- name_template: ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}
image_templates:
- ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-amd64
- name_template: ghcr.io/polarsignals/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-amd64
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM cgr.dev/chainguard/static:latest
USER root

COPY gpu-metrics-agent /gpu-metrics-agent

ENTRYPOINT ["/gpu-metrics-agent"]
Loading