name: Build Docker Image on: push: tags: - '*' jobs: build-and-push-image: name: Docker Build runs-on: self-hosted permissions: contents: read packages: write steps: - name: Set version id: version run: echo "::set-output name=version::$(echo ${GITHUB_REF#refs/tags/})" - name: Check out the repo uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Cache Docker layers uses: actions/cache@v3 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx- - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }} - name: Generate build variables id: prep run: | echo "built_at=$(date +%Y-%m-%dT%H:%M:%S)" >> $GITHUB_OUTPUT echo "go_version=$(go version | cut -d ' ' -f 3)" >> $GITHUB_OUTPUT echo "git_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache build-args: | BuiltAt=${{ steps.prep.outputs.built_at }} GoVersion=${{ steps.prep.outputs.go_version }} GitCommit=${{ steps.prep.outputs.git_commit }} Version=${{ steps.version.outputs.version }} - name: Extract metadata (tags, labels) for Docker if: startsWith(github.ref, 'refs/tags/v') id: publicmeta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }}-testing - name: Build and push Docker image if: startsWith(github.ref, 'refs/tags/v') uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.publicmeta.outputs.tags }} labels: ${{ steps.publicmeta.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache build-args: | BuiltAt=$(date +%Y-%m-%dT%H:%M:%S) GoVersion=$(go version) GitCommit=$(git rev-parse HEAD) Version=${{ steps.version.outputs.version }}