From 6f60d13bca52b2bab67214ecb7e9bfe67672f58a Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 15 Jan 2025 00:17:28 +0000 Subject: [PATCH] ci: support caching mounts when building Docker images --- .github/workflows/docker.yml | 77 +++++++++++++++--------------------- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7a1aea2bd..fe735812e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,10 +12,18 @@ on: permissions: read-all jobs: - build_publish_docker_hub: - name: Build and Publish Docker Image to Docker Hub - if: contains(github.ref, 'refs/tags/') + build_and_publish: + name: Build and Publish Docker Image runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + registry: [ ghcr, dockerhub ] + include: + - registry: ghcr + image: 'ghcr.io/endstonemc/endstone' + - registry: dockerhub + image: 'endstone/endstone' steps: - name: Checkout Code @@ -27,52 +35,14 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub - if: github.event_name != 'pull_request' + if: matrix.registry == 'dockerhub' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Extract Metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: endstone/endstone - tags: | - type=raw,value=latest,enable={{ is_default_branch }} - type=pep440,pattern={{version}} - - - name: Build and Push - id: build-and-push - uses: docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - secrets: | - sentry-auth-token=${{ secrets.SENTRY_AUTH_TOKEN }} - - build_publish_ghcr: - name: Build and Publish Docker Image to GitHub Container Registry - runs-on: ubuntu-latest - permissions: - packages: write - - steps: - - name: Checkout Code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to GitHub Container Registry - if: github.event_name != 'pull_request' + if: matrix.registry == 'ghcr' uses: docker/login-action@v3 with: registry: ghcr.io @@ -83,14 +53,31 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ghcr.io/endstonemc/endstone + images: ${{ matrix.image }} tags: | type=raw,value=latest,enable={{ is_default_branch }} type=pep440,pattern={{version}} + - name: Conan Cache for Docker + uses: actions/cache@v4 + with: + path: conan-docker-cache + key: ${{ runner.os }}-conan-docker-${{ hashFiles('conanfile.py') }} + + - name: Inject Conan Cache into Docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.0 + with: + cache-map: | + { + "conan-docker-cache": "/root/.conan2/p" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + - name: Build and Push - id: build-and-push uses: docker/build-push-action@v6 + if: > + matrix.registry == 'dockerhub' && startsWith(github.ref, 'refs/tags/') || + matrix.registry == 'ghcr' with: context: . platforms: linux/amd64