Skip to content

Commit 3869810

Browse files
0xverinIgor TrofimovBillyWooo
authored
Build match worker image (#2313)
* add worker && cli build * separate docker builds * add Docker Buildx * add caches --------- Co-authored-by: Igor Trofimov <igor@kawagarbo-tech.io> Co-authored-by: BillyWooo <thedreamofbilly@gmail.com>
1 parent 8969e7e commit 3869810

File tree

4 files changed

+159
-46
lines changed

4 files changed

+159
-46
lines changed

.github/workflows/create-release-draft.yml

Lines changed: 134 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ on:
2424
required: true
2525
default: true
2626
release_tag:
27-
description: an existing tag for creating release (e.g. v1.2.3)
27+
description: an existing tag for creating release (e.g. p1.2.0-w0.0.1-101)
2828
required: true
2929
diff_tag:
30-
description: an existing tag to run diff against (e.g. v1.2.0)
30+
description: an existing tag to run diff against (e.g. p1.1.0-w0.0.1-100)
3131
default: ""
3232
required: false
3333
genesis_release:
@@ -44,6 +44,7 @@ env:
4444
DIFF_TAG: ${{ github.event.inputs.diff_tag }}
4545
GENESIS_RELEASE: ${{ github.event.inputs.genesis_release }}
4646
DOCKER_BUILDKIT: 1
47+
REF_VERSION: ${{ github.head_ref || github.ref_name }}
4748

4849
jobs:
4950
set-release-type:
@@ -114,8 +115,8 @@ jobs:
114115
${{ matrix.chain }}-parachain-srtool-digest.json
115116
${{ matrix.chain }}-parachain-runtime.compact.compressed.wasm
116117
117-
## build docker image of parachain binary ##
118-
build-docker:
118+
# build docker image of parachain binary ##
119+
build-parachain-docker:
119120
if: ${{ github.event.inputs.release_client == 'true' }}
120121
runs-on: ubuntu-latest
121122
steps:
@@ -127,7 +128,7 @@ jobs:
127128

128129
- name: Set env
129130
run: |
130-
DOCKER_TAG=$(echo ${{ env.RELEASE_TAG }} | cut -d'-' -f1 | sed 's/p/v/')
131+
DOCKER_TAG=$(echo ${{ env.RELEASE_TAG }} | sed 's/p/v/;s/\(.*\)-w.*/\1/')
131132
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
132133
133134
- name: Build docker image
@@ -166,6 +167,121 @@ jobs:
166167
${{ env.GENESIS_RELEASE }}-genesis-state
167168
${{ env.GENESIS_RELEASE }}-genesis-wasm
168169
170+
build-worker-docker:
171+
if: ${{ github.event.inputs.release_worker == 'true' }}
172+
runs-on: ubuntu-latest
173+
steps:
174+
- name: Checkout codes on ${{ env.RELEASE_TAG }}
175+
uses: actions/checkout@v4
176+
with:
177+
ref: ${{ env.RELEASE_TAG }}
178+
fetch-depth: 0
179+
- name: Set env
180+
run: |
181+
WORKER_TAG=$(echo ${{ env.RELEASE_TAG }} | sed 's/.*\(w.*\)/\1/;s/w/v/')
182+
echo "WORKER_TAG=$WORKER_TAG" >> $GITHUB_ENV
183+
184+
- name: Free up disk space
185+
if: startsWith(runner.name, 'GitHub Actions')
186+
uses: jlumbroso/free-disk-space@main
187+
with:
188+
tool-cache: true
189+
swap-storage: false
190+
large-packages: false
191+
192+
- name: Set up Docker Buildx
193+
uses: docker/setup-buildx-action@v3
194+
with:
195+
# use the docker driver to access the local image
196+
# we don't need external caches or multi platforms here
197+
# see https://docs.docker.com/build/drivers/
198+
driver: docker
199+
200+
- name: Cache worker-cache
201+
uses: actions/cache@v3
202+
with:
203+
path: |
204+
worker-cache
205+
key: worker-cache-${{ env.REF_VERSION }}-${{ hashFiles('tee-worker/**/Cargo.lock', 'tee-worker/**/Cargo.toml') }}
206+
restore-keys: |
207+
worker-cache-${{ env.REF_VERSION }}-
208+
worker-cache-
209+
210+
- name: Create cache folder if not exist
211+
run: |
212+
for i in 'git/db' 'registry/cache' 'registry/index' 'sccache'; do
213+
[ ! -d "worker-cache/$i" ] && mkdir -p "worker-cache/$i" || true
214+
echo "hello" > worker-cache/$i/nix
215+
done
216+
echo "::group::List worker-cache size"
217+
du -sh worker-cache/*
218+
echo "::endgroup::"
219+
echo "::group::Show disk usage"
220+
df -h .
221+
echo "::endgroup::"
222+
223+
- name: Build local builder
224+
uses: docker/build-push-action@v5
225+
with:
226+
context: .
227+
file: tee-worker/build.Dockerfile
228+
tags: local-builder:latest
229+
target: builder
230+
build-args: |
231+
WORKER_MODE_ARG=sidechain
232+
ADDITIONAL_FEATURES_ARG=
233+
234+
- name: Copy caches from the built image
235+
run: |
236+
echo "::group::Show disk usage"
237+
df -h .
238+
echo "::endgroup::"
239+
echo "::group::docker images"
240+
docker images --all
241+
echo "::endgroup::"
242+
echo "::group::copy cache out"
243+
for i in 'git/db' 'registry/cache' 'registry/index'; do
244+
b="${i%/*}"
245+
rm -rf worker-cache/$i
246+
docker cp "$(docker create --rm local-builder:latest):/opt/rust/$i" worker-cache/$b
247+
done
248+
rm -rf worker-cache/sccache
249+
docker cp "$(docker create --rm local-builder:latest):/opt/rust/sccache" worker-cache
250+
du -sh worker-cache/*
251+
echo "::endgroup::"
252+
echo "::group::df -h ."
253+
df -h .
254+
echo "::endgroup::"
255+
256+
- name: Build worker
257+
uses: docker/build-push-action@v5
258+
with:
259+
context: .
260+
file: tee-worker/build.Dockerfile
261+
tags: litentry/litentry-worker:${{ env.WORKER_TAG }}
262+
target: deployed-worker
263+
264+
- name: Build cli
265+
uses: docker/build-push-action@v5
266+
with:
267+
context: .
268+
file: tee-worker/build.Dockerfile
269+
tags: litentry/litentry-cli:${{ env.WORKER_TAG }}
270+
target: deployed-client
271+
272+
- run: docker images --all
273+
274+
- name: Dockerhub login
275+
uses: docker/login-action@v3
276+
with:
277+
username: ${{ secrets.DOCKERHUB_USERNAME }}
278+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
279+
280+
- name: Push worker image
281+
run: |
282+
docker push litentry/litentry-worker:$WORKER_TAG
283+
docker push litentry/litentry-cli:$WORKER_TAG
284+
169285
## Build the enclave and package config files
170286
build-tee:
171287
if: ${{ github.event.inputs.release_worker == 'true' }} || ${{ github.event.inputs.release_enclave == 'true' }}
@@ -181,8 +297,8 @@ jobs:
181297
ref: ${{ env.RELEASE_TAG }}
182298
fetch-depth: 0
183299

184-
- name: Build release artefacts
185-
run: |
300+
- name: Build release artefacts
301+
run: |
186302
source /opt/intel/sgxsdk/environment
187303
./tee-worker/scripts/litentry/release/build.sh ${{ github.event.inputs.release_worker }} ${{ github.event.inputs.release_enclave }}
188304
@@ -214,11 +330,11 @@ jobs:
214330
- name: Fail early
215331
if: failure()
216332
uses: andymckay/cancel-action@0.3
217-
333+
218334
## test again the built docker image ##
219335
run-ts-tests:
220336
runs-on: ubuntu-latest
221-
needs: build-docker
337+
needs: build-parachain-docker
222338
strategy:
223339
matrix:
224340
chain:
@@ -235,7 +351,7 @@ jobs:
235351

236352
- name: Download and tag docker image
237353
run: |
238-
export DOCKER_TAG=$(echo ${{ env.RELEASE_TAG }} | cut -d'-' -f1 | sed 's/p/v/')
354+
export DOCKER_TAG=$(echo ${{ env.RELEASE_TAG }} | sed 's/p/v/;s/\(.*\)-w.*/\1/')
239355
docker pull litentry/litentry-parachain:$DOCKER_TAG
240356
docker tag litentry/litentry-parachain:$DOCKER_TAG litentry/litentry-parachain:latest
241357
@@ -260,7 +376,7 @@ jobs:
260376
## check extrinsic ##
261377
extrinsic-ordering-check-from-bin:
262378
runs-on: ubuntu-latest
263-
needs: build-docker
379+
needs: build-parachain-docker
264380
strategy:
265381
matrix:
266382
chain: [rococo, litmus, litentry]
@@ -280,7 +396,7 @@ jobs:
280396
- name: Prepare output and compare the metadata
281397
timeout-minutes: 3
282398
run: |
283-
export DOCKER_TAG=$(echo ${{ env.RELEASE_TAG }} | cut -d'-' -f1 | sed 's/p/v/')
399+
export DOCKER_TAG=$(echo ${{ env.RELEASE_TAG }} | sed 's/p/v/;s/\(.*\)-w.*/\1/')
284400
PARACHAIN_NAME=local-parachain
285401
BASE_URL=ws://127.0.0.1:9944
286402
chain=${{ matrix.chain }}
@@ -310,16 +426,16 @@ jobs:
310426
uses: actions-cool/issues-helper@v3
311427
id: findissueid
312428
with:
313-
actions: 'find-issues'
429+
actions: "find-issues"
314430
token: ${{ secrets.GITHUB_TOKEN }}
315-
issue-state: 'open'
431+
issue-state: "open"
316432
title-includes: Litentry-parachain ${{ env.RELEASE_TAG }} Release checklist
317-
433+
318434
- name: Create comment
319435
if: ${{ steps.findissueid.outputs.issues }} != '[]'
320436
uses: actions-cool/issues-helper@v3
321437
with:
322-
actions: 'create-comment'
438+
actions: "create-comment"
323439
token: ${{ secrets.GITHUB_TOKEN }}
324440
issue-number: ${{ fromJson(steps.findissueid.outputs.issues)[0].number }}
325441
body: |
@@ -334,7 +450,7 @@ jobs:
334450
- set-release-type
335451
- build-tee
336452
- run-ts-tests
337-
- build-wasm
453+
- build-wasm
338454
if: |
339455
!failure() &&
340456
(success('build-wasm') || success('run-ts-tests') || success('build-tee'))
@@ -347,7 +463,7 @@ jobs:
347463

348464
- name: Download all artefacts
349465
uses: actions/download-artifact@v3
350-
466+
351467
- name: Generate release notes
352468
run: |
353469
export MRENCLAVE="${{ needs.build-tee.outputs.mrenclave }}"

.github/workflows/release-ts-api-package.yml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,10 @@ name: Release Ts API Package
33

44
on:
55
workflow_dispatch:
6-
inputs:
7-
parachain-tag:
8-
description: 'Parachain docker image tag'
9-
required: true
10-
default: 'latest'
11-
worker-tag:
12-
description: 'Worker docker image tag'
13-
required: true
14-
default: 'latest'
15-
release-tag:
16-
description: 'Client-api release tag'
17-
required: true
18-
default: 'latest'
6+
inputs:
7+
release-tag:
8+
description: "Client-api release tag (e.g. p1.2.0-9701-w0.0.1-101)"
9+
required: true
1910
env:
2011
NODE_AUTH_TOKEN: ${{ secrets.RELEASE_TS_API_PACKAGE_TOKEN }}
2112

@@ -25,18 +16,24 @@ jobs:
2516
steps:
2617
- uses: actions/checkout@v4
2718

19+
- name: Set ENV
20+
run: |
21+
# extracting parachain version and worker version from release tag
22+
echo "PARACHAIN_TAG=$(echo ${{inputs.release-tag}} | sed 's/p/v/;s/\(.*\)-w.*/\1/')" >> $GITHUB_ENV
23+
echo "WORKER_TAG=$(echo ${{inputs.release-tag}} | sed 's/.*\(w.*\)/\1/;s/w/v/')" >> $GITHUB_ENV
24+
2825
- name: Pull litentry image optionally
2926
run: |
3027
docker pull parity/polkadot
31-
docker pull litentry/litentry-worker:${{ inputs.worker-tag }}
32-
docker pull litentry/litentry-cli:${{ inputs.worker-tag }}
33-
docker pull litentry/litentry-parachain:${{ inputs.parachain-tag }}
28+
docker pull litentry/litentry-worker:$WORKER_TAG
29+
docker pull litentry/litentry-cli:$WORKER_TAG
30+
docker pull litentry/litentry-parachain:$PARACHAIN_TAG
3431
3532
- name: Re-tag docker image
3633
run: |
37-
docker tag litentry/litentry-worker:${{ inputs.worker-tag }} litentry/litentry-worker:latest
38-
docker tag litentry/litentry-cli:${{ inputs.worker-tag }} litentry/litentry-cli:latest
39-
docker tag litentry/litentry-parachain:${{ inputs.parachain-tag }} litentry/litentry-parachain:latest
34+
docker tag litentry/litentry-worker:$WORKER_TAG litentry/litentry-worker:latest
35+
docker tag litentry/litentry-cli:$WORKER_TAG litentry/litentry-cli:latest
36+
docker tag litentry/litentry-parachain:$PARACHAIN_TAG litentry/litentry-parachain:latest
4037
4138
- run: docker images --all
4239

@@ -51,9 +48,8 @@ jobs:
5148
run: |
5249
cd tee-worker/docker
5350
docker compose -f litentry-parachain.build.yml build
54-
51+
5552
- name: Update metadata and generate types
56-
timeout-minutes: 10
5753
run: |
5854
cd tee-worker/docker
5955
docker compose -f docker-compose.yml -f lit-ts-api-package-build.yml up --no-build --exit-code-from lit-ts-api-package-build lit-ts-api-package-build
@@ -83,7 +79,6 @@ jobs:
8379
echo "$api dist and build files do not exist. Publishing failed."
8480
exit 1
8581
fi
86-
8782
npm publish --tag ${{ inputs.release-tag }}
8883
8984
echo "------------------------$api published------------------------"
@@ -109,4 +104,4 @@ jobs:
109104
with:
110105
name: logs-lit-ts-api-package-build
111106
path: logs
112-
if-no-files-found: ignore
107+
if-no-files-found: ignore

tee-worker/cli/lit_ts_api_package_build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ echo "Using client binary $CLIENT_BIN"
4242
echo "Using node uri $NODEURL:$NPORT"
4343
echo "Using trusted-worker uri $WORKER1URL:$WORKER1PORT"
4444
echo "Using node http uri $NODEHTTPURL:$NPORT"
45-
echo ""
46-
45+
echo "waiting 20 secs worker to run successfully"
46+
sleep 20
4747
cd /client-api/parachain-api
4848
curl -s -H "Content-Type: application/json" -d '{"id": "1", "jsonrpc": "2.0", "method": "state_getMetadata", "params": []}' $NODEHTTPURL:$NPORT > prepare-build/litentry-parachain-metadata.json
4949
echo "update parachain metadata"

tee-worker/docker/lit-ts-api-package-build.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ services:
1313
litentry-node:
1414
condition: service_healthy
1515
litentry-worker-1:
16-
condition: service_healthy
16+
# using +service_started+ over +service_healthy+ since worker runs successfully but can not connect to parachain
17+
# as requires additional pre-setup for parachain image which built in production mode
18+
# for generating types there is no need for fully workable interaction between worker and parachain
19+
condition: service_started
1720
networks:
1821
- litentry-test-network
19-
entrypoint:
20-
"/usr/local/worker-cli/lit_ts_api_package_build.sh -p 9912 -u ws://litentry-node
22+
entrypoint: "/usr/local/worker-cli/lit_ts_api_package_build.sh -p 9912 -u ws://litentry-node
2123
-W http://litentry-node -V wss://litentry-worker-1 -A 2011 -C /usr/local/bin/litentry-cli 2>&1"
2224
restart: "no"
2325
networks:

0 commit comments

Comments
 (0)