Build CC-Job-Image-Base #23
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: Build and Update CC-Job-Image-Base | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Docker-Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Setup QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| - name: docker-auth | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| registry: ghcr.io | |
| - name: Set lowercase repository owner | |
| id: repo_owner_lower | |
| run: | | |
| lower_repo_owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]') | |
| echo "lower_repo_owner=$lower_repo_owner" >> $GITHUB_OUTPUT | |
| - name: Build and Push Base Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ghcr.io/${{ steps.repo_owner_lower.outputs.lower_repo_owner }}/cc-utils/job-image-base:latest | |
| file: Dockerfile.job-image-base | |
| update-dockerfile: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| outputs: | |
| docker_version: ${{ steps.get_docker_version.outputs.docker_version }} | |
| buildx_version: ${{ steps.get_buildx_version.outputs.buildx_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Git Identity | |
| run: | | |
| git config --global --add safe.directory $PWD | |
| git config --global user.name 'Gardener-CICD Bot' | |
| git config --global user.email 'gardener.ci.user@gmail.com' | |
| - name: Get latest Docker version | |
| id: get_docker_version | |
| run: | | |
| greatest_version=$(curl -sL https://download.docker.com/linux/static/stable/x86_64/ \ | |
| | cut -d\" -f2 \ | |
| | grep "docker-[[:digit:]]" \ | |
| | cut -d- -f2 \ | |
| | cut -d. -f1,2,3 \ | |
| | sort -Vr \ | |
| | head -1) | |
| echo "docker_version=$greatest_version" >> $GITHUB_OUTPUT | |
| - name: Get latest Buildx version | |
| id: get_buildx_version | |
| run: | | |
| greatest_version=$(curl -sL https://api.github.com/repos/docker/buildx/releases/ \ | |
| -H 'Accept: application/json' \ | |
| | jq -r .[].tag_name \ | |
| | sort -Vr \ | |
| | head -1) | |
| echo "buildx_version=$greatest_version" >> $GITHUB_OUTPUT | |
| - name: Update Dockerfile | |
| run: | | |
| sed -i "s/DOCKER_VERSION=.*/DOCKER_VERSION=${{ steps.get_docker_version.outputs.docker_version }}/" Dockerfile.job-image-base | |
| sed -i "s/DOCKER_BUILDX_VERSION=.*/DOCKER_BUILDX_VERSION=${{ steps.get_buildx_version.outputs.buildx_version }}/" Dockerfile.job-image-base | |
| git add Dockerfile.job-image-base | |
| git commit -m "Update Dockerfile to use Docker ${{ steps.get_docker_version.outputs.docker_version }} and \ | |
| Buildx ${{ steps.get_buildx_version.outputs.buildx_version }}" | |
| git checkout -b update-dockerfile | |
| git push origin update-dockerfile --force | |
| - name: Create Pull Request | |
| run: | | |
| gh pr create \ | |
| -B master \ | |
| -H update-dockerfile \ | |
| --title "Update Dockerfile with latest Docker and Buildx versions" \ | |
| --body "Updates the Dockerfile to use the latest versions: | |
| - Docker: `${{ steps.get_docker_version.outputs.docker_version }}` | |
| - Buildx: `${{ steps.get_buildx_version.outputs.buildx_version }}`" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |