Publish release Docker images per binary #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - '[0-9]*.[0-9]*.[0-9]*' | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| release: | |
| name: Build and publish release artifacts | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: Run Go tests | |
| run: go test ./... | |
| - name: Validate Docker Compose config | |
| run: | | |
| set -euo pipefail | |
| if docker compose version >/dev/null 2>&1; then | |
| docker compose -f deploy/compose.yaml config >/dev/null | |
| else | |
| echo "Docker Compose is unavailable; skipping compose config validation." | |
| fi | |
| - name: Build release artifacts | |
| env: | |
| TAG_NAME: ${{ github.ref_name }} | |
| run: | | |
| set -euo pipefail | |
| commands=(edge-gateway private-connector signurl) | |
| targets=( | |
| linux/amd64 | |
| linux/arm64 | |
| darwin/amd64 | |
| darwin/arm64 | |
| windows/amd64 | |
| windows/arm64 | |
| ) | |
| mkdir -p build dist | |
| for command in "${commands[@]}"; do | |
| for target in "${targets[@]}"; do | |
| goos="${target%/*}" | |
| goarch="${target#*/}" | |
| extension="" | |
| if [[ "${goos}" == "windows" ]]; then | |
| extension=".exe" | |
| fi | |
| binary_path="build/${command}-${goos}-${goarch}${extension}" | |
| archive_name="air3-${command}-${TAG_NAME}-${goos}-${goarch}.tar.gz" | |
| package_dir="$(mktemp -d)" | |
| echo "Building ${command} for ${goos}/${goarch}" | |
| env CGO_ENABLED=0 GOOS="${goos}" GOARCH="${goarch}" \ | |
| go build -trimpath -ldflags="-s -w" -o "${binary_path}" "./cmd/${command}" | |
| cp "${binary_path}" "${package_dir}/${command}${extension}" | |
| tar -C "${package_dir}" -czf "dist/${archive_name}" "${command}${extension}" | |
| rm -rf "${package_dir}" | |
| done | |
| done | |
| - name: Generate checksums | |
| run: | | |
| set -euo pipefail | |
| cd dist | |
| sha256sum *.tar.gz > SHA256SUMS | |
| - name: Upload workflow artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: air3-${{ github.ref_name }}-release-artifacts | |
| path: dist/* | |
| if-no-files-found: error | |
| - name: Create or update GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG_NAME: ${{ github.ref_name }} | |
| run: | | |
| set -euo pipefail | |
| if gh release view "${TAG_NAME}" >/dev/null 2>&1; then | |
| gh release edit "${TAG_NAME}" --title "${TAG_NAME}" --notes "Release ${TAG_NAME}" | |
| gh release upload "${TAG_NAME}" dist/* --clobber | |
| else | |
| gh release create "${TAG_NAME}" dist/* --title "${TAG_NAME}" --notes "Release ${TAG_NAME}" | |
| fi | |
| docker-images: | |
| name: Build and publish ${{ matrix.app }} image | |
| runs-on: ubuntu-latest | |
| needs: release | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| app: | |
| - edge-gateway | |
| - private-connector | |
| - signurl | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Prepare image name | |
| id: image | |
| env: | |
| REPOSITORY: ${{ github.repository }} | |
| APP: ${{ matrix.app }} | |
| run: | | |
| set -euo pipefail | |
| repository="${REPOSITORY,,}" | |
| echo "name=ghcr.io/${repository}/${APP}" >> "${GITHUB_OUTPUT}" | |
| - name: Build and push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| build-args: | | |
| APP=${{ matrix.app }} | |
| tags: | | |
| ${{ steps.image.outputs.name }}:${{ github.ref_name }} | |
| labels: | | |
| org.opencontainers.image.title=air3 ${{ matrix.app }} | |
| org.opencontainers.image.description=air3 ${{ matrix.app }} release image | |
| org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.version=${{ github.ref_name }} |