Build Runner Image #62
This file contains 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 Runner Image | |
on: | |
workflow_dispatch: | |
inputs: | |
github-runner-version: | |
description: 'Version on github runner(in https://github.com/actions/runner), e.g: 2.309.0' | |
required: true | |
default: '2.309.0' | |
jobs: | |
build-images: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: | |
platform: [amd64, arm64] | |
code_name: [focal, jammy] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: knatnetwork | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: knatnetwork | |
password: ${{ secrets.DOCKERHUB_PASSWD }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ matrix.platform }}-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx-${{ matrix.platform }} | |
- name: Build and push ${{ github.event.inputs.github-runner-version }} ${{ matrix.platform }} Version | |
uses: docker/build-push-action@v3 | |
with: | |
context: ./${{ matrix.code_name }}-${{ matrix.platform }}/ | |
file: ./${{ matrix.code_name }}-${{ matrix.platform }}/Dockerfile | |
platforms: linux/${{ matrix.platform }} | |
push: true | |
provenance: false | |
sbom: false | |
build-args: GITHUB_RUNNER_VERSION=${{ github.event.inputs.github-runner-version }} | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ matrix.code_name }}-${{ github.event.inputs.github-runner-version }}-${{ matrix.platform }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
combine-two-images: | |
runs-on: ubuntu-latest | |
needs: | |
- build-images | |
steps: | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: knatnetwork | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: knatnetwork | |
password: ${{ secrets.DOCKERHUB_PASSWD }} | |
- name: Get regctl | |
run: | | |
wget -q https://github.com/regclient/regclient/releases/download/v0.5.1/regctl-linux-amd64 | |
chmod +x regctl-linux-amd64 | |
- name: Combine two images on GHCR and sync to DockerHub | |
run: | | |
docker manifest create ghcr.io/${{ github.repository }}:focal-${{ github.event.inputs.github-runner-version }} --amend ghcr.io/${{ github.repository }}:focal-${{ github.event.inputs.github-runner-version }}-amd64 --amend ghcr.io/${{ github.repository }}:focal-${{ github.event.inputs.github-runner-version }}-arm64 | |
docker manifest push ghcr.io/${{ github.repository }}:focal-${{ github.event.inputs.github-runner-version }} | |
docker manifest create ghcr.io/${{ github.repository }}:jammy-${{ github.event.inputs.github-runner-version }} --amend ghcr.io/${{ github.repository }}:jammy-${{ github.event.inputs.github-runner-version }}-amd64 --amend ghcr.io/${{ github.repository }}:jammy-${{ github.event.inputs.github-runner-version }}-arm64 | |
docker manifest push ghcr.io/${{ github.repository }}:jammy-${{ github.event.inputs.github-runner-version }} | |
./regctl-linux-amd64 image copy ghcr.io/${{ github.repository }}:focal-${{ github.event.inputs.github-runner-version }} ${{ github.repository }}:focal-${{ github.event.inputs.github-runner-version }} -v info | |
./regctl-linux-amd64 image copy ghcr.io/${{ github.repository }}:jammy-${{ github.event.inputs.github-runner-version }} ${{ github.repository }}:jammy-${{ github.event.inputs.github-runner-version }} -v info | |
- name: Update image latest tag | |
run: | | |
./regctl-linux-amd64 image copy ghcr.io/${{ github.repository }}:jammy-${{ github.event.inputs.github-runner-version }} ${{ github.repository }}:latest -v info | |
./regctl-linux-amd64 image copy ghcr.io/${{ github.repository }}:jammy-${{ github.event.inputs.github-runner-version }} ghcr.io/${{ github.repository }}:latest -v info |