-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: support caching mounts when building Docker images
- Loading branch information
1 parent
5306514
commit 2a6fa19
Showing
1 changed file
with
32 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[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 | ||
|