-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (81 loc) · 2.82 KB
/
reusable-builder.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Reusable Image Builder
on:
workflow_call:
inputs:
name:
required: true
type: string
version:
required: true
type: string
dockerfile:
required: true
type: string
build-args:
required: false
default: ""
type: string
build-platforms:
required: false
default: linux/amd64,linux/arm64
type: string
jobs:
build-image:
name: Build ${{ inputs.dockerfile }}
runs-on: ubuntu-22.04
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Login to Github Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Build ${{ inputs.dockerfile }}
uses: docker/build-push-action@v4
with:
context: .
file: ${{ inputs.dockerfile }}
tags: ghcr.io/paperless-ngx/builder/${{ inputs.name }}:${{ inputs.version }}
platforms: ${{ inputs.build-platforms }}
build-args: ${{ inputs.build-args }}
push: true
cache-from: ghcr.io/paperless-ngx/builder/cache/${{ inputs.name }}:${{ inputs.version }}
cache-to: ghcr.io/paperless-ngx/builder/cache/${{ inputs.name }}:${{ inputs.version }}
-
name: Package built files
run: |
for platform in "linux/amd64" "linux/arm64"
do
if [ ${platform} = "linux/amd64" ]; then
short_name="amd64"
elif [ ${platform} = "linux/arm64" ]; then
short_name="arm64"
else
short_name="armv7"
fi
docker pull --quiet --platform ${platform} ghcr.io/paperless-ngx/builder/${{ inputs.name }}:${{ inputs.version }}
docker create --platform ${platform} --name extract-container ghcr.io/paperless-ngx/builder/${{ inputs.name }}:${{ inputs.version }}
mkdir --verbose --parents ${{ inputs.name }}/${{ inputs.version }}/${short_name}
docker cp extract-container:/usr/src/${{ inputs.name }}/ ${{ inputs.name }}/${{ inputs.version }}/${short_name}/
mv --verbose ${{ inputs.name }}/${{ inputs.version }}/${short_name}/${{ inputs.name }}/* ${{ inputs.name }}/${{ inputs.version }}/${short_name}/
docker rm --force extract-container
done
-
name: Upload files
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.name }}-${{ inputs.version }}
path: ${{ inputs.name }}/
if-no-files-found: error
retention-days: 1