-
Notifications
You must be signed in to change notification settings - Fork 160
221 lines (205 loc) · 7.94 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Forest Docker
# Cancel workflow if there is a new change to the branch.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
on:
push:
branches: [main]
tags:
- "*"
paths-ignore:
- 'docs/'
merge_group:
pull_request:
# This needs to be declared explicitly so that the job is actually
# run when moved out of draft.
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
- 'docs/'
env:
CI: 1
CARGO_INCREMENTAL: 0
CACHE_TIMEOUT_MINUTES: 5
SCRIPT_TIMEOUT_MINUTES: 30
AWS_ACCESS_KEY_ID: '${{ secrets.AWS_ACCESS_KEY_ID }}'
AWS_SECRET_ACCESS_KEY: '${{ secrets.AWS_SECRET_ACCESS_KEY }}'
RUSTC_WRAPPER: sccache
CC: sccache clang
CXX: sccache clang++
jobs:
build-ubuntu-2204-amd64:
name: Build forest binaries on Ubuntu-22.04-amd64
runs-on: ubuntu-22.04
# Run the job only if the PR is not a draft.
# This is done to limit the runner cost.
if: github.event.pull_request.draft == false
steps:
- name: Configure SCCache variables
run: |
# External PRs do not have access to 'vars' or 'secrets'.
if [[ "${{secrets.AWS_ACCESS_KEY_ID}}" != "" ]]; then
echo "SCCACHE_ENDPOINT=${{ vars.SCCACHE_ENDPOINT}}" >> $GITHUB_ENV
echo "SCCACHE_BUCKET=${{ vars.SCCACHE_BUCKET}}" >> $GITHUB_ENV
echo "SCCACHE_REGION=${{ vars.SCCACHE_REGION}}" >> $GITHUB_ENV
fi
- run: lscpu
- name: Show IP
run: curl ifconfig.me
continue-on-error: true
- name: Checkout Sources
uses: actions/checkout@v4
- name: Setup sccache
uses: mozilla-actions/[email protected]
timeout-minutes: '${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}'
continue-on-error: true
- uses: actions/setup-go@v5
with:
go-version-file: "go.work"
- name: Cargo Install
env:
# To minimize compile times: https://nnethercote.github.io/perf-book/build-configuration.html#minimizing-compile-times
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
run: make install
- uses: actions/upload-artifact@v4
with:
name: 'forest-linux-amd64'
path: |
~/.cargo/bin/forest*
if-no-files-found: error
build-ubuntu-2204-arm64:
name: Build forest binaries on Ubuntu-22.04-arm64
runs-on: buildjet-8vcpu-ubuntu-2204-arm
# Run the job only if the PR is not a draft.
# This is done to limit the runner cost.
if: github.event.pull_request.draft == false
steps:
- name: Configure SCCache variables
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
run: |
# External PRs do not have access to 'vars' or 'secrets'.
if [[ "${{secrets.AWS_ACCESS_KEY_ID}}" != "" ]]; then
echo "SCCACHE_ENDPOINT=${{ vars.SCCACHE_ENDPOINT}}" >> $GITHUB_ENV
echo "SCCACHE_BUCKET=${{ vars.SCCACHE_BUCKET}}" >> $GITHUB_ENV
echo "SCCACHE_REGION=${{ vars.SCCACHE_REGION}}" >> $GITHUB_ENV
fi
echo "SCCACHE_S3_KEY_PREFIX=aarch64" >> $GITHUB_ENV
- run: lscpu
- run: vmstat -s
- name: Show IP
run: curl ifconfig.me
continue-on-error: true
- name: Checkout Sources
uses: actions/checkout@v4
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
- name: Setup sccache
uses: mozilla-actions/[email protected]
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
timeout-minutes: '${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}'
continue-on-error: true
- uses: actions/setup-go@v5
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
with:
go-version-file: "go.work"
- name: Cargo Install
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
run: make install
- uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
with:
name: 'forest-linux-arm64'
path: |
~/.cargo/bin/forest*
if-no-files-found: error
build-and-push-docker-image:
name: Build images and push to GHCR
runs-on: ubuntu-22.04
# Run the job only if the PR is not a draft.
# This is done to limit the runner cost.
if: github.event.pull_request.draft == false
timeout-minutes: 30
needs:
- build-ubuntu-2204-amd64
- build-ubuntu-2204-arm64
steps:
- name: List cached docker images
run: docker image ls
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: 'forest-linux-amd64'
path: /tmp/forest/forest-linux-amd64
- uses: actions/download-artifact@v4
# Compile Docker image only for AMD64 for a regular PR to save some CI time.
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
with:
name: 'forest-linux-arm64'
path: /tmp/forest/forest-linux-arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
continue-on-error: true
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Build the fat image first, for details see <https://github.com/ChainSafe/forest/pull/3912>
# This step yields the following labels
# - {date}-{sha}-fat, e.g. 2023-01-19-da4692d-fat,
# - edge-fat
# - tag-fat (if pushed).
- name: Docker Meta fat
id: metafat
uses: docker/metadata-action@v5
with:
images: ghcr.io/chainsafe/forest
flavor: |
latest=false
suffix=-fat
tags: |
type=raw,value={{date 'YYYY-MM-DD'}}-{{sha}}
type=ref,event=tag
type=edge
- name: Build fat image and push to GitHub Container Registry
uses: docker/build-push-action@v6
with:
context: /tmp/forest
file: ./Dockerfile-ci
tags: ${{ steps.metafat.outputs.tags }}
labels: ${{ steps.metafat.outputs.labels }}
push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
# Compile Docker image only for AMD64 for a regular PR to save some CI time.
platforms: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
target: fat-image
# This step yields the following labels
# - date+sha, e.g. 2023-01-19-da4692d,
# - tag (if pushed).
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/chainsafe/forest
flavor: |
latest=false
tags: |
type=raw,value={{date 'YYYY-MM-DD'}}-{{sha}}
type=ref,event=tag
type=edge
- name: Build slim image and push to GitHub Container Registry
uses: docker/build-push-action@v6
with:
context: /tmp/forest
file: ./Dockerfile-ci
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
# Compile Docker image only for AMD64 for a regular PR to save some CI time.
platforms: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
target: slim-image