Skip to content

Commit

Permalink
feat: push completed image
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 6, 2023
1 parent 890b2e2 commit 7ac85a1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
46 changes: 44 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
# see https://docs.docker.com/build/ci/github-actions/test-before-push/
test-proposals:
runs-on: ubuntu-latest
timeout-minutes: 60
Expand All @@ -29,12 +34,49 @@ jobs:
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
echo "=== After cleanup:"
df -h
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
# see https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ env.REGISTRY }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# The .ts scripts depend upon this
- run: yarn global add tsx

- name: build test images
run: ./buildTestImages.ts
run: |
docker info
./buildTestImages.ts
- name: run test images
run: ./runTestImages.ts

# XXX this should be instant because all the stages were already built in the steps above
# but it's re-building the last stage. This is deemed good enough for now.
# see https://github.com/moby/moby/issues/34715
- name: Build and push complete image
uses: docker/build-push-action@v5
with:
context: .
# push to registry on every repo push. A PR #2 will push with tag `pr-2` and `main` will have tag `main`.
# See https://github.com/docker/metadata-action?tab=readme-ov-file#basic.
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: notify on failure
if: failure() && github.event_name != 'pull_request'
uses: ./.github/actions/notify-status
Expand Down
4 changes: 3 additions & 1 deletion buildTestImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ for (const proposal of proposals) {
console.log(`\nBuilding test image for proposal ${proposal.proposalName}`);
}
const { name, target } = imageNameForProposalTest(proposal);
const cmd = `docker build --tag ${name} --target ${target} .`;
// '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' });
Expand Down
17 changes: 16 additions & 1 deletion makeDockerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,22 @@ RUN ./run_use.sh ${proposalIdentifier}:${proposalName}
# TEST ${proposalName}
FROM use-${proposalName} as test-${proposalName}
# XXX the test files were already copied in the "use" stage
WORKDIR /usr/src/upgrade-test-scripts
SHELL ["/bin/bash", "-c"]
ENTRYPOINT ./run_test.sh ${proposalIdentifier}:${proposalName}
`;
},
/**
* The last target in the file, for untargeted `docker build`
*/
DEFAULT(lastProposal: ProposalInfo) {
return `
# DEFAULT
FROM use-${lastProposal.proposalName}
WORKDIR /usr/src/upgrade-test-scripts
SHELL ["/bin/bash", "-c"]
ENTRYPOINT ./start_agd.sh
`;
},
};
Expand Down Expand Up @@ -166,10 +178,13 @@ for (const proposal of readProposals()) {
blocks.push(stage.EXECUTE(proposal));
}

// The stages must be output in dependency order because if the builder finds a FROM
// that it hasn't built yet, it will search for it in the registry. But it won't be there!
blocks.push(stage.USE(proposal));
blocks.push(stage.TEST(proposal));
previousProposal = proposal;
}
blocks.push(stage.DEFAULT(previousProposal!));

export function refreshDockerfile() {
const contents = blocks.join('\n');
Expand Down

0 comments on commit 7ac85a1

Please sign in to comment.