Skip to content

Commit eeb368e

Browse files
GHW for building and publishing docker images (#1391)
* add ghw and scripts for docker image deployment * debug * add permissions for content * fix path to the bin folder * add tags * rename env * fix path to docker file * make polkadot-parachain executable * fix typo * fix more typos * test * revert back use of working directory * mke bin executable in the artifacts folder * use cd instead of working directory * change path to cash * fix path to cash * change cache key * delete old flows * addressed PR comments * fix path * reorg docker files
1 parent 4c077b2 commit eeb368e

File tree

55 files changed

+784
-677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+784
-677
lines changed

.gitlab/common/lib.sh renamed to .github/scripts/common/lib.sh

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ structure_message() {
9696
# access_token: see https://matrix.org/docs/guides/client-server-api/
9797
# Usage: send_message $body (json formatted) $room_id $access_token
9898
send_message() {
99-
curl -XPOST -d "$1" "https://matrix.parity.io/_matrix/client/r0/rooms/$2/send/m.room.message?access_token=$3"
99+
curl -XPOST -d "$1" "https://m.parity.io/_matrix/client/r0/rooms/$2/send/m.room.message?access_token=$3"
100100
}
101101

102102
# Pretty-printing functions
@@ -193,3 +193,74 @@ check_bootnode(){
193193
echo " Bootnode appears unreachable"
194194
return 1
195195
}
196+
197+
# Assumes the ENV are set:
198+
# - RELEASE_ID
199+
# - GITHUB_TOKEN
200+
# - REPO in the form paritytech/polkadot
201+
fetch_release_artifacts() {
202+
echo "Release ID : $RELEASE_ID"
203+
echo "Repo : $REPO"
204+
echo "Binary : $BINARY"
205+
206+
curl -L -s \
207+
-H "Accept: application/vnd.github+json" \
208+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
209+
-H "X-GitHub-Api-Version: 2022-11-28" \
210+
https://api.github.com/repos/${REPO}/releases/${RELEASE_ID} > release.json
211+
212+
# Get Asset ids
213+
ids=($(jq -r '.assets[].id' < release.json ))
214+
count=$(jq '.assets|length' < release.json )
215+
216+
# Fetch artifacts
217+
mkdir -p "./release-artifacts/${BINARY}"
218+
pushd "./release-artifacts/${BINARY}" > /dev/null
219+
220+
iter=1
221+
for id in "${ids[@]}"
222+
do
223+
echo " - $iter/$count: downloading asset id: $id..."
224+
curl -s -OJ -L -H "Accept: application/octet-stream" \
225+
-H "Authorization: Token ${GITHUB_TOKEN}" \
226+
"https://api.github.com/repos/${REPO}/releases/assets/$id"
227+
iter=$((iter + 1))
228+
done
229+
230+
pwd
231+
ls -al --color
232+
popd > /dev/null
233+
}
234+
235+
# Check the checksum for a given binary
236+
function check_sha256() {
237+
echo "Checking SHA256 for $1"
238+
shasum -qc $1.sha256
239+
}
240+
241+
# Import GPG keys of the release team members
242+
# This is done in parallel as it can take a while sometimes
243+
function import_gpg_keys() {
244+
GPG_KEYSERVER=${GPG_KEYSERVER:-"keyserver.ubuntu.com"}
245+
SEC="9D4B2B6EB8F97156D19669A9FF0812D491B96798"
246+
WILL="2835EAF92072BC01D188AF2C4A092B93E97CE1E2"
247+
EGOR="E6FC4D4782EB0FA64A4903CCDB7D3555DD3932D3"
248+
MARA="533C920F40E73A21EEB7E9EBF27AEA7E7594C9CF"
249+
MORGAN="2E92A9D8B15D7891363D1AE8AF9E6C43F7F8C4CF"
250+
251+
echo "Importing GPG keys from $GPG_KEYSERVER in parallel"
252+
for key in $SEC $WILL $EGOR $MARA $MORGAN; do
253+
(
254+
echo "Importing GPG key $key"
255+
gpg --no-tty --quiet --keyserver $GPG_KEYSERVER --recv-keys $key
256+
echo -e "5\ny\n" | gpg --no-tty --command-fd 0 --expert --edit-key $key trust;
257+
) &
258+
done
259+
wait
260+
}
261+
262+
# Check the GPG signature for a given binary
263+
function check_gpg() {
264+
echo "Checking GPG Signature for $1"
265+
gpg --no-tty --verify -q $1.asc $1
266+
}

cumulus/.github/workflows/release-50_publish-docker.yml renamed to .github/workflows/release-50_publish-docker.yml

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ name: Release - Publish Docker Image
77
# image and publishes it.
88

99
on:
10-
release:
11-
types:
12-
- published
10+
#TODO: activate automated run later
11+
# release:
12+
# types:
13+
# - published
1314
workflow_dispatch:
1415
inputs:
1516
release_id:
@@ -39,6 +40,18 @@ on:
3940
required: true
4041
type: string
4142
default: parity
43+
binary:
44+
description: Binary to be published
45+
required: true
46+
default: polkadot
47+
type: choice
48+
options:
49+
- polkadot
50+
- staking-miner
51+
- polkadot-parachain
52+
53+
permissions:
54+
contents: write
4255

4356
env:
4457
RELEASE_ID: ${{ inputs.release_id }}
@@ -47,8 +60,8 @@ env:
4760
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4861
DOCKER_OWNER: ${{ inputs.owner || github.repository_owner }}
4962
REPO: ${{ github.repository }}
50-
BINARY: polkadot-parachain
51-
EVENT_ACTION: ${{ github.event.action }}
63+
BINARY: ${{ inputs.binary }}
64+
# EVENT_ACTION: ${{ github.event.action }}
5265
EVENT_NAME: ${{ github.event_name }}
5366
IMAGE_TYPE: ${{ inputs.image_type }}
5467

@@ -58,100 +71,68 @@ jobs:
5871

5972
steps:
6073
- name: Checkout sources
61-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
62-
63-
- name: Prepare temp folder
64-
run: |
65-
TMP=$(mktemp -d)
66-
echo "TMP=$TMP" >> "$GITHUB_ENV"
67-
pwd
68-
ls -al "$TMP"
74+
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
6975

70-
- name: Fetch lib.sh from polkadot repo
71-
working-directory: ${{ env.TMP }}
72-
run: |
73-
curl -O -L \
74-
-H "Accept: application/vnd.github.v3.raw" \
75-
https://raw.githubusercontent.com/paritytech/polkadot/master/scripts/ci/common/lib.sh
76-
77-
chmod a+x lib.sh
78-
ls -al
79-
80-
- name: Fetch release artifacts based on final release tag
76+
#TODO: this step will be needed when automated triggering will work
8177
#this step runs only if the workflow is triggered automatically when new release is published
82-
if: ${{ env.EVENT_NAME == 'release' && env.EVENT_ACTION != '' && env.EVENT_ACTION == 'published' }}
83-
run: |
84-
mkdir -p release-artifacts && cd release-artifacts
85-
86-
for f in $BINARY $BINARY.asc $BINARY.sha256; do
87-
URL="https://github.com/${{ github.event.repository.full_name }}/releases/download/${{ github.event.release.tag_name }}/$f"
88-
echo " - Fetching $f from $URL"
89-
wget "$URL" -O "$f"
90-
done
91-
chmod a+x $BINARY
92-
cp -f ${TMP}/lib.sh .
93-
ls -al
78+
# if: ${{ env.EVENT_NAME == 'release' && env.EVENT_ACTION != '' && env.EVENT_ACTION == 'published' }}
79+
# run: |
80+
# mkdir -p release-artifacts && cd release-artifacts
81+
82+
# for f in $BINARY $BINARY.asc $BINARY.sha256; do
83+
# URL="https://github.com/${{ github.event.repository.full_name }}/releases/download/${{ github.event.release.tag_name }}/$f"
84+
# echo " - Fetching $f from $URL"
85+
# wget "$URL" -O "$f"
86+
# done
87+
# chmod a+x $BINARY
88+
# ls -al
9489

9590
- name: Fetch rc artifacts or release artifacts based on release id
9691
#this step runs only if the workflow is triggered manually
9792
if: ${{ env.EVENT_NAME == 'workflow_dispatch' }}
9893
run: |
99-
. ${TMP}/lib.sh
94+
. ./.github/scripts/common/lib.sh
10095
10196
fetch_release_artifacts
10297
103-
chmod a+x release-artifacts/$BINARY
104-
ls -al
105-
106-
cp -f ${TMP}/lib.sh release-artifacts/
107-
10898
- name: Cache the artifacts
10999
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
110100
with:
111-
key: artifacts-${{ github.sha }}
101+
key: artifacts-${{ env.BINARY }}-${{ github.sha }}
112102
path: |
113-
./release-artifacts/**/*
103+
./release-artifacts/${{ env.BINARY }}/**/*
114104
115105
build-container:
116106
runs-on: ubuntu-latest
117107
needs: fetch-artifacts
118108

119109
steps:
120110
- name: Checkout sources
121-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
111+
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
122112

123113
- name: Get artifacts from cache
124114
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
125115
with:
126-
key: artifacts-${{ github.sha }}
116+
key: artifacts-${{ env.BINARY }}-${{ github.sha }}
127117
fail-on-cache-miss: true
128118
path: |
129-
./release-artifacts/**/*
119+
./release-artifacts/${{ env.BINARY }}/**/*
130120
131121
- name: Check sha256 ${{ env.BINARY }}
132-
working-directory: ./release-artifacts
122+
working-directory: ./release-artifacts/${{ env.BINARY }}
133123
run: |
134-
. ./lib.sh
124+
. ../../.github/scripts/common/lib.sh
135125
136126
echo "Checking binary $BINARY"
137127
check_sha256 $BINARY && echo "OK" || echo "ERR"
138128
139129
- name: Check GPG ${{ env.BINARY }}
140-
working-directory: ./release-artifacts
130+
working-directory: ./release-artifacts/${{ env.BINARY }}
141131
run: |
142-
. ./lib.sh
132+
. ../../.github/scripts/common/lib.sh
143133
import_gpg_keys
144134
check_gpg $BINARY
145135
146-
- name: Build Injected Container image for ${{ env.BINARY }}
147-
env:
148-
IMAGE_NAME: ${{ env.BINARY }}
149-
OWNER: ${{ env.DOCKER_OWNER }}
150-
run: |
151-
ls -al
152-
echo "Building container for $BINARY"
153-
./docker/scripts/build-injected-image.sh
154-
155136
- name: Fetch rc commit and tag
156137
if: ${{ env.IMAGE_TYPE == 'rc' }}
157138
id: fetch_rc_refs
@@ -167,36 +148,55 @@ jobs:
167148
echo "No tag, doing without"
168149
169150
- name: Fetch release tags
170-
if: ${{ env.IMAGE_TYPE == 'release' || env.EVENT_NAME == 'release' && env.EVENT_ACTION != '' && env.EVENT_ACTION == 'published' }}
151+
working-directory: ./release-artifacts/${{ env.BINARY }}
152+
if: ${{ env.IMAGE_TYPE == 'release'}}
171153
id: fetch_release_refs
172154
run: |
173-
VERSION=$(docker run --pull never --rm $DOCKER_OWNER/$BINARY --version | awk '{ print $2 }' )
155+
chmod a+rx $BINARY
156+
VERSION=$(./$BINARY --version | awk '{ print $2 }' )
174157
release=$( echo $VERSION | cut -f1 -d- )
175158
echo "tag=latest" >> $GITHUB_OUTPUT
176159
echo "release=${release}" >> $GITHUB_OUTPUT
177160
161+
- name: Build Injected Container image for polkadot/staking-miner
162+
if: ${{ env.BINARY == 'polkadot' || env.BINARY == 'staking-miner' }}
163+
env:
164+
ARTIFACTS_FOLDER: ./release-artifacts
165+
IMAGE_NAME: ${{ env.BINARY }}
166+
OWNER: ${{ env.DOCKER_OWNER }}
167+
TAGS: ${{ join(steps.fetch_rc_refs.outputs.*, ',') || join(steps.fetch_release_refs.outputs.*, ',') }}
168+
run: |
169+
ls -al
170+
echo "Building container for $BINARY"
171+
./docker/scripts/build-injected.sh
172+
173+
- name: Build Injected Container image for polkadot-parachain
174+
if: ${{ env.BINARY == 'polkadot-parachain' }}
175+
env:
176+
ARTIFACTS_FOLDER: ./release-artifacts
177+
IMAGE_NAME: ${{ env.BINARY }}
178+
OWNER: ${{ env.DOCKER_OWNER }}
179+
DOCKERFILE: docker/dockerfiles/polkadot-parachain/polkadot-parachain_injected.Dockerfile
180+
TAGS: ${{ join(steps.fetch_rc_refs.outputs.*, ',') || join(steps.fetch_release_refs.outputs.*, ',') }}
181+
run: |
182+
ls -al
183+
mkdir -p $ARTIFACTS_FOLDER/specs
184+
cp cumulus/parachains/chain-specs/*.json $ARTIFACTS_FOLDER/specs
185+
186+
echo "Building container for $BINARY"
187+
./docker/scripts/build-injected.sh
178188
179189
- name: Login to Dockerhub
180190
uses: docker/login-action@v2
181191
with:
182192
username: ${{ secrets.DOCKERHUB_USERNAME }}
183193
password: ${{ secrets.DOCKERHUB_TOKEN }}
184194

185-
- name: Tag and Push Container image for ${{ env.BINARY }}
195+
- name: Push Container image for ${{ env.BINARY }}
186196
id: docker_push
187-
env:
188-
TAGS: ${{ join(steps.fetch_rc_refs.outputs.*, ',') || join(steps.fetch_release_refs.outputs.*, ',') }}
189197
run: |
190-
TAGS=${TAGS[@]:-latest}
191-
IFS=',' read -r -a TAG_ARRAY <<< "$TAGS"
192-
193-
echo "The image ${BINARY} will be tagged with ${TAG_ARRAY[*]}"
194-
for TAG in "${TAG_ARRAY[@]}"; do
195-
$ENGINE tag ${DOCKER_OWNER}/${BINARY} ${DOCKER_OWNER}/${BINARY}:${TAG}
196-
$ENGINE push ${DOCKER_OWNER}/${BINARY}:${TAG}
197-
done
198-
199198
$ENGINE images | grep ${BINARY}
199+
$ENGINE push --all-tags ${REGISTRY}/${DOCKER_OWNER}/${BINARY}
200200
201201
- name: Check version for the published image for ${{ env.BINARY }}
202202
env:

.gitlab/pipeline/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ build-linux-substrate:
328328
cut -d ' ' -f 2 | tee ./artifacts/substrate/VERSION;
329329
fi
330330
- sha256sum ./artifacts/substrate/substrate | tee ./artifacts/substrate/substrate.sha256
331-
- cp -r ./docker/substrate_injected.Dockerfile ./artifacts/substrate/
331+
- cp -r ./docker/dockerfiles/substrate_injected.Dockerfile ./artifacts/substrate/
332332
# - printf '\n# building node-template\n\n'
333333
# - ./scripts/ci/node-template-release.sh ./artifacts/substrate/substrate-node-template.tar.gz
334334

0 commit comments

Comments
 (0)