Skip to content

optimize build

optimize build #986

Workflow file for this run

name: 'Docker Publish'
on:
schedule:
- cron: '0 2 * * *'
pull_request:
push:
branches:
- master
jobs:
build:
name: Build image
runs-on: ubuntu-latest
if: github.repository == 'juliushaertl/nextcloud-docker-dev'
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
container:
- php80
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: nextcloud-dev-${{ matrix.container }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ matrix.container }}-buildx-${{ github.sha }}
restore-keys: |
${{ matrix.container }}-buildx-
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Set dockerfile path
id: dockerfile
run: |
NAME="${{ matrix.container }}"
DOCKERFILE=$([[ -f "docker/$NAME/Dockerfile" ]] && echo "docker/$NAME/Dockerfile" || echo "docker/Dockerfile.$NAME")
echo "DOCKERFILE=$DOCKERFILE" >> $GITHUB_OUTPUT
- name: Build container image
uses: docker/build-push-action@v5
with:
push: false
context: docker/
platforms: ${{ matrix.platform }}
file: ${{ steps.dockerfile.outputs.DOCKERFILE }}
outputs: type=image,name=nextcloud-dev-${{ matrix.container }},push-by-digest=true,name-canonical=true,push=true
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- build
strategy:
matrix:
container:
- php80
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: nextcloud-dev-${{ matrix.container }}
- name: Login to GitHub Container Registry
if: needs.prepare.outputs.push == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ steps.meta.outputs.name }} :${{ steps.meta.outputs.version }}