Skip to content

Commit 920295c

Browse files
committed
test: push nitro contracts docker image to ghcr
1 parent fb0b7e1 commit 920295c

File tree

3 files changed

+60
-25
lines changed

3 files changed

+60
-25
lines changed

.github/workflows/build-test.yml

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,24 +226,32 @@ jobs:
226226
test-integration-anvil:
227227
name: Test (Integration Anvil)
228228
runs-on: ubuntu-latest
229-
env:
230-
NITRO_CONTRACTS_IMAGE_REF: v3.2.0-2f747c7
229+
permissions:
230+
contents: read
231+
packages: read
231232
steps:
232233
- name: Checkout
233234
uses: actions/checkout@v4
234235

235-
- name: Set up Docker Buildx
236-
uses: docker/setup-buildx-action@v3
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"
237239
238-
- name: Build nitro contracts image
239-
uses: docker/build-push-action@v6
240+
- name: Log in to GHCR
241+
uses: docker/login-action@v3
240242
with:
241-
context: ./nitro-contracts
242-
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 }}
243+
registry: ghcr.io
244+
username: ${{ github.actor }}
245+
password: ${{ secrets.GITHUB_TOKEN }}
246+
247+
- name: Load nitro contracts image
248+
run: |
249+
if ! docker pull "${NITRO_CONTRACTS_GHCR_IMAGE}"; then
250+
docker build \
251+
-f ./nitro-contracts/Dockerfile \
252+
-t "${NITRO_CONTRACTS_GHCR_IMAGE}" \
253+
./nitro-contracts
254+
fi
247255
248256
- name: Setup pnpm
249257
uses: pnpm/action-setup@v4
@@ -288,3 +296,36 @@ jobs:
288296
with:
289297
path: .cache/anvil-rpc-cache.json
290298
key: ${{ runner.os }}-anvil-rpc-cache-${{ github.ref_name }}-${{ github.run_id }}
299+
300+
publish-nitro-contracts-image:
301+
name: Publish Nitro Contracts Image
302+
runs-on: ubuntu-latest
303+
permissions:
304+
contents: read
305+
packages: write
306+
steps:
307+
- name: Checkout
308+
uses: actions/checkout@v4
309+
310+
- name: Set nitro contracts image
311+
run: |
312+
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts:v3.2.0-2f747c7"
313+
314+
- name: Set up Docker Buildx
315+
uses: docker/setup-buildx-action@v3
316+
317+
- name: Log in to GHCR
318+
uses: docker/login-action@v3
319+
with:
320+
registry: ghcr.io
321+
username: ${{ github.actor }}
322+
password: ${{ secrets.GITHUB_TOKEN }}
323+
324+
- name: Build and push nitro contracts image
325+
uses: docker/build-push-action@v6
326+
with:
327+
context: ./nitro-contracts
328+
file: ./nitro-contracts/Dockerfile
329+
push: true
330+
tags: |
331+
${{ env.NITRO_CONTRACTS_GHCR_IMAGE }}

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)