Skip to content

store git branch on deployments #1286

store git branch on deployments

store git branch on deployments #1286

Workflow file for this run

name: πŸ’« CI
on:
push:
branches: [master]
concurrency:
group: environment-${{ github.ref }}
cancel-in-progress: true
jobs:
setup_env:
name: βš™οΈ Setup environment
runs-on: ubuntu-24.04
steps:
- name: Add SHORT_SHA env property
run: echo "SHORT_SHA=`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV
- name: Put commit msg in environment
run: echo "COMMIT_MSG=${{ github.event.head_commit.message }}" >> $GITHUB_ENV
- name: Escape commit message
run: |
echo "COMMIT_MSG=$(echo $COMMIT_MSG | tr -d \'\\\")" >> $GITHUB_ENV
- name: Get branch name (merge)
if: github.event_name != 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Get branch name (pull request)
if: github.event_name == 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
- name: Set build start in env variable
run: echo "BUILD_START=$(date +%s)" >> $GITHUB_ENV
outputs:
short_sha: ${{ env.SHORT_SHA }}
commit_msg: ${{ env.COMMIT_MSG }}
branch_name: ${{ env.BRANCH_NAME }}
build_start: ${{ env.BUILD_START }}
build:
name: πŸ”¨ Build Binaries and Docker Image
needs: setup_env
strategy:
matrix:
include:
- platform: linux/amd64
runs-on: ubuntu-24.04
arch: amd64
- platform: linux/arm64
runs-on: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.runs-on }}
env:
GITHUB_RUN_ID: ${{ github.run_id }}
steps:
- uses: actions/checkout@v4
- name: Setup Go with cache
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build GO Server Binary
run: |
cd cmd/api && CGO_ENABLED=0 GOARCH=${{ matrix.arch }} go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }} -X \"main.CommitMsg=${{ needs.setup_env.outputs.commit_msg }}\"" -o ./api && cd ../..
- name: Build Oauth Server Binary
run: |
cd cmd/oauth2server && CGO_ENABLED=0 GOARCH=${{ matrix.arch }} go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }} -X \"main.CommitMsg=${{ needs.setup_env.outputs.commit_msg }}\"" -o ./oauth2server && cd ../..
- name: Build CLI Binary
run: |
cd cmd/cli && CGO_ENABLED=0 GOARCH=${{ matrix.arch }} go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }} -X \"main.CommitMsg=${{ needs.setup_env.outputs.commit_msg }}\"" -o ./cli && cd ../..
- name: Build Builder Binary
run: |
cd cmd/builder && CGO_ENABLED=0 GOARCH=${{ matrix.arch }} go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }} -X \"main.CommitMsg=${{ needs.setup_env.outputs.commit_msg }}\"" -o ./builder && cd ../..
- name: Build and push image
if: success()
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
provenance: false
push: true
file: ./Dockerfile.ci
tags: ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-${{ matrix.arch }}
- name: Build and push builder image
if: success()
uses: docker/build-push-action@v5
with:
context: .
provenance: false
platforms: ${{ matrix.platform }}
push: true
file: ./Dockerfile.ci-builder
tags: ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-${{ matrix.arch }}
create_manifest:
name: πŸ“¦ Create Multi-Arch Manifest
runs-on: ubuntu-24.04
needs: [setup_env, build]
env:
GITHUB_RUN_ID: ${{ github.run_id }}
steps:
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push API manifest
run: |
docker manifest create ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} \
--amend ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 \
--amend ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64
docker manifest annotate --arch amd64 --os linux ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64
docker manifest annotate --arch arm64 --os linux ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64
docker manifest push ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}
# Also tag as latest
docker manifest create ghcr.io/unbindapp/unbind-api:latest \
--amend ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 \
--amend ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64
docker manifest annotate --arch amd64 --os linux ghcr.io/unbindapp/unbind-api:latest ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64
docker manifest annotate --arch arm64 --os linux ghcr.io/unbindapp/unbind-api:latest ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64
docker manifest push ghcr.io/unbindapp/unbind-api:latest
- name: Create and push builder manifest
run: |
# Create a new manifest for the builder image
docker manifest create ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} \
--amend ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 \
--amend ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64
docker manifest annotate --arch amd64 --os linux ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64
docker manifest annotate --arch arm64 --os linux ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64
docker manifest push ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}
# Also tag as latest
docker manifest create ghcr.io/unbindapp/unbind-builder:latest \
--amend ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 \
--amend ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64
docker manifest annotate --arch amd64 --os linux ghcr.io/unbindapp/unbind-builder:latest ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64
docker manifest annotate --arch arm64 --os linux ghcr.io/unbindapp/unbind-builder:latest ghcr.io/unbindapp/unbind-builder:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64
docker manifest push ghcr.io/unbindapp/unbind-builder:latest
deploy_prod:
name: πŸš€ Deploy Apps (PROD)
runs-on: ubuntu-24.04
needs:
- setup_env
- create_manifest
env:
GITHUB_RUN_ID: ${{ github.run_id }}
steps:
- uses: actions/checkout@v4
- name: Deploy
uses: ./.github/actions/k8s-deploy
with:
image: ghcr.io/unbindapp/unbind-api:${{ needs.setup_env.outputs.branch_name}}-${{ env.GITHUB_RUN_ID }}
kube_config: ${{ secrets.K3S_KUBE_CONFIG }}