Skip to content

Commit 36ee882

Browse files
committed
Composite action
Signed-off-by: CrazyMax <[email protected]>
1 parent a66e35b commit 36ee882

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,3 +673,29 @@ jobs:
673673
name: Dump context
674674
if: always()
675675
uses: crazy-max/ghaction-dump-context@v1
676+
677+
composite:
678+
runs-on: ubuntu-latest
679+
services:
680+
registry:
681+
image: registry:2
682+
ports:
683+
- 5000:5000
684+
steps:
685+
-
686+
name: Checkout
687+
uses: actions/checkout@v2
688+
-
689+
name: Build with composite
690+
uses: ./composite
691+
with:
692+
context: .
693+
file: ./test/Dockerfile
694+
images: |
695+
localhost:5000/name/app
696+
platforms: linux/amd64,linux/arm64
697+
push: ${{ github.event_name != 'pull_request' }}
698+
-
699+
name: Dump context
700+
if: always()
701+
uses: crazy-max/ghaction-dump-context@v1

composite/action.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: 'Docker composite action'
2+
description: 'Set up Buildx and QEMU + Cache + Metadata + Build and push'
3+
4+
inputs:
5+
images:
6+
description: "List of Docker image slugs (eg. name/app)"
7+
required: true
8+
context:
9+
description: "Build's context is the set of files located in the specified PATH or URL. (default Git context)"
10+
required: false
11+
file:
12+
description: "Path to the Dockerfile. (default {context}/Dockerfile)"
13+
required: false
14+
platforms:
15+
description: "List of target platforms (eg. linux/amd64)"
16+
required: false
17+
cachekey:
18+
description: "Cache key for local cache. (default buildx-{github.repository.name})"
19+
required: false
20+
default: "buildx-${{ github.repository.name}}"
21+
push:
22+
description: "Push image to the registry"
23+
required: false
24+
default: "true"
25+
26+
runs:
27+
using: "composite"
28+
steps:
29+
-
30+
uses: actions/cache@v2
31+
with:
32+
path: /tmp/.buildx-${{ inputs.cachekey }}-cache
33+
key: ${{ runner.os }}-${{ inputs.cachekey }}-${{ github.sha }}
34+
restore-keys: |
35+
${{ runner.os }}-${{ inputs.cachekey }}-
36+
-
37+
id: meta
38+
uses: docker/metadata-action@v3
39+
with:
40+
images: ${{ inputs.images }}
41+
tags: |
42+
type=schedule
43+
type=ref,event=branch
44+
type=semver,pattern={{version}}
45+
type=semver,pattern={{major}}.{{minor}}
46+
type=semver,pattern={{major}}
47+
-
48+
uses: docker/setup-qemu-action@v1
49+
-
50+
uses: docker/setup-buildx-action@v1
51+
-
52+
uses: docker/build-push-action@v2
53+
with:
54+
context: ${{ inputs.context }}
55+
file: ${{ inputs.file }}
56+
push: ${{ inputs.push }}
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
platforms: ${{ inputs.platforms }}
60+
cache-from: type=local,src=/tmp/.${{ inputs.cachekey }}-cache
61+
cache-to: type=local,dest=/tmp/.${{ inputs.cachekey }}-cache-new,mode=max
62+
-
63+
# Temp fix
64+
# https://github.com/docker/build-push-action/issues/252
65+
# https://github.com/moby/buildkit/issues/1896
66+
run: |
67+
rm -rf /tmp/.${{ inputs.cachekey }}-cache
68+
mv /tmp/.${{ inputs.cachekey }}-cache-new /tmp/.${{ inputs.cachekey }}-cache
69+
shell: bash

0 commit comments

Comments
 (0)