Skip to content

Commit b405a88

Browse files
committed
test: push nitro contracts docker image to ghcr
1 parent b035b13 commit b405a88

File tree

3 files changed

+64
-22
lines changed

3 files changed

+64
-22
lines changed

.github/workflows/build-test.yml

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,27 +223,73 @@ jobs:
223223
# INTEGRATION_TEST_NITRO_CONTRACTS_BRANCH=${{matrix.config.nitro-contracts-branch}} \
224224
# pnpm test:integration
225225

226-
test-integration-anvil:
227-
name: Test (Integration Anvil)
226+
publish-nitro-contracts-image:
227+
name: Publish Nitro Contracts Image
228228
runs-on: ubuntu-latest
229-
env:
230-
NITRO_CONTRACTS_IMAGE_REF: v3.2.0-2f747c7
229+
permissions:
230+
contents: read
231+
packages: write
231232
steps:
232233
- name: Checkout
233234
uses: actions/checkout@v4
234235

236+
- name: Set nitro contracts image
237+
run: |
238+
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts:v3.2.0-2f747c7" >> "$GITHUB_ENV"
239+
235240
- name: Set up Docker Buildx
236241
uses: docker/setup-buildx-action@v3
237242

238-
- name: Build nitro contracts image
243+
- name: Log in to GHCR
244+
uses: docker/login-action@v3
245+
with:
246+
registry: ghcr.io
247+
username: ${{ github.actor }}
248+
password: ${{ secrets.GITHUB_TOKEN }}
249+
250+
- name: Check nitro contracts image
251+
id: check-image
252+
run: |
253+
if docker manifest inspect "${NITRO_CONTRACTS_GHCR_IMAGE}" >/dev/null 2>&1; then
254+
echo "exists=true" >> "$GITHUB_OUTPUT"
255+
else
256+
echo "exists=false" >> "$GITHUB_OUTPUT"
257+
fi
258+
259+
- name: Build and push nitro contracts image
260+
if: steps.check-image.outputs.exists != 'true'
239261
uses: docker/build-push-action@v6
240262
with:
241263
context: ./nitro-contracts
242264
file: ./nitro-contracts/Dockerfile
243-
tags: chain-sdk-nitro-contracts:${{ env.NITRO_CONTRACTS_IMAGE_REF }}
244-
load: true
245-
cache-from: type=gha,scope=chain-sdk-nitro-contracts-${{ env.NITRO_CONTRACTS_IMAGE_REF }}
246-
cache-to: type=gha,mode=max,scope=chain-sdk-nitro-contracts-${{ env.NITRO_CONTRACTS_IMAGE_REF }}
265+
push: true
266+
tags: |
267+
${{ env.NITRO_CONTRACTS_GHCR_IMAGE }}
268+
269+
test-integration-anvil:
270+
name: Test (Integration Anvil)
271+
needs: publish-nitro-contracts-image
272+
runs-on: ubuntu-latest
273+
permissions:
274+
contents: read
275+
packages: read
276+
steps:
277+
- name: Checkout
278+
uses: actions/checkout@v4
279+
280+
- name: Set nitro contracts image
281+
run: |
282+
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts:v3.2.0-2f747c7" >> "$GITHUB_ENV"
283+
284+
- name: Log in to GHCR
285+
uses: docker/login-action@v3
286+
with:
287+
registry: ghcr.io
288+
username: ${{ github.actor }}
289+
password: ${{ secrets.GITHUB_TOKEN }}
290+
291+
- name: Load nitro contracts image
292+
run: docker pull "${NITRO_CONTRACTS_GHCR_IMAGE}"
247293

248294
- name: Setup pnpm
249295
uses: pnpm/action-setup@v4
@@ -288,3 +334,5 @@ jobs:
288334
with:
289335
path: .cache/anvil-rpc-cache.json
290336
key: ${{ runner.os }}-anvil-rpc-cache-${{ github.ref_name }}-${{ github.run_id }}
337+
338+

src/integrationTestHelpers/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ethers } from 'ethers';
44
export const testConstants = {
55
DEFAULT_ANVIL_IMAGE: 'ghcr.io/foundry-rs/foundry:v1.3.1',
66
DEFAULT_NITRO_IMAGE: 'offchainlabs/nitro-node:v3.9.5-66e42c4',
7-
DEFAULT_NITRO_CONTRACTS_REF: 'v3.2.0-2f747c7',
7+
DEFAULT_NITRO_CONTRACTS_IMAGE: 'ghcr.io/offchainlabs/chain-sdk-nitro-contracts:v3.2.0-2f747c7',
88
DEFAULT_L2_CHAIN_ID: 421_337,
99
DEFAULT_L3_CHAIN_ID: 421_338,
1010
DEFAULT_L1_RPC_PORT: 9645,

src/integrationTestHelpers/dockerHelpers.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,18 @@ export function dockerAsync(args: string[]): Promise<string> {
3636
});
3737
}
3838

39-
function sanitizeDockerTagPart(value: string): string {
40-
return value.replace(/[^a-zA-Z0-9_.-]+/g, '-');
41-
}
42-
4339
export function getNitroContractsImage(): string {
44-
const imageTag = `chain-sdk-nitro-contracts:${sanitizeDockerTagPart(
45-
testConstants.DEFAULT_NITRO_CONTRACTS_REF,
46-
)}`;
47-
40+
const image = process.env.NITRO_CONTRACTS_GHCR_IMAGE ?? testConstants.DEFAULT_NITRO_CONTRACTS_IMAGE;
4841
try {
49-
docker(['image', 'inspect', imageTag]);
42+
docker(['image', 'inspect', image]);
43+
return image;
5044
} catch {
5145
const nitroContractsDir = join(process.cwd(), 'nitro-contracts');
5246
const dockerfilePath = join(process.cwd(), 'nitro-contracts', 'Dockerfile');
53-
docker(['build', '-f', dockerfilePath, '-t', imageTag, nitroContractsDir]);
54-
}
47+
docker(['build', '-f', dockerfilePath, '-t', image, nitroContractsDir]);
5548

56-
return imageTag;
49+
return image;
50+
}
5751
}
5852

5953
export function createDockerNetwork(networkName: string) {

0 commit comments

Comments
 (0)