forked from hobbyfarm/ui
-
Notifications
You must be signed in to change notification settings - Fork 1
95 lines (83 loc) · 2.7 KB
/
pkg.yaml
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
92
93
94
95
name: PKG
on:
push:
branches: ['master']
tags: ['*']
workflow_dispatch: {}
env:
should_push_image: |-
${{
github.event_name == 'push' && (
github.ref_type == 'tag' ||
github.ref_name == 'master'
)
}}
should_tag_latest: |-
${{
github.event_name == 'push' &&
github.ref_type == 'tag'
}}
build_and_cache: |-
build_and_cache() {
arch="$1"
if ! docker buildx build \
--platform linux/$arch \
--cache-from type=local,src=/home/runner/tmp/$arch \
--cache-to type=local,dest=/home/runner/tmp/$arch \
--tag ${GITHUB_REPOSITORY,,}:$arch \
--file Dockerfile . ;
then
echo "::error::Docker-Build Error. $arch Cache will be deleted now!"
rm -rf /home/runner/tmp/$arch/
fi
}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: update cache on every commit
uses: actions/cache@v3
with:
path: /home/runner/tmp
key: docker-${{ github.run_id }}
restore-keys: |
docker-
- name: Prep build # also builds the conatiner when triggered via workflow_dispatch
run: |
docker buildx create --use
docker buildx inspect --bootstrap
- name: Fill AMD64 cache
run: |
${{ env.build_and_cache }}
build_and_cache amd64
- name: Fill ARM64 cache
run: |
${{ env.build_and_cache }}
build_and_cache arm64
- name: Login container registry
if: fromJSON(env.should_push_image)
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" \
| docker login -u "${{ secrets.REGISTRY_USER }}" --password-stdin
- name: Build from cache & Push # if commit is taged, the container name is freed from unwanted chars
if: fromJSON(env.should_push_image)
run: |
safe_ref=$(echo "${{ github.ref_name }}" | sed -e 's/[^a-zA-Z0-9\-\.]/-/g')
docker buildx build --push \
--platform linux/amd64,linux/arm64 \
--cache-from type=local,src=/home/runner/tmp/amd64 \
--cache-from type=local,src=/home/runner/tmp/arm64 \
--tag ${GITHUB_REPOSITORY,,}:$safe_ref \
--file Dockerfile .
- name: Build from cache & Push latest
if: fromJSON(env.should_tag_latest)
run: |
docker buildx build --push \
--platform linux/amd64,linux/arm64 \
--cache-from type=local,src=/home/runner/tmp/amd64 \
--cache-from type=local,src=/home/runner/tmp/arm64 \
--tag ${GITHUB_REPOSITORY,,}:latest \
--file Dockerfile .