-
Notifications
You must be signed in to change notification settings - Fork 10
232 lines (212 loc) · 10.1 KB
/
docker-publish.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
222
223
224
225
226
227
228
229
230
231
232
name: Docker
on:
# TODO: build nightly image
# schedule:
# - cron: '22 3 * * *'
push:
branches: [ main, 'v0.11*', '0.11*' ]
# Publish semver tags as releases.
tags: [ 'v*.*.*', '0.11.*', '1.*' ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ${{ github.ref_type != 'tag' && 'ghcr.io/' || '' }}
# github.repository as <account>/<repo>
IMAGE_NAME: godwoken-prebuilds
jobs:
docker-build-push:
# Same as image base
runs-on: ubuntu-20.04
# Map the meta step outputs to this job outputs
outputs:
image_name: ${{ steps.result.outputs.image_name }}
image_tag: ${{ steps.result.outputs.image_tag }}
# If you specify the access for any of these scopes, all of those that are not specified are set to none.
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Rust components
run: rustup component add rustfmt && rustup component add clippy
- name: Install moleculec
run: |
test "$(moleculec --version)" = "Moleculec 0.7.2" \
|| cargo install moleculec --version 0.7.2 --force
- name: Install capsule
env:
CAPSULE_VERSION: v0.7.0
run: |
(which capsule && test "$(capsule --version)" = "Capsule 0.7.0") \
|| curl -OL https://github.com/nervosnetwork/capsule/releases/download/${CAPSULE_VERSION}/capsule_${CAPSULE_VERSION}_x86_64-linux.tar.gz \
&& tar xf capsule_${CAPSULE_VERSION}_x86_64-linux.tar.gz \
&& mv capsule_${CAPSULE_VERSION}_x86_64-linux/capsule ~/.cargo/bin/
capsule --version
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
# GitHub automatically creates a unique GITHUB_TOKEN secret to use in this workflow.
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.ref_type != 'tag' && github.repository_owner || secrets.DOCKERHUB_USERNAME }}
password: ${{ github.ref_type != 'tag' && secrets.GITHUB_TOKEN || secrets.DOCKERHUB_TOKEN }}
- name: Prepare components
id: prepare
run: |
make prepare-repos
echo "Record the component's reference to the outputs of this step"
cat versions
- name: Print the references of components
run: |
echo ref.component.godwoken=${{ steps.prepare.outputs.GODWOKEN_REF }}
echo ref.component.godwoken-scripts=${{ steps.prepare.outputs.GODWOKEN_SCRIPTS_REF }}
echo ref.component.godwoken-polyjuice=${{ steps.prepare.outputs.POLYJUICE_REF }}
echo ref.component.clerkb=${{ steps.prepare.outputs.CLERKB_REF }}
- name: Cache of component.clerkb
id: clerkb-cache
uses: actions/cache@v3
with:
path: |
build/clerkb/build/debug/poa
build/clerkb/build/debug/state
key: component.clerkb-${{ steps.prepare.outputs.clerkb-sha1 }}
- name: Build clerkb
if: steps.clerkb-cache.outputs.cache-hit != 'true'
working-directory: build/clerkb
run: yarn && make all-via-docker
# Skip building godwoken-scripts because Godwoken v0 is in maintenance mode with no change.
# - name: Cache of component.godwoken-scripts
# id: godwoken-scripts-cache
# uses: actions/cache@v3
# with:
# path: |
# build/godwoken-scripts/build/release/*
# build/godwoken-scripts/c/build/*-generator
# build/godwoken-scripts/c/build/*-validator
# build/godwoken-scripts/c/build/account_locks/*
# key: component.godwoken-scripts-${{ steps.prepare.outputs.godwoken-scripts-sha1 }}
# - name: Build godwoken-scripts
# if: steps.godwoken-scripts-cache.outputs.cache-hit != 'true'
# working-directory: build/godwoken-scripts
# run: cd c && make && cd .. && capsule build --release --debug-output
# Skip building godwoken-polyjuice because Godwoken v0 is in maintenance mode with no change.
# - name: Cache of component.godwoken-polyjuice
# id: godwoken-polyjuice-cache
# uses: actions/cache@v3
# with:
# path: |
# build/godwoken-polyjuice/build/*generator*
# build/godwoken-polyjuice/build/*validator*
# key: component.godwoken-polyjuice-${{ steps.prepare.outputs.godwoken-polyjuice-sha1 }}
# - name: Build godwoken-polyjuice
# if: steps.godwoken-polyjuice-cache.outputs.cache-hit != 'true'
# working-directory: build/godwoken-polyjuice
# run: make all-via-docker
- name: Cache of component.godwoken
id: godwoken-cache
uses: actions/cache@v3
with:
path: |
build/godwoken/target/release/godwoken
build/godwoken/target/release/gw-tools
key: component.godwoken-${{ steps.prepare.outputs.godwoken-sha1 }}
- name: Cache Godwoken target directory
if: steps.godwoken-cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
with:
path: |
build/godwoken/target
key: ${{ runner.os }}-cargo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build godwoken
if: steps.godwoken-cache.outputs.cache-hit != 'true'
working-directory: build/godwoken
env:
# For ckb-rocksdb.
PORTABLE: true
CARGO_PROFILE_RELEASE_LTO: thin
run: rustup component add rustfmt && cargo build --release
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}${{ startsWith(github.ref, 'refs/tags') && github.repository_owner == 'nervosnetwork' && 'nervos' || github.repository_owner }}/${{ env.IMAGE_NAME }}
# dynamically set date as a suffix
tags: |
type=ref,event=tag
type=ref,event=branch,suffix=-{{date 'YYYYMMDDHHmm'}}
type=ref,event=branch
labels: |
maintainer=Nervos Core Dev <dev@nervos.org>
org.opencontainers.image.authors=Nervos Core Dev <dev@nervos.org>
source.component.godwoken=https://github.com/nervosnetwork/godwoken
source.component.godwoken-scripts-Scripts=https://github.com/nervosnetwork/godwoken-scripts
source.component.godwoken-polyjuice=https://github.com/nervosnetwork/godwoken-polyjuice
source.component.clerkb=https://github.com/nervosnetwork/clerkb.git
ref.component.godwoken=${{ steps.prepare.outputs.GODWOKEN_REF }}
ref.component.godwoken-sha1=${{ steps.prepare.outputs.godwoken-sha1 }}
ref.component.godwoken-scripts=${{ steps.prepare.outputs.GODWOKEN_SCRIPTS_REF }}
ref.component.godwoken-scripts-sha1=${{ steps.prepare.outputs.godwoken-scripts-sha1 }}
ref.component.godwoken-polyjuice=${{ steps.prepare.outputs.POLYJUICE_REF }}
ref.component.godwoken-polyjuice-sha1=${{ steps.prepare.outputs.godwoken-polyjuice-sha1 }}
ref.component.clerkb=${{ steps.prepare.outputs.OMNI_LOCK_REF }}
ref.component.clerkb-sha1=${{ steps.prepare.outputs.clerkb-sha1 }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image to ${{ env.REGISTRY }}${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
if: ${{ github.ref_type != 'tag' }}
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile.fast
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Build and push Docker image with Buildx (don't push on PR)
# only for new tag
- name: Build and push Docker image to https://hub.docker.com/r/nervos/godwoken-prebuilds
if: ${{ github.repository_owner == 'nervosnetwork' && startsWith(github.ref, 'refs/tags') }}
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile.fast
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Check versions of the binaries in ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
if: ${{ github.event_name != 'pull_request' }}
env:
IMAGE: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
run: |
docker run --rm ${{ env.IMAGE }} godwoken --version
docker run --rm ${{ env.IMAGE }} gw-tools --version
docker run --rm ${{ env.IMAGE }} ckb --version
docker run --rm ${{ env.IMAGE }} ckb-cli --version
docker run --rm ${{ env.IMAGE }} find /scripts -type f -exec sha1sum {} \;
- name: Record image info to the outputs of this jobs
id: result
run: |
echo "::set-output name=image_name::`echo ${{ fromJSON(steps.meta.outputs.json).tags[0] }} | awk -F ':' '{print $1}'`"
echo "::set-output name=image_tag::`echo ${{ fromJSON(steps.meta.outputs.json).tags[0] }} | awk -F ':' '{print $NF}'`"
integration-test:
needs: docker-build-push
uses: nervosnetwork/godwoken-tests/.github/workflows/reusable-integration-test-v0.yml@develop
with:
gw_prebuild_image_name: ${{ needs.docker-build-push.outputs.image_name }}
gw_prebuild_image_tag: ${{ needs.docker-build-push.outputs.image_tag }}
# gw_prebuild_image_digest: ${{ needs.docker-build-push.outputs.image_digest }}