-
Notifications
You must be signed in to change notification settings - Fork 45
183 lines (166 loc) · 6.05 KB
/
docker.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Build Docker image
on:
workflow_call:
inputs:
uploadImageAsTarball:
description: 'uploads the Docker image additionally as a tarball'
required: false
default: false
type: boolean
platforms:
description: 'platforms for docker build step'
required: false
default: ''
type: string
debug:
description: 'include debug symbols in built image'
required: false
default: false
type: boolean
parca:
description: 'split out debug symbols and upload to polar signals'
required: false
default: false
type: boolean
features:
description: 'features to enable in the build'
required: false
default: ''
type: string
pushToDockerHub:
description: 'push image to DockerHub'
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
uploadImageAsTarball:
description: 'uploads the Docker image additionally as a tarball'
required: false
default: false
type: boolean
platforms:
description: 'platforms for docker build step'
required: false
default: ''
type: string
debug:
description: 'include debug symbols in built image'
required: false
default: false
type: boolean
parca:
description: 'upload debug symbols to polar signals'
required: false
default: false
type: boolean
pushToDockerHub:
description: 'push image to DockerHub'
required: false
default: false
type: boolean
env:
REPOSITORY_OWNER: ${{ github.repository_owner }}
GHCR_REGISTRY: 'ghcr.io'
GHCR_REGISTRY_USERNAME: ${{ github.actor }}
GHCR_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build-and-push-image:
runs-on: warp-ubuntu-latest-x64-16x
timeout-minutes: ${{ (inputs.debug || inputs.parca) && 140 || 70 }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
# this is needed to be able to load and push a multiplatform image in one step
- name: Set up Docker containerd snapshotter
uses: crazy-max/ghaction-setup-docker@v3
with:
daemon-config: |
{
"features": {
"containerd-snapshotter": true
}
}
- name: Set up QEMU dependency
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# https://docs.warpbuild.com/cache/docker-layer-caching#step-1-set-up-docker-buildx-action
driver-opts: |
network=host
- name: Cache sccache
id: cache
uses: WarpBuilds/cache@v1
with:
path: sccache-cache
key: ${{ runner.os }}-sccache-${{ hashFiles('**/Cargo.lock') }}
- name: Inject sccache-cache into Docker
uses: reproducible-containers/buildkit-cache-dance@v3
with:
cache-map: |
{
"sccache-cache": "/var/cache/sccache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
- name: Log into GitHub container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ env.GHCR_REGISTRY_USERNAME }}
password: ${{ env.GHCR_REGISTRY_TOKEN }}
- name: Log into DockerHub
if: ${{ inputs.pushToDockerHub }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract image name
# Set repository name as image name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/${{ env.IMAGE_NAME }}
${{ inputs.pushToDockerHub && format('docker.io/{0}/{1}', env.REPOSITORY_OWNER, env.IMAGE_NAME) || '' }}
flavor: |
${{ inputs.debug && 'prefix=debug-,onlatest=true' || '' }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build${{(inputs.uploadImageAsTarball != true || github.ref == 'refs/heads/main') && ' and push ' || ' '}}Docker image
id: build
uses: docker/build-push-action@v6
with:
context: .
file: "docker/Dockerfile"
# push if we aren't uploading as a tarball, or if this is main'
tags: ${{ steps.meta.outputs.tags }}
# push if we aren't uploading as a tarball, or if this is main
outputs: |
${{ (inputs.uploadImageAsTarball != true || github.ref == 'refs/heads/main') && 'type=registry' || '' }}
${{ inputs.uploadImageAsTarball == true && 'type=oci,dest=restate.tar' || '' }}
labels: ${{ steps.meta.outputs.labels }}
# on main, always push both platforms, otherwise use platform input
platforms: ${{ github.ref == 'refs/heads/main' && 'linux/arm64,linux/amd64' || (inputs.platforms || 'linux/arm64,linux/amd64') }}
network: host
build-args: |
CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug || inputs.parca }}
UPLOAD_DEBUGINFO=${{ inputs.parca }}
RESTATE_FEATURES=${{ inputs.features || '' }}
secrets: |
parca=${{ secrets.PARCA_TOKEN }}
cache-from: type=gha,url=http://127.0.0.1:49160/
cache-to: type=gha,url=http://127.0.0.1:49160/,mode=max
- name: Upload docker image tar as artifact
if: ${{ inputs.uploadImageAsTarball }}
uses: actions/upload-artifact@v4
with:
name: restate.tar
path: restate.tar
retention-days: 1
if-no-files-found: error