From d1d3c9cb094d10664d38b7eea7dc0b54aea12104 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Tue, 3 Dec 2024 12:07:39 +1100 Subject: [PATCH] chore: move to reusable docker workflows --- .github/actions/save-docker-image/action.yml | 24 ++++++++++++++++++ .../actions/shard-docker-builds/action.yml | 13 ++++++++++ .github/workflows/ci.yml | 25 ++++++++++--------- .github/workflows/release.yml | 22 ++++++---------- 4 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 .github/actions/save-docker-image/action.yml create mode 100644 .github/actions/shard-docker-builds/action.yml diff --git a/.github/actions/save-docker-image/action.yml b/.github/actions/save-docker-image/action.yml new file mode 100644 index 0000000000..f13838d9e2 --- /dev/null +++ b/.github/actions/save-docker-image/action.yml @@ -0,0 +1,24 @@ +name: Save Docker Images +description: Builds all docker images and saves them as artifacts +inputs: + service: + description: The service to build + required: true +runs: + using: "composite" + # Make sure to keep these cache entries in sync with those in writecache.yml + steps: + - name: Init Hermit + uses: cashapp/activate-hermit@v1.1.3 + - name: Build Docker Image + shell: bash + run: | + just build-docker ${{ inputs.service }} + mkdir -p artifacts/ftl-${{ inputs.service }} + docker save -o artifacts/ftl-${{ inputs.service }}/ftl-${{ inputs.service }}.tar ftl0/ftl-${{ inputs.service }}:latest + - name: Temporarily save Docker image + uses: actions/upload-artifact@v4 + with: + name: docker-${{ inputs.service }}-artifact + path: artifacts/ftl-${{ inputs.service }} + retention-days: 1 diff --git a/.github/actions/shard-docker-builds/action.yml b/.github/actions/shard-docker-builds/action.yml new file mode 100644 index 0000000000..051f3ce0d9 --- /dev/null +++ b/.github/actions/shard-docker-builds/action.yml @@ -0,0 +1,13 @@ +name: Shard Docker Builds +description: Outputs a matrix of all services to build +outputs: + matrix: + description: A matrix of all services to build + value: ${{ steps.set-matrix.outputs.matrix }} +runs: + using: "composite" + steps: + - uses: cashapp/activate-hermit@v1.1.3 + - id: set-matrix + shell: bash + run: echo "matrix=$(just list-docker-images | tr -d '\n' | jq -R -s -c 'split(" ")')" >> "$GITHUB_OUTPUT" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 295fee2e39..e3c9e9c7f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -224,24 +224,25 @@ jobs: outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - - uses: actions/checkout@v4 - - uses: cashapp/activate-hermit@v1.1.3 + - name: Checkout code + uses: actions/checkout@v4 - id: set-matrix - run: echo "matrix=$(just list-docker-images | tr -d '\n' | jq -R -s -c 'split(" ")')" >> "$GITHUB_OUTPUT" - docker-build: + name: Shard Docker Builds + uses: ./.github/actions/shard-docker-builds + build-docker-images: name: Build ${{ matrix.service }} Docker Image needs: docker-shard runs-on: ubuntu-latest strategy: - fail-fast: false matrix: service: ${{ fromJson(needs.docker-shard.outputs.matrix) }} steps: - - uses: actions/checkout@v4 - - uses: cashapp/activate-hermit@v1.1.3 - - uses: ./.github/actions/build-cache - - name: Build Docker Image - run: just build-docker ${{ matrix.service }} + - name: Checkout code + uses: actions/checkout@v4 + - name: Build Image and Save + uses: ./.github/actions/save-docker-image + with: + service: ${{ matrix.service }} console-e2e: name: Console e2e # if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all') @@ -394,13 +395,13 @@ jobs: fi docker-success: name: Docker Success - needs: [docker-build] + needs: [build-docker-images] runs-on: ubuntu-latest if: ${{ always() }} steps: - name: Check docker builds result run: | - if [[ "${{ needs.docker-build.result }}" == "failure" ]]; then + if [[ "${{ needs.build-docker-images.result }}" == "failure" ]]; then echo "Docker builds failed" exit 1 else diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2d05f0cfb6..c796fbc379 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,10 +10,11 @@ jobs: outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - - uses: actions/checkout@v4 - - uses: cashapp/activate-hermit@v1.1.3 + - name: Checkout code + uses: actions/checkout@v4 - id: set-matrix - run: echo "matrix=$(just list-docker-images | tr -d '\n' | jq -R -s -c 'split(" ")')" >> "$GITHUB_OUTPUT" + name: Shard Docker Builds + uses: ./.github/actions/shard-docker-builds build-docker-images: name: Build ${{ matrix.service }} Docker Image needs: docker-shard @@ -24,19 +25,10 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - name: Init Hermit - uses: cashapp/activate-hermit@v1.1.3 - - name: Build Docker Image - run: | - just build-docker ${{ matrix.service }} - mkdir -p artifacts/ftl-${{ matrix.service }} - docker save -o artifacts/ftl-${{ matrix.service }}/ftl-${{ matrix.service }}.tar ftl0/ftl-${{ matrix.service }}:latest - - name: Temporarily save Docker image - uses: actions/upload-artifact@v4 + - name: Build Image and Save + uses: ./.github/actions/save-docker-image with: - name: docker-${{ matrix.service }}-artifact - path: artifacts/ftl-${{ matrix.service }} - retention-days: 1 + service: ${{ matrix.service }} release-docker: name: Release Docker Images runs-on: ubuntu-latest