From 369b85018a8bbc91bcef03ae4b85247d7e569b6c Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 14 Sep 2022 20:31:19 +0200 Subject: [PATCH] ci: improve containers build caching --- .../actions/build-container/action.yml | 9 ++-- .github/workflows/container.yml | 45 ++++++++++++++----- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.github/workflows/actions/build-container/action.yml b/.github/workflows/actions/build-container/action.yml index 50785002c..286725225 100644 --- a/.github/workflows/actions/build-container/action.yml +++ b/.github/workflows/actions/build-container/action.yml @@ -4,8 +4,6 @@ description: Build and push a container inputs: target: required: true - images: - required: true runs: using: composite @@ -13,12 +11,15 @@ runs: - uses: docker/metadata-action@v4 id: meta with: - images: ${{ inputs.images }} + images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ inputs.target }} - uses: docker/build-push-action@v3 with: context: . - push: ${{ startsWith(github.ref, 'refs/tags') }} + pull: true + push: ${{ github.event_name == 'push' }} target: ${{ inputs.target }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,scope=${{ inputs.target }} + cache-to: type=gha,scope=${{ inputs.target }},mode=max diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 46bebde36..8090dea35 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -17,43 +17,68 @@ jobs: env: REGISTRY: ghcr.io NAMESPACE: ${{ github.repository_owner }} + CACHE_REF: ghcr.io/${{ github.repository_owner }}/libretime-cache if: ${{ github.repository_owner == 'libretime' }} steps: - uses: actions/checkout@v3 + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build libretime-analyzer + - name: Build python-builder + uses: docker/build-push-action@v3 + with: + context: . + pull: true + target: python-builder + cache-from: type=gha,scope=python-builder + cache-to: type=gha,scope=python-builder,mode=max + + - name: Build python-base + uses: docker/build-push-action@v3 + with: + context: . + pull: true + target: python-base + cache-from: type=gha,scope=python-base + cache-to: type=gha,scope=python-base,mode=max + + - name: Build python-base-ffmpeg + uses: docker/build-push-action@v3 + with: + context: . + pull: true + target: python-base-ffmpeg + cache-from: type=gha,scope=python-base-ffmpeg + cache-to: type=gha,scope=python-base-ffmpeg,mode=max + + - name: Build analyzer uses: ./.github/workflows/actions/build-container with: target: libretime-analyzer - images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/libretime-analyzer - - name: Build libretime-api + - name: Build api uses: ./.github/workflows/actions/build-container with: target: libretime-api - images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/libretime-api - - name: Build libretime-playout + - name: Build playout uses: ./.github/workflows/actions/build-container with: target: libretime-playout - images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/libretime-playout - - name: Build libretime-worker + - name: Build worker uses: ./.github/workflows/actions/build-container with: target: libretime-worker - images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/libretime-worker - - name: Build libretime-legacy + - name: Build legacy uses: ./.github/workflows/actions/build-container with: target: libretime-legacy - images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/libretime-legacy