From 51642c65d5056c124fffed225944f72d82be469c Mon Sep 17 00:00:00 2001 From: Darksome Date: Mon, 22 Apr 2024 14:08:38 +0000 Subject: [PATCH] feat: custom runner image --- .github/workflows/ci.yaml | 99 +++++++++++++++++++++++++++++++++++++++ Dockerfile | 5 ++ 2 files changed, 104 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..99eeaa5 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,99 @@ +name: ci +on: + push: + branches: ["main"] + paths: + - "Dockerfile" +concurrency: + # Support push/pr as event types with different behaviors each: + # 1. push: queue up builds + # 2. pr: only allow one run per PR + group: ${{ github.workflow }}-${{ github.event_name }}${{ github.event.pull_request.number }} + # If there is already a workflow running for the same pull request, cancel it + cancel-in-progress: ${{ github.event_name == 'pull_request' }} +env: + AWS_REGION: "eu-central-1" +jobs: + build: + name: "Build image: ${{ matrix.images.name }}" + runs-on: + group: ubuntu-runners + strategy: + fail-fast: false + matrix: + images: + - name: github-actions-runner + dockerfile: ./Dockerfile + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-central-1 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ steps.login-ecr.outputs.registry }}/${{ matrix.images.name }} + flavor: | + latest=auto + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=sha + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build, tag and cache the image + uses: docker/build-push-action@v3 + with: + context: . + file: ${{ matrix.images.dockerfile }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + outputs: type=docker,dest=/tmp/image-${{ matrix.images.name }}.tar + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: image-${{ matrix.images.name }} + path: /tmp/image-${{ matrix.images.name }}.tar + + publish: + needs: [tests, build, cargo-deny] + name: "Publish image: ${{ matrix.images.name }}" + runs-on: + group: ubuntu-runners + strategy: + fail-fast: false + matrix: + images: + - name: github-actions-runner + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-central-1 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: image-${{ matrix.images.name }} + path: /tmp + - name: Push the image to ECR + run: | + docker load --input /tmp/image-${{ matrix.images.name }}.tar + docker image push --all-tags ${{ steps.login-ecr.outputs.registry }}/${{ matrix.images.name }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0a1daac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM myoung34/github-runner:ubuntu-focal + +# modify actions runner binaries to allow custom cache server implementation +# https://gha-cache-server.falcondev.io/getting-started +RUN sed -i 's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' /home/runner/bin/Runner.Worker.dll