add build cache #135
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
name: Build and Push Docker Image | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- "*" | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- name: "ghcr.io/bigboot/autokuma" | |
dockerfile: Dockerfile | |
build_args: "" | |
tag_prefix: "" | |
- name: "ghcr.io/bigboot/kuma" | |
dockerfile: Dockerfile.cli | |
build_args: "" | |
tag_prefix: "" | |
- name: "ghcr.io/bigboot/autokuma" | |
dockerfile: Dockerfile | |
build_args: "FEATURES=uptime-kuma-v2" | |
tag_prefix: "uptime-kuma-v2-" | |
- name: "ghcr.io/bigboot/kuma" | |
dockerfile: Dockerfile.cli | |
build_args: "FEATURES=uptime-kuma-v2" | |
tag_prefix: "uptime-kuma-v2-" | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v3 | |
with: | |
images: ${{ matrix.name }} | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=pr,prefix=${{ matrix.tag_prefix }}pr- | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha,prefix=${{ matrix.tag_prefix }}sha- | |
flavor: | | |
latest=auto | |
prefix=${{ matrix.tag_prefix }},onlatest=true | |
suffix= | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Cache | |
uses: actions/cache@v3 | |
id: cache | |
with: | |
path: | | |
cache | |
key: cache-${{ runner.os }}-${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: inject cache into docker | |
uses: reproducible-containers/[email protected] | |
with: | |
cache-map: | | |
{ | |
"cache": "/cache" | |
} | |
skip-extraction: ${{ steps.cache.outputs.cache-hit }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: ${{ 'linux/amd64,linux/arm64' }} | |
file: ${{ matrix.dockerfile }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: ${{ matrix.build_args }} | |
- name: Image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} |