forked from ferriskey/ferriskey
-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (151 loc) · 5.07 KB
/
docker.yaml
File metadata and controls
168 lines (151 loc) · 5.07 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: docker
on:
push:
branches:
- main
tags:
- v*.*.*
- v*.*.*-rc*
pull_request:
branches:
- main
paths:
- .github/workflows/docker.yaml
- api/**
- client/**
- core/**
- front/**
- operator/**
- .dockerignore
- Cargo.*
- '!api/tests/**'
- '!front/.editorconfig'
- '!front/.gitignore'
- '!front/.prettierrc'
- '!**.example'
- '!**md'
workflow_dispatch:
inputs:
push:
type: boolean
default: false
description: "Whether to push the image"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ${{ matrix.runner.name }}
strategy:
matrix:
runner:
- name: ubuntu-24.04
platform: linux/amd64
- name: ubuntu-24.04-arm
platform: linux/arm64
target:
- api
- operator
- webapp
steps:
- name: checkout
uses: actions/checkout@v5
- name: set up builx
uses: docker/setup-buildx-action@v3
- name: cache layers
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/.buildx-cache
key: buildx-${{ runner.arch }}-${{ matrix.target }}-${{ github.sha }}
restore-keys: |
buildx-${{ runner.arch }}-${{ matrix.target }}-
- name: get image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/ferriskey/ferriskey-${{ matrix.target }}
- name: log-in to ghcr
if: inputs.push || startsWith(github.ref, 'refs/tags/v') || github.ref_name == github.event.repository.default_branch
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build and push
uses: docker/build-push-action@v6
id: build
with:
context: .
target: ${{ matrix.target }}
platforms: ${{ matrix.runner.platform }}
tags: ghcr.io/ferriskey/ferriskey-${{ matrix.target }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=${{ runner.temp }}/.buildx-cache
cache-to: type=local,dest=${{ runner.temp }}/.buildx-cache-new,mode=max
outputs: type=image,push-by-digest=true,name-canonical=true,push=${{ inputs.push || startsWith(github.ref, 'refs/tags/v') || github.ref_name == github.event.repository.default_branch }}
- name: prepare digest
id: digest
if: inputs.push || startsWith(github.ref, 'refs/tags/v') || github.ref_name == github.event.repository.default_branch
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: upload digest
if: inputs.push || startsWith(github.ref, 'refs/tags/v') || github.ref_name == github.event.repository.default_branch
uses: actions/upload-artifact@v4
with:
name: digests-${{ runner.arch }}-${{ matrix.target }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: move cache
run: |
rm -rf ${{ runner.temp }}/.buildx-cache
mv ${{ runner.temp }}/.buildx-cache-new ${{ runner.temp }}/.buildx-cache
push-manifest:
if: inputs.push || startsWith(github.ref, 'refs/tags/v') || github.ref_name == github.event.repository.default_branch
needs:
- build
runs-on: ubuntu-latest
strategy:
matrix:
target:
- api
- operator
- webapp
steps:
- name: set up builx
uses: docker/setup-buildx-action@v3
- name: download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*-${{ matrix.target }}
merge-multiple: true
- name: log-in to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: get image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/ferriskey/ferriskey-${{ matrix.target }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=pr
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: push manifest
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $(printf 'ghcr.io/ferriskey/ferriskey-${{ matrix.target }}@sha256:%s ' *)