-
Notifications
You must be signed in to change notification settings - Fork 1
214 lines (212 loc) · 9.15 KB
/
polkadot.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
name: Build Polkadot binaries and images
on:
push:
branches:
paths:
- .github/workflows/polkadot.yml
- dockerfiles/Dockerfile-env-test
- dockerfiles/Dockerfile-env-amd64
- dockerfiles/Dockerfile-amd64
- config.yml
pull_request:
paths:
- .github/workflows/polkadot.yml
- dockerfiles/Dockerfile-env-test
- dockerfiles/Dockerfile-env-amd64
- dockerfiles/Dockerfile-amd64
- config.yml
env:
REGISTRY: ghcr.io
jobs:
build-docker-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
ENV_IMAGE_NAME: kogeler/substrate-cross-compiler-env
outputs:
image-name: ${{ steps.env-vars.outputs.image-name }}
strategy:
fail-fast: false
matrix:
debian-versions: [bullseye, bookworm]
rust-versions: [1.81.0]
clang-versions: [17, 18]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set environmental variables
id: env-vars
run: |
echo "ENV_FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.ENV_IMAGE_NAME }}:debian-${{ matrix.debian-versions }}-rust-${{ matrix.rust-versions }}-clang-${{ matrix.clang-versions }}" >> "$GITHUB_ENV"
echo "image-name=${{ env.REGISTRY }}/${{ env.ENV_IMAGE_NAME }}" >> "$GITHUB_OUTPUT"
echo "CODE_GIT_REPO=$(cat config.yml | yq -r '.polkadot.code_git_repo' | tr -d '\n')" >> "$GITHUB_ENV"
echo "CODE_GIT_REF=$(cat config.yml | yq -r '.polkadot.code_git_ref' | tr -d '\n')" >> "$GITHUB_ENV"
echo "PUSH_GIT_REF=$(cat config.yml | yq -r '.polkadot.push_git_ref' | tr -d '\n')" >> "$GITHUB_ENV"
- name: Check Docker image
run: |
if docker manifest inspect "${ENV_FULL_IMAGE_NAME}" > /dev/null 2>&1; then
echo "Image ${ENV_FULL_IMAGE_NAME} exists in the registry."
echo "CONTINUE_IMAGE_BUILD=false" >> "$GITHUB_ENV"
else
echo "Image ${ENV_FULL_IMAGE_NAME} does not exist in the registry."
echo "CONTINUE_IMAGE_BUILD=true" >> "$GITHUB_ENV"
fi
- name: Set up QEMU
if: env.CONTINUE_IMAGE_BUILD == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: env.CONTINUE_IMAGE_BUILD == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to Container registry
if: env.CONTINUE_IMAGE_BUILD == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Extract metadata (tags, labels) for Docker
if: env.CONTINUE_IMAGE_BUILD == 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.ENV_IMAGE_NAME }}
- name: Build and push Docker image
if: env.CONTINUE_IMAGE_BUILD == 'true'
uses: docker/build-push-action@v6
with:
context: dockerfiles
file: dockerfiles/Dockerfile-env-amd64
push: false
load: true
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DEBIAN_VERSION=${{ matrix.debian-versions }}
RUST_STABLE_VERSION=${{ matrix.rust-versions }}
CLANG_VERSION=${{ matrix.clang-versions }}
tags: ${{ env.ENV_FULL_IMAGE_NAME }},image-to-test:latest
- name: Switch to default Docker builder
if: env.CONTINUE_IMAGE_BUILD == 'true'
run: docker buildx use default
- name: Build node to test Docker image
if: env.CONTINUE_IMAGE_BUILD == 'true'
uses: docker/build-push-action@v6
with:
context: dockerfiles
file: dockerfiles/Dockerfile-env-test
push: false
pull: false
build-args: |
IMAGE_VERSION=image-to-test:latest
GIT_REPO=${{ env.CODE_GIT_REPO }}
GIT_REF=${{ env.CODE_GIT_REF }}
tags: test-build-image
- name: Push Docker image
if: ${{ env.CONTINUE_IMAGE_BUILD == 'true' && github.ref == env.PUSH_GIT_REF }}
run: docker push ${{ env.ENV_FULL_IMAGE_NAME }}
build-binaries:
runs-on: ubuntu-latest
needs: [build-docker-images]
permissions:
contents: write
packages: write
container:
image: ${{ needs.build-docker-images.outputs.image-name }}:debian-${{ matrix.debian-versions }}-rust-${{ matrix.rust-versions }}-clang-${{ matrix.clang-versions }}
options: --user 0:0 --privileged -v /var/run/docker.sock:/var/run/docker.sock
strategy:
fail-fast: false
matrix:
debian-versions: [bullseye, bookworm]
rust-versions: [1.81.0]
clang-versions: [17, 18]
rustc-targets: ["x86-64-v2", "x86-64-v3", "x86-64-v4"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set environmental variables
run: |
echo "CODE_GIT_REPO=$(cat config.yml | yq -r '.polkadot.code_git_repo' | tr -d '\n')" >> "$GITHUB_ENV"
CODE_GIT_REF=$(cat config.yml | yq -r '.polkadot.code_git_ref' | tr -d '\n')
echo "CODE_GIT_REF=${CODE_GIT_REF}" >> $GITHUB_ENV
IMAGE_NAME=$(cat config.yml | yq -r '.polkadot.image_name' | tr -d '\n')
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
echo "PUSH_GIT_REF=$(cat config.yml | yq -r '.polkadot.push_git_ref' | tr -d '\n')" >> "$GITHUB_ENV"
BUILD_VERSION="debian-${{ matrix.debian-versions }}-rust-${{ matrix.rust-versions }}-clang-${{ matrix.clang-versions }}-${{ matrix.rustc-targets }}"
echo "BINARY_FILE_NAME=${CODE_GIT_REF}-${BUILD_VERSION}" >> $GITHUB_ENV
echo "EXECUTE_WORKER_BINARY_FILE_NAME=${CODE_GIT_REF}-execute-worker-${BUILD_VERSION}" >> $GITHUB_ENV
echo "PREPARE_WORKER_BINARY_FILE_NAME=${CODE_GIT_REF}-prepare-worker-${BUILD_VERSION}" >> $GITHUB_ENV
echo "FULL_IMAGE_NAME=${{ env.REGISTRY }}/${IMAGE_NAME}:${CODE_GIT_REF}-${BUILD_VERSION}" >> "$GITHUB_ENV"
git config --global --add safe.directory $(pwd)
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ env.CODE_GIT_REPO }}
path: git-content
ref: ${{ env.CODE_GIT_REF }}
- name: Build binaries
working-directory: ./git-content
env:
RUSTFLAGS: "-C target-cpu=${{ matrix.rustc-targets }}"
run: |
export WASM_BUILD_WORKSPACE_HINT=$(pwd)
env
cargo build --profile production --locked --bin polkadot --bin polkadot-execute-worker --bin polkadot-prepare-worker --target x86_64-unknown-linux-gnu
export BINARIES_DIR=/opt/cargo_target/x86_64-unknown-linux-gnu/production
ls ${BINARIES_DIR}
mkdir ${GITHUB_WORKSPACE}/artifacts
cp ${BINARIES_DIR}/polkadot ${GITHUB_WORKSPACE}/artifacts
cp ${BINARIES_DIR}/polkadot-execute-worker ${GITHUB_WORKSPACE}/artifacts
cp ${BINARIES_DIR}/polkadot-prepare-worker ${GITHUB_WORKSPACE}/artifacts
- name: Create GitHub release
if: ${{ github.ref == env.PUSH_GIT_REF }}
uses: "actions/github-script@v6"
with:
script: |
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: process.env.CODE_GIT_REF,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.CODE_GIT_REF,
});
} catch (error) {
core.notice(error.message);
}
- name: Upload binaries to GitHub release
if: ${{ github.ref == env.PUSH_GIT_REF }}
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir gh_artifacts
cp artifacts/polkadot gh_artifacts/${BINARY_FILE_NAME}
cp artifacts/polkadot-execute-worker gh_artifacts/${EXECUTE_WORKER_BINARY_FILE_NAME}
cp artifacts/polkadot-prepare-worker gh_artifacts/${PREPARE_WORKER_BINARY_FILE_NAME}
gh release upload ${{ env.CODE_GIT_REF }} gh_artifacts/${BINARY_FILE_NAME} --clobber
gh release upload ${{ env.CODE_GIT_REF }} gh_artifacts/${EXECUTE_WORKER_BINARY_FILE_NAME} --clobber
gh release upload ${{ env.CODE_GIT_REF }} gh_artifacts/${PREPARE_WORKER_BINARY_FILE_NAME} --clobber
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
file: dockerfiles/Dockerfile-amd64
context: artifacts
push: ${{ github.ref == env.PUSH_GIT_REF }}
load: true
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DEBIAN_VERSION=${{ matrix.debian-versions }}
tags: ${{ env.FULL_IMAGE_NAME }}