Sync Go Images #355
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: Sync Go Images | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| - 'test-**' | |
| schedule: | |
| - cron: '0 0 * * *' | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| IMAGE_REGISTRY: ghcr.io | |
| GO_BUILDER_REGISTRY: ${{ github.repository }}/go-builder | |
| GO_RUNTIME_REGISTRY: ${{ github.repository }}/go-runtime | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_build: ${{ steps.check.outputs.should_build }} | |
| version: ${{ steps.check.outputs.version }} | |
| steps: | |
| - name: Check version and image | |
| id: check | |
| run: | | |
| LATEST_GO_VERSION=$(curl -s 'https://go.dev/VERSION?m=text' | head -n 1 | cut -c 3-) | |
| echo "Latest go version is $LATEST_GO_VERSION" | |
| echo "version=$LATEST_GO_VERSION" >> $GITHUB_OUTPUT | |
| GO_BUILDER_IMAGE_TAG="${IMAGE_REGISTRY}/${GO_BUILDER_REGISTRY}:v${LATEST_GO_VERSION}" | |
| GO_RUNTIME_IMAGE_TAG="${IMAGE_REGISTRY}/${GO_RUNTIME_REGISTRY}:v${LATEST_GO_VERSION}" | |
| echo "GO_BUILDER_IMAGE_TAG:${GO_BUILDER_IMAGE_TAG}" | |
| echo "GO_RUNTIME_IMAGE_TAG:${GO_RUNTIME_IMAGE_TAG}" | |
| if docker manifest inspect ${GO_BUILDER_IMAGE_TAG} >/dev/null 2>&1 && | |
| docker manifest inspect ${GO_RUNTIME_IMAGE_TAG} >/dev/null 2>&1 ; then | |
| echo "should_build=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| fi | |
| build: | |
| needs: check | |
| if: github.event_name == 'workflow_dispatch' || needs.check.outputs.should_build == 'true' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| image: [ 'go-builder', 'go-runtime' ] | |
| include: | |
| - image: 'go-builder' | |
| dockerfile: 'go-builder/Dockerfile' | |
| context: 'go-builder' | |
| registry_suffix: go-builder | |
| - image: 'go-runtime' | |
| dockerfile: 'go-runtime/Dockerfile' | |
| context: 'go-runtime' | |
| registry_suffix: go-runtime | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.IMAGE_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| timeout-minutes: 120 | |
| with: | |
| context: ${{ matrix.context }} | |
| file: ${{ matrix.dockerfile }} | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| build-args: | | |
| VERSION=${{ needs.check.outputs.version }} | |
| tags: | | |
| ${{ env.IMAGE_REGISTRY }}/${{ github.repository }}/${{ matrix.registry_suffix }}:v${{ needs.check.outputs.version }} | |
| ${{ env.IMAGE_REGISTRY }}/${{ github.repository }}/${{ matrix.registry_suffix }}:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| labels: | | |
| org.opencontainers.image.title=${{ matrix.image }} | |
| org.opencontainers.image.description=Go ${{ needs.check.outputs.version }} ${{ matrix.image }} image | |
| org.opencontainers.image.version=${{ needs.check.outputs.version }} | |
| org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} | |
| org.opencontainers.image.revision=${{ github.sha }} |