Skip to content

Commit 7c7871a

Browse files
authored
ci: add compatible contracts image for nim-codex docker image (#1186)
* ci: add compatible contracts image for nim-codex docker image * ci: with submodules * ci: with submodules on correct place * ci: remove double dash * ci: avoiding artifact conflicts * ci: add labels to arch images * ci: correct way to add label to arch images * ci: correct contract label * ci: avoid building contracts image and use contracts commit hash * refactor: better way to get the hash
1 parent b92f79a commit 7c7871a

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

.github/workflows/docker-reusable.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ on:
5959
required: false
6060
type: string
6161
default: false
62+
contract_image:
63+
description: Specifies compatible smart contract image
64+
required: false
65+
type: string
6266

6367

6468
env:
@@ -71,6 +75,7 @@ env:
7175
TAG_LATEST: ${{ inputs.tag_latest }}
7276
TAG_SHA: ${{ inputs.tag_sha }}
7377
TAG_SUFFIX: ${{ inputs.tag_suffix }}
78+
CONTRACT_IMAGE: ${{ inputs.contract_image }}
7479
# Tests
7580
TESTS_SOURCE: codex-storage/cs-codex-dist-tests
7681
TESTS_BRANCH: master
@@ -80,8 +85,19 @@ env:
8085

8186

8287
jobs:
88+
compute:
89+
name: Compute build ID
90+
runs-on: ubuntu-latest
91+
outputs:
92+
build_id: ${{ steps.build_id.outputs.build_id }}
93+
steps:
94+
- name: Generate unique build id
95+
id: build_id
96+
run: echo "build_id=$(openssl rand -hex 5)" >> $GITHUB_OUTPUT
97+
8398
# Build platform specific image
8499
build:
100+
needs: compute
85101
strategy:
86102
fail-fast: true
87103
matrix:
@@ -108,11 +124,19 @@ jobs:
108124
- name: Checkout
109125
uses: actions/checkout@v4
110126

127+
- name: Docker - Variables
128+
run: |
129+
# Create contract label for compatible contract image if specified
130+
if [[ -n "${{ env.CONTRACT_IMAGE }}" ]]; then
131+
echo "CONTRACT_LABEL=storage.codex.nim-codex.blockchain-image=${{ env.CONTRACT_IMAGE }}" >>$GITHUB_ENV
132+
fi
133+
111134
- name: Docker - Meta
112135
id: meta
113136
uses: docker/metadata-action@v5
114137
with:
115138
images: ${{ env.DOCKER_REPO }}
139+
labels: ${{ env.CONTRACT_LABEL }}
116140

117141
- name: Docker - Set up Buildx
118142
uses: docker/setup-buildx-action@v3
@@ -147,7 +171,7 @@ jobs:
147171
- name: Docker - Upload digest
148172
uses: actions/upload-artifact@v4
149173
with:
150-
name: digests-${{ matrix.target.arch }}
174+
name: digests-${{ needs.compute.outputs.build_id }}-${{ matrix.target.arch }}
151175
path: /tmp/digests/*
152176
if-no-files-found: error
153177
retention-days: 1
@@ -159,7 +183,7 @@ jobs:
159183
runs-on: ubuntu-latest
160184
outputs:
161185
version: ${{ steps.meta.outputs.version }}
162-
needs: build
186+
needs: [build, compute]
163187
steps:
164188
- name: Docker - Variables
165189
run: |
@@ -183,11 +207,16 @@ jobs:
183207
else
184208
echo "TAG_RAW=false" >>$GITHUB_ENV
185209
fi
210+
211+
# Create contract label for compatible contract image if specified
212+
if [[ -n "${{ env.CONTRACT_IMAGE }}" ]]; then
213+
echo "CONTRACT_LABEL=storage.codex.nim-codex.blockchain-image=${{ env.CONTRACT_IMAGE }}" >>$GITHUB_ENV
214+
fi
186215
187216
- name: Docker - Download digests
188217
uses: actions/download-artifact@v4
189218
with:
190-
pattern: digests-*
219+
pattern: digests-${{ needs.compute.outputs.build_id }}-*
191220
merge-multiple: true
192221
path: /tmp/digests
193222

@@ -199,6 +228,7 @@ jobs:
199228
uses: docker/metadata-action@v5
200229
with:
201230
images: ${{ env.DOCKER_REPO }}
231+
labels: ${{ env.CONTRACT_LABEL }}
202232
flavor: |
203233
latest=${{ env.TAG_LATEST }}
204234
suffix=${{ env.TAG_SUFFIX }},onlatest=true

.github/workflows/docker.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,25 @@ on:
2020

2121

2222
jobs:
23+
get-contracts-hash:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
hash: ${{ steps.get-hash.outputs.hash }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
submodules: true
31+
32+
- name: Get submodule short hash
33+
id: get-hash
34+
run: |
35+
hash=$(git rev-parse --short HEAD:vendor/codex-contracts-eth)
36+
echo "hash=$hash" >> $GITHUB_OUTPUT
2337
build-and-push:
2438
name: Build and Push
2539
uses: ./.github/workflows/docker-reusable.yml
40+
needs: get-contracts-hash
2641
with:
2742
tag_latest: ${{ github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/') }}
28-
secrets: inherit
43+
contract_image: "codexstorage/codex-contracts-eth:sha-${{ needs.get-contracts-hash.outputs.hash }}"
44+
secrets: inherit

0 commit comments

Comments
 (0)