From 62b5684af8b81892c9ad27037f7137fd50db57d2 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 6 Nov 2023 06:59:26 -0800 Subject: [PATCH 1/6] ci: use GitHub Actions Cache --- .github/workflows/ci.yml | 12 +++++++++--- buildTestImages.ts | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a7c5614..42306444 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,10 +59,12 @@ jobs: # The .ts scripts depend upon this - run: npm install --global tsx + - name: Export vars of Actions Runtime for caching + uses: crazy-max/ghaction-github-runtime@v3 + - name: build test images - run: | - docker info - ./buildTestImages.ts + run: ./buildTestImages.ts --buildOpts="--cache-from type=gha --cache-to type=gha,mode=max" + - name: run test images run: ./runTestImages.ts @@ -78,6 +80,10 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + # use GitHub Actions Cache https://github.com/moby/buildkit#github-actions-cache-experimental + cache-from: type=gha + cache-to: type=gha,mode=max + - name: notify on failure if: failure() && github.event_name != 'pull_request' uses: ./.github/actions/notify-status diff --git a/buildTestImages.ts b/buildTestImages.ts index 873e48c7..61661de6 100755 --- a/buildTestImages.ts +++ b/buildTestImages.ts @@ -8,12 +8,13 @@ import { refreshDockerfile } from './makeDockerfile'; refreshDockerfile(); const options = { + buildOpts: { type: 'string' }, match: { short: 'm', type: 'string' }, dry: { type: 'boolean' }, } as const; const { values } = parseArgs({ options }); -const { match, dry } = values; +const { buildOpts, match, dry } = values; const allProposals = readProposals(); @@ -28,7 +29,7 @@ for (const proposal of proposals) { const { name, target } = imageNameForProposalTest(proposal); // 'load' to ensure the images are output to the Docker client. Seems to be necessary // for the CI docker/build-push-action to re-use the cached stages. - const cmd = `docker buildx build --load --tag ${name} --target ${target} .`; + const cmd = `docker buildx build ${buildOpts} --load --tag ${name} --target ${target} .`; console.log(cmd); if (!dry) { execSync(cmd, { stdio: 'inherit' }); From 0584ca2ffa85ba0463e0059b57a8799836013193 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 6 Nov 2023 15:07:22 -0800 Subject: [PATCH 2/6] ci: include scope in GHA cache --- .github/workflows/ci.yml | 2 +- buildTestImages.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42306444..48285f27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: uses: crazy-max/ghaction-github-runtime@v3 - name: build test images - run: ./buildTestImages.ts --buildOpts="--cache-from type=gha --cache-to type=gha,mode=max" + run: ./buildTestImages.ts - name: run test images run: ./runTestImages.ts diff --git a/buildTestImages.ts b/buildTestImages.ts index 61661de6..8a3ccc3b 100755 --- a/buildTestImages.ts +++ b/buildTestImages.ts @@ -8,13 +8,12 @@ import { refreshDockerfile } from './makeDockerfile'; refreshDockerfile(); const options = { - buildOpts: { type: 'string' }, match: { short: 'm', type: 'string' }, dry: { type: 'boolean' }, } as const; const { values } = parseArgs({ options }); -const { buildOpts, match, dry } = values; +const { match, dry } = values; const allProposals = readProposals(); @@ -22,14 +21,24 @@ const proposals = match ? allProposals.filter(p => p.proposalName.includes(match)) : allProposals; +function buildOptsFor(name: string) { + // use GitHub Actions Cache if enabled https://docs.docker.com/build/cache/backends/gha/ + if (process.env.ACTIONS_RUNTIME_TOKEN) { + const refName = process.env.GITHUB_REF_NAME; + return `--cache-from type=gha,scope=${refName}-${name} --cache-to type=gha,mode=max,scope=${refName}-${name}`; + } + return ''; +} + for (const proposal of proposals) { if (!dry) { console.log(`\nBuilding test image for proposal ${proposal.proposalName}`); } const { name, target } = imageNameForProposalTest(proposal); + const opts = buildOptsFor(name); // 'load' to ensure the images are output to the Docker client. Seems to be necessary // for the CI docker/build-push-action to re-use the cached stages. - const cmd = `docker buildx build ${buildOpts} --load --tag ${name} --target ${target} .`; + const cmd = `docker buildx build ${opts} --load --tag ${name} --target ${target} .`; console.log(cmd); if (!dry) { execSync(cmd, { stdio: 'inherit' }); From c43767455bb12aefa675b55fa94f5950e9d6d34b Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 9 Nov 2023 11:05:36 -0800 Subject: [PATCH 3/6] build: dockerignore .git --- .dockerignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index d2905d81..d635f0a0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ # each stage does its own yarn install -node_modules +**/node_modules/ +**/.git From 6e804ec0deb72bf6e37354c86c17dc354debc045 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 9 Nov 2023 11:19:54 -0800 Subject: [PATCH 4/6] build: omit SLOGFILE (~1GB) --- upgrade-test-scripts/run_eval.sh | 2 -- upgrade-test-scripts/run_test.sh | 2 -- upgrade-test-scripts/run_use.sh | 2 -- upgrade-test-scripts/start_agd.sh | 2 -- upgrade-test-scripts/start_to_to.sh | 2 -- 5 files changed, 10 deletions(-) diff --git a/upgrade-test-scripts/run_eval.sh b/upgrade-test-scripts/run_eval.sh index a30d96a4..e9027f78 100644 --- a/upgrade-test-scripts/run_eval.sh +++ b/upgrade-test-scripts/run_eval.sh @@ -6,8 +6,6 @@ set -e source ./env_setup.sh -export SLOGFILE=slog.slog - PROPOSAL_PATH=$1 startAgd diff --git a/upgrade-test-scripts/run_test.sh b/upgrade-test-scripts/run_test.sh index 116d549a..2df0c46f 100644 --- a/upgrade-test-scripts/run_test.sh +++ b/upgrade-test-scripts/run_test.sh @@ -6,8 +6,6 @@ set -e source ./env_setup.sh -export SLOGFILE=slog.slog - PROPOSAL_PATH=$1 startAgd diff --git a/upgrade-test-scripts/run_use.sh b/upgrade-test-scripts/run_use.sh index c1a19076..11948380 100644 --- a/upgrade-test-scripts/run_use.sh +++ b/upgrade-test-scripts/run_use.sh @@ -23,8 +23,6 @@ fi source ./env_setup.sh -export SLOGFILE=slog.slog - echo "Starting agd in the background." startAgd diff --git a/upgrade-test-scripts/start_agd.sh b/upgrade-test-scripts/start_agd.sh index ecdd2092..5003c233 100644 --- a/upgrade-test-scripts/start_agd.sh +++ b/upgrade-test-scripts/start_agd.sh @@ -6,7 +6,5 @@ grep -qF 'printKeys' /root/.bashrc || echo "printKeys" >>/root/.bashrc source ./env_setup.sh -export SLOGFILE=slog.slog - # don't use startAgd() because that backgrounds agd start --log_level warn "$@" diff --git a/upgrade-test-scripts/start_to_to.sh b/upgrade-test-scripts/start_to_to.sh index a58d64ee..974f617a 100644 --- a/upgrade-test-scripts/start_to_to.sh +++ b/upgrade-test-scripts/start_to_to.sh @@ -6,8 +6,6 @@ grep -qF 'printKeys' /root/.bashrc || echo "printKeys" >>/root/.bashrc source ./env_setup.sh -export SLOGFILE=slog.slog - startAgd if [[ -z "${UPGRADE_TO}" ]]; then From acccaf8ab2526f2284566e2383f10a95f967afbe Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 9 Nov 2023 14:24:35 -0800 Subject: [PATCH 5/6] feat: build 'use' images script --- .github/workflows/ci.yml | 3 +++ buildTestImages.ts | 4 ++-- buildUseImages.ts | 36 ++++++++++++++++++++++++++++++++++++ common.ts | 7 +++++-- runTestImages.ts | 4 ++-- 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100755 buildUseImages.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48285f27..41736b78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,6 +62,9 @@ jobs: - name: Export vars of Actions Runtime for caching uses: crazy-max/ghaction-github-runtime@v3 + - name: build use images + run: ./buildUseImages.ts + - name: build test images run: ./buildTestImages.ts diff --git a/buildTestImages.ts b/buildTestImages.ts index 8a3ccc3b..c7a6ef45 100755 --- a/buildTestImages.ts +++ b/buildTestImages.ts @@ -2,7 +2,7 @@ import { parseArgs } from 'node:util'; import { execSync } from 'node:child_process'; -import { imageNameForProposalTest, readProposals } from './common'; +import { imageNameForProposal, readProposals } from './common'; import { refreshDockerfile } from './makeDockerfile'; refreshDockerfile(); @@ -34,7 +34,7 @@ for (const proposal of proposals) { if (!dry) { console.log(`\nBuilding test image for proposal ${proposal.proposalName}`); } - const { name, target } = imageNameForProposalTest(proposal); + const { name, target } = imageNameForProposal(proposal, 'test'); const opts = buildOptsFor(name); // 'load' to ensure the images are output to the Docker client. Seems to be necessary // for the CI docker/build-push-action to re-use the cached stages. diff --git a/buildUseImages.ts b/buildUseImages.ts new file mode 100755 index 00000000..b5e34008 --- /dev/null +++ b/buildUseImages.ts @@ -0,0 +1,36 @@ +#!/usr/bin/env tsx + +import { parseArgs } from 'node:util'; +import { execSync } from 'node:child_process'; +import { imageNameForProposal, readProposals } from './common'; +import { refreshDockerfile } from './makeDockerfile'; + +refreshDockerfile(); + +const options = { + match: { short: 'm', type: 'string' }, + dry: { type: 'boolean' }, +} as const; +const { values } = parseArgs({ options }); + +const { match, dry } = values; + +const allProposals = readProposals(); + +const proposals = match + ? allProposals.filter(p => p.proposalName.includes(match)) + : allProposals; + +for (const proposal of proposals) { + if (!dry) { + console.log(`\nBuilding use image for proposal ${proposal.proposalName}`); + } + const { name, target } = imageNameForProposal(proposal, 'use'); + // 'load' to ensure the images are output to the Docker client. Seems to be necessary + // for the CI docker/build-push-action to re-use the cached stages. + const cmd = `docker buildx build --load --tag ${name} --target ${target} .`; + console.log(cmd); + if (!dry) { + execSync(cmd, { stdio: 'inherit' }); + } +} diff --git a/common.ts b/common.ts index 7bf3e3e4..f74727fc 100644 --- a/common.ts +++ b/common.ts @@ -44,8 +44,11 @@ export function readProposals(): ProposalInfo[] { return proposalPaths.map(readInfo); } -export function imageNameForProposalTest(proposal) { - const target = `test-${proposal.proposalName}`; +export function imageNameForProposal( + proposal: ProposalCommon, + stage: 'use' | 'test', +) { + const target = `${stage}-${proposal.proposalName}`; return { name: `${repository}:${target}`, target, diff --git a/runTestImages.ts b/runTestImages.ts index b9dd11ba..786a7416 100755 --- a/runTestImages.ts +++ b/runTestImages.ts @@ -2,7 +2,7 @@ import { parseArgs } from 'node:util'; import { execSync } from 'node:child_process'; -import { imageNameForProposalTest, readProposals } from './common'; +import { imageNameForProposal, readProposals } from './common'; const options = { match: { short: 'm', type: 'string' }, @@ -19,7 +19,7 @@ const proposals = match for (const proposal of proposals) { console.log(`Running test image for proposal ${proposal.proposalName}`); - const { name } = imageNameForProposalTest(proposal); + const { name } = imageNameForProposal(proposal, 'test'); // 'rm' to remove the container when it exits const cmd = `docker run --rm ${name}`; execSync(cmd, { stdio: 'inherit' }); From b7d41b0765aec1c8c6dfb435a46f020d5af5fcae Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 9 Nov 2023 14:26:53 -0800 Subject: [PATCH 6/6] ci: switch to inline cache --- .github/workflows/ci.yml | 8 ++------ buildTestImages.ts | 12 +----------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41736b78..f70935f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,9 +59,6 @@ jobs: # The .ts scripts depend upon this - run: npm install --global tsx - - name: Export vars of Actions Runtime for caching - uses: crazy-max/ghaction-github-runtime@v3 - - name: build use images run: ./buildUseImages.ts @@ -83,9 +80,8 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - # use GitHub Actions Cache https://github.com/moby/buildkit#github-actions-cache-experimental - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main + cache-to: type=inline - name: notify on failure if: failure() && github.event_name != 'pull_request' diff --git a/buildTestImages.ts b/buildTestImages.ts index c7a6ef45..ce103c6a 100755 --- a/buildTestImages.ts +++ b/buildTestImages.ts @@ -21,24 +21,14 @@ const proposals = match ? allProposals.filter(p => p.proposalName.includes(match)) : allProposals; -function buildOptsFor(name: string) { - // use GitHub Actions Cache if enabled https://docs.docker.com/build/cache/backends/gha/ - if (process.env.ACTIONS_RUNTIME_TOKEN) { - const refName = process.env.GITHUB_REF_NAME; - return `--cache-from type=gha,scope=${refName}-${name} --cache-to type=gha,mode=max,scope=${refName}-${name}`; - } - return ''; -} - for (const proposal of proposals) { if (!dry) { console.log(`\nBuilding test image for proposal ${proposal.proposalName}`); } const { name, target } = imageNameForProposal(proposal, 'test'); - const opts = buildOptsFor(name); // 'load' to ensure the images are output to the Docker client. Seems to be necessary // for the CI docker/build-push-action to re-use the cached stages. - const cmd = `docker buildx build ${opts} --load --tag ${name} --target ${target} .`; + const cmd = `docker buildx build --load --tag ${name} --target ${target} .`; console.log(cmd); if (!dry) { execSync(cmd, { stdio: 'inherit' });