From 63d2cbfdaacded86c9b7991d58b77ebca0c587d5 Mon Sep 17 00:00:00 2001 From: Callum Tait <15716903+toast-gear@users.noreply.github.com> Date: Wed, 30 Nov 2022 15:00:16 +0000 Subject: [PATCH] ci: multiple ubuntu version (#2036) * ci: prepare ci for multiple runners * chore: rename dockerfiles * chore: sup multiple os in makefile * chore: changes to support multiple versions * chore: remove test for TARGETPLATFORM * chore: fixes and add individual targets * ci: add latest tag back in * ci: remove latest suffix tag Co-authored-by: toast-gear --- .github/workflows/runners.yaml | 34 ++++++-- runner/Makefile | 83 ++++++++++++++----- ...ner-dind-rootless.ubuntu-20.04.dockerfile} | 4 +- ...tions-runner-dind.ubuntu-20.04.dockerfile} | 4 +- ...=> actions-runner.ubuntu-20.04.dockerfile} | 4 +- runner/startup.sh | 4 + 6 files changed, 99 insertions(+), 34 deletions(-) rename runner/{actions-runner-dind-rootless.dockerfile => actions-runner-dind-rootless.ubuntu-20.04.dockerfile} (98%) rename runner/{actions-runner-dind.dockerfile => actions-runner-dind.ubuntu-20.04.dockerfile} (98%) rename runner/{actions-runner.dockerfile => actions-runner.ubuntu-20.04.dockerfile} (97%) diff --git a/.github/workflows/runners.yaml b/.github/workflows/runners.yaml index 91f1c3143f..851cfb621f 100644 --- a/.github/workflows/runners.yaml +++ b/.github/workflows/runners.yaml @@ -44,12 +44,15 @@ jobs: - name: actions-runner os-name: ubuntu os-version: 20.04 + latest: "true" - name: actions-runner-dind os-name: ubuntu os-version: 20.04 + latest: "true" - name: actions-runner-dind-rootless os-name: ubuntu os-version: 20.04 + latest: "true" steps: - name: Checkout @@ -67,7 +70,7 @@ jobs: uses: docker/build-push-action@v3 with: context: ./runner - file: ./runner/${{ matrix.name }}.dockerfile + file: ./runner/${{ matrix.name }}.${{ matrix.os-name }}-${{ matrix.os-version }}.dockerfile platforms: linux/amd64,linux/arm64 push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} build-args: | @@ -77,9 +80,30 @@ jobs: tags: | ${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }} ${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}-${{ env.sha_short }} - ${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:latest - ghcr.io/${{ github.repository }}/${{ matrix.name }}:latest + ${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:${{ matrix.os-name }}-${{ matrix.os-version }} ghcr.io/${{ github.repository }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }} ghcr.io/${{ github.repository }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}-${{ env.sha_short }} - cache-from: type=gha,scope=build-${{ matrix.name }} - cache-to: type=gha,mode=max,scope=build-${{ matrix.name }} + ghcr.io/${{ github.repository }}/${{ matrix.name }}:${{ matrix.os-name }}-${{ matrix.os-version }} + cache-from: type=gha,scope=build-${{ matrix.name }}-${{ matrix.os-name }}-${{ matrix.os-version }} + cache-to: type=gha,mode=max,scope=build-${{ matrix.name }}-${{ matrix.os-name }}-${{ matrix.os-version }} + + # NOTE : Only to be used on the 20.04 image until we remove the latest tag entirely + # at which point this step needs to be deleted + # https://github.com/actions-runner-controller/actions-runner-controller/issues/2056 + - name: Build and Push Latest Tags + id: ${{ matrix.latest == "true" }} + uses: docker/build-push-action@v3 + with: + context: ./runner + file: ./runner/${{ matrix.name }}.${{ matrix.os-name }}-${{ matrix.os-version }}.dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + build-args: | + RUNNER_VERSION=${{ env.RUNNER_VERSION }} + DOCKER_VERSION=${{ env.DOCKER_VERSION }} + RUNNER_CONTAINER_HOOKS_VERSION=${{ env.RUNNER_CONTAINER_HOOKS_VERSION }} + tags: | + ${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:latest + ghcr.io/${{ github.repository }}/${{ matrix.name }}:latest + cache-from: type=gha,scope=build-${{ matrix.name }}-${{ matrix.os-name }}-${{ matrix.os-version }} + cache-to: type=gha,mode=max,scope=build-${{ matrix.name }}-${{ matrix.os-name }}-${{ matrix.os-version }} diff --git a/runner/Makefile b/runner/Makefile index 249b2877b9..bb07543bad 100644 --- a/runner/Makefile +++ b/runner/Makefile @@ -1,9 +1,9 @@ DOCKER_USER ?= summerwind DOCKER ?= docker -NAME ?= ${DOCKER_USER}/actions-runner +DEFAULT_RUNNER_NAME ?= ${DOCKER_USER}/actions-runner DIND_RUNNER_NAME ?= ${DOCKER_USER}/actions-runner-dind DIND_ROOTLESS_RUNNER_NAME ?= ${DOCKER_USER}/actions-runner-dind-rootless -TAG ?= latest +OS_IMAGE ?= ubuntu-20.04 TARGETPLATFORM ?= $(shell arch) RUNNER_VERSION ?= 2.299.1 @@ -39,33 +39,33 @@ else $(error Supported target platforms: linux/amd64 and linux/arm64) endif -docker-build-ubuntu: check-target-platform +docker-build-set: check-target-platform ${DOCKER} build \ --build-arg TARGETPLATFORM=${TARGETPLATFORM} \ --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ --build-arg RUNNER_CONTAINER_HOOKS_VERSION=${RUNNER_CONTAINER_HOOKS_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ - -f actions-runner.dockerfile \ - -t ${NAME}:${TAG} . + -f actions-runner.${OS_IMAGE}.dockerfile \ + -t ${DEFAULT_RUNNER_NAME}:${OS_IMAGE} . ${DOCKER} build \ --build-arg TARGETPLATFORM=${TARGETPLATFORM} \ --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ - -f actions-runner-dind.dockerfile \ - -t ${DIND_RUNNER_NAME}:${TAG} . + -f actions-runner-dind.${OS_IMAGE}.dockerfile \ + -t ${DIND_RUNNER_NAME}:${OS_IMAGE} . ${DOCKER} build \ --build-arg TARGETPLATFORM=${TARGETPLATFORM} \ --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ - -f actions-runner-dind-rootless.dockerfile \ - -t ${DIND_ROOTLESS_RUNNER_NAME}:${TAG} . + -f actions-runner-dind-rootless.${OS_IMAGE}.dockerfile \ + -t "${DIND_ROOTLESS_RUNNER_NAME}:${OS_IMAGE}" . -docker-push-ubuntu: - ${DOCKER} push ${NAME}:${TAG} - ${DOCKER} push ${DIND_RUNNER_NAME}:${TAG} - ${DOCKER} push ${DIND_ROOTLESS_RUNNER_NAME}:${TAG} +docker-push-set: + ${DOCKER} push "${DEFAULT_RUNNER_NAME}:${OS_IMAGE}" + ${DOCKER} push "${DIND_RUNNER_NAME}:${OS_IMAGE}" + ${DOCKER} push "${DIND_ROOTLESS_RUNNER_NAME}:${OS_IMAGE}" -docker-buildx-ubuntu: +docker-buildx-set: export DOCKER_CLI_EXPERIMENTAL=enabled ;\ export DOCKER_BUILDKIT=1 @if ! docker buildx ls | grep -q container-builder; then\ @@ -75,19 +75,62 @@ docker-buildx-ubuntu: --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ --build-arg RUNNER_CONTAINER_HOOKS_VERSION=${RUNNER_CONTAINER_HOOKS_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ - -f actions-runner.dockerfile \ - -t "${NAME}:${TAG}" \ + -f actions-runner.${OS_IMAGE}.dockerfile \ + -t "${DEFAULT_RUNNER_NAME}:${OS_IMAGE}" \ . ${PUSH_ARG} ${DOCKER} buildx build --platform ${PLATFORMS} \ --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ --build-arg RUNNER_CONTAINER_HOOKS_VERSION=${RUNNER_CONTAINER_HOOKS_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ - -f actions-runner-dind.dockerfile \ - -t "${DIND_RUNNER_NAME}:${TAG}" \ + -f actions-runner-dind.${OS_IMAGE}.dockerfile \ + -t "${DIND_RUNNER_NAME}:${OS_IMAGE}" \ . ${PUSH_ARG} ${DOCKER} buildx build --platform ${PLATFORMS} \ --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ + --build-arg RUNNER_CONTAINER_HOOKS_VERSION=${RUNNER_CONTAINER_HOOKS_VERSION} \ + --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ + -f actions-runner-dind-rootless.${OS_IMAGE}.dockerfile \ + -t "${DIND_ROOTLESS_RUNNER_NAME}:${OS_IMAGE}" \ + . ${PUSH_ARG} + +docker-buildx-default: + export DOCKER_CLI_EXPERIMENTAL=enabled ;\ + export DOCKER_BUILDKIT=1 + @if ! docker buildx ls | grep -q container-builder; then\ + docker buildx create --platform ${PLATFORMS} --name container-builder --use;\ + fi + ${DOCKER} buildx build --platform ${PLATFORMS} \ + --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ + --build-arg RUNNER_CONTAINER_HOOKS_VERSION=${RUNNER_CONTAINER_HOOKS_VERSION} \ + --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ + -f actions-runner.${OS_IMAGE}.dockerfile \ + -t "${DEFAULT_RUNNER_NAME}:${OS_IMAGE}" \ + . ${PUSH_ARG} + +docker-buildx-dind: + export DOCKER_CLI_EXPERIMENTAL=enabled ;\ + export DOCKER_BUILDKIT=1 + @if ! docker buildx ls | grep -q container-builder; then\ + docker buildx create --platform ${PLATFORMS} --name container-builder --use;\ + fi + ${DOCKER} buildx build --platform ${PLATFORMS} \ + --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ + --build-arg RUNNER_CONTAINER_HOOKS_VERSION=${RUNNER_CONTAINER_HOOKS_VERSION} \ + --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ + -f actions-runner-dind.${OS_IMAGE}.dockerfile \ + -t "${DIND_RUNNER_NAME}:${OS_IMAGE}" \ + . ${PUSH_ARG} + +docker-buildx-dind-rootless: + export DOCKER_CLI_EXPERIMENTAL=enabled ;\ + export DOCKER_BUILDKIT=1 + @if ! docker buildx ls | grep -q container-builder; then\ + docker buildx create --platform ${PLATFORMS} --name container-builder --use;\ + fi + ${DOCKER} buildx build --platform ${PLATFORMS} \ + --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ + --build-arg RUNNER_CONTAINER_HOOKS_VERSION=${RUNNER_CONTAINER_HOOKS_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ - -f actions-runner-dind-rootless.dockerfile \ - -t "${DIND_ROOTLESS_RUNNER_NAME}:${TAG}" \ + -f actions-runner-dind-rootless.${OS_IMAGE}.dockerfile \ + -t "${DIND_ROOTLESS_RUNNER_NAME}:${OS_IMAGE}" \ . ${PUSH_ARG} diff --git a/runner/actions-runner-dind-rootless.dockerfile b/runner/actions-runner-dind-rootless.ubuntu-20.04.dockerfile similarity index 98% rename from runner/actions-runner-dind-rootless.dockerfile rename to runner/actions-runner-dind-rootless.ubuntu-20.04.dockerfile index 3062963ac3..7db70c1145 100644 --- a/runner/actions-runner-dind-rootless.dockerfile +++ b/runner/actions-runner-dind-rootless.ubuntu-20.04.dockerfile @@ -11,10 +11,8 @@ ARG DUMB_INIT_VERSION=1.2.5 # Other arguments ARG DEBUG=false -RUN test -n "$TARGETPLATFORM" || (echo "TARGETPLATFORM must be set" && false) - ENV DEBIAN_FRONTEND=noninteractive -RUN apt update -y \ +RUN apt-get update -y \ && apt-get install -y software-properties-common \ && add-apt-repository -y ppa:git-core/ppa \ && apt-get update -y \ diff --git a/runner/actions-runner-dind.dockerfile b/runner/actions-runner-dind.ubuntu-20.04.dockerfile similarity index 98% rename from runner/actions-runner-dind.dockerfile rename to runner/actions-runner-dind.ubuntu-20.04.dockerfile index a46ea278e0..84608acbec 100644 --- a/runner/actions-runner-dind.dockerfile +++ b/runner/actions-runner-dind.ubuntu-20.04.dockerfile @@ -9,10 +9,8 @@ ARG DOCKER_VERSION=20.10.18 ARG DOCKER_COMPOSE_VERSION=v2.6.0 ARG DUMB_INIT_VERSION=1.2.5 -RUN test -n "$TARGETPLATFORM" || (echo "TARGETPLATFORM must be set" && false) - ENV DEBIAN_FRONTEND=noninteractive -RUN apt update -y \ +RUN apt-get update -y \ && apt-get install -y software-properties-common \ && add-apt-repository -y ppa:git-core/ppa \ && apt-get update -y \ diff --git a/runner/actions-runner.dockerfile b/runner/actions-runner.ubuntu-20.04.dockerfile similarity index 97% rename from runner/actions-runner.dockerfile rename to runner/actions-runner.ubuntu-20.04.dockerfile index 181fdb0527..e5f755a22c 100644 --- a/runner/actions-runner.dockerfile +++ b/runner/actions-runner.ubuntu-20.04.dockerfile @@ -9,10 +9,8 @@ ARG DOCKER_VERSION=20.10.18 ARG DOCKER_COMPOSE_VERSION=v2.6.0 ARG DUMB_INIT_VERSION=1.2.5 -RUN test -n "$TARGETPLATFORM" || (echo "TARGETPLATFORM must be set" && false) - ENV DEBIAN_FRONTEND=noninteractive -RUN apt update -y \ +RUN apt-get update -y \ && apt-get install -y software-properties-common \ && add-apt-repository -y ppa:git-core/ppa \ && apt-get update -y \ diff --git a/runner/startup.sh b/runner/startup.sh index f726a7a7f7..f04a169529 100755 --- a/runner/startup.sh +++ b/runner/startup.sh @@ -172,5 +172,9 @@ unset RUNNER_NAME RUNNER_REPO RUNNER_TOKEN STARTUP_DELAY_IN_SECONDS DISABLE_WAIT if [ -z "${UNITTEST:-}" ]; then mapfile -t env