Skip to content

Commit

Permalink
ci: support caching mounts when building Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jan 15, 2025
1 parent 5306514 commit 2a6fa19
Showing 1 changed file with 32 additions and 45 deletions.
77 changes: 32 additions & 45 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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/[email protected]
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
Expand Down

0 comments on commit 2a6fa19

Please sign in to comment.