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

ci: migrate publish container workflow to GHA #844

Draft
wants to merge 2 commits into
base: gha-push-pr
Choose a base branch
from
Draft
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
63 changes: 63 additions & 0 deletions .github/workflows/publish-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish container

permissions:
# Needed to assume roles from Github's OIDC.
contents: read
id-token: write
# Needed to push to ghcr.
packages: write

on:
push:
branches:
- 'main'
# FIXME: FOR TESTING ONLY. DELETE BEFORE MERGING.
- 'gha-publish-container'
tags:
- 'v*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: grafana/shared-workflows/actions/dockerhub-login@main
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for the version script to work.
- name: Compute repo metadata
id: repo
run: |-
echo "name=$(basename '${{ github.repository }}')" >> $GITHUB_OUTPUT
echo "version=$(./scripts/version)" >> $GITHUB_OUTPUT
echo "version-short=$(./scripts/version short)" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
# TODO: Make Dockerfile selfcontained. For now we need to build binaries on the host.
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build
run: |
make build
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Build and push container
uses: docker/build-push-action@v6
with:
push: false # FIXME: For testing, should be `true`.
platforms: linux/amd64,linux/arm64
# Needed for this action to use local context incl. binaries built in the previous step.
# https://github.com/docker/build-push-action?tab=readme-ov-file#path-context
# TODO: Make docker build self-contained.
context: .
tags: |-
docker.io/${{ github.repository}}:latest
docker.io/${{ github.repository}}:${{ steps.repo.outputs.version }}
docker.io/${{ github.repository}}:${{ steps.repo.outputs.version-short }}
ghcr.io/${{ github.repository}}:${{ steps.repo.outputs.version-short }}
7 changes: 6 additions & 1 deletion scripts/version
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/bin/sh

git describe --dirty --tags --long --always
args=""
if [ "$1" != "short" ]; then
args="--long"
fi

git describe --dirty --tags --always $args
Loading