Build CC-Job-Image-Base #42
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: read | |
| packages: write | |
| outputs: | |
| version: ${{ steps.read_version.outputs.version }} | |
| 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: Read Version | |
| id: read_version | |
| run: | | |
| version=$(cat VERSION_CC_JOB_IMAGE_BASE) | |
| echo "version=$version" >> $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:${{ steps.read_version.outputs.version }} | |
| file: Dockerfile.job-image-base | |
| update-dockerfile: | |
| 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 | |
| uses: ./.github/actions/setup-git-identity | |
| - 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: | | |
| if gh pr view -B master -H update-dockerfile > /dev/null 2>&1; then | |
| echo "Pull request already exists for update-dockerfile -> master." | |
| else | |
| 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 }}" | |
| fi || true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| update-base-image-version: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| outputs: | |
| new_version: ${{ steps.update_version.outputs.new_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Git Identity | |
| uses: ./.github/actions/setup-git-identity | |
| - name: Update Base Image and Increment Version | |
| id: update_version | |
| run: | | |
| current_version=$(cat VERSION_CC_JOB_IMAGE_BASE) | |
| sed -i "s|^ARG BASE_IMAGE=.*|ARG BASE_IMAGE=ghcr.io/${{ github.repository_owner }}/cc-utils/job-image-base:$current_version|" Dockerfile | |
| new_version=$(echo $current_version | awk -F. '{printf "%d.%d.%d", $1, $2+1, $3}') | |
| echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
| echo "$new_version" > VERSION_CC_JOB_IMAGE_BASE | |
| git add Dockerfile VERSION_CC_JOB_IMAGE_BASE | |
| git commit -m "Update job-image to use job-image-base version $current_version and prepare for $new_version" | |
| git checkout -b update-base-image | |
| git push origin update-base-image --force | |
| - name: Create Pull Request | |
| run: | | |
| if gh pr view -B master -H update-base-image > /dev/null 2>&1; then | |
| echo "Pull request already exists for update-base-image -> master." | |
| else | |
| gh pr create \ | |
| -B master \ | |
| -H update-base-image \ | |
| --title "Update job-image to use job-image-base version ${{ needs.build-and-push.outputs.version }}" \ | |
| --body "Updates the job-image to use the latest job-image-base version: | |
| - Base Image Version: ${{ needs.build-and-push.outputs.version }}. | |
| - Also increments the version for the next release to ${{ steps.update_version.outputs.new_version }}." | |
| fi || true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |