Skip to content

Commit

Permalink
[docker] Check that version matches tag before publishing release images
Browse files Browse the repository at this point in the history
We currently dont check that the tag and the aptos-node cargo.toml version match

This ensures that before publish we have to check the tag and version match only for release images

Test Plan: wrote unittests and added a testing workflow

made the script possibel to unittest
  • Loading branch information
perryjrandall committed Mar 19, 2024
1 parent bba6feb commit f83e6c3
Show file tree
Hide file tree
Showing 8 changed files with 2,519 additions and 128 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test-copy-images-to-dockerhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test Release Images
on:
pull_request:
paths:
- "docker/release-images.mjs"
- "docker/__tests__/**"
push:
branches:
- main
paths:
- "docker/release-images.mjs"
- "docker/__tests__/**"

permissions:
contents: read

jobs:
test-copy-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: .node-version
- uses: pnpm/action-setup@v2
- run: pnpm install
- name: Test Release Images
run: ./docker/test.sh
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aptos-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "aptos-node"
description = "Aptos node"
version = "1.7.0"
version = "0.0.0-main"

# Workspace inherited keys
authors = { workspace = true }
Expand Down
30 changes: 30 additions & 0 deletions docker/__tests__/release-images.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env -S pnpm test release-images.test.js

import { assertTagMatchesSourceVersion, getImageReleaseGroupByImageTagPrefix, isReleaseImage } from '../release-images.mjs';

describe('releaseImages', () => {
it('gets aptos-node as the default image group', () => {
const prefix = 'image-banana';
const releaseGroup = getImageReleaseGroupByImageTagPrefix(prefix);
expect(releaseGroup).toEqual('aptos-node');
});
it('gets indexer image group', () => {
const prefix = 'aptos-indexer-grpc-vX.Y.Z';
const releaseGroup = getImageReleaseGroupByImageTagPrefix(prefix);
expect(releaseGroup).toEqual('aptos-indexer-grpc');
});
it('gets aptos-node as the node image group', () => {
const prefix = 'aptos-node-vX.Y.Z';
const releaseGroup = getImageReleaseGroupByImageTagPrefix(prefix);
expect(releaseGroup).toEqual('aptos-node');
});
it('determines image is a release image', () => {
expect(isReleaseImage("nightly-banana")).toEqual(false);
expect(isReleaseImage("aptos-node-v1.2.3")).toEqual(true);
});
it('asserts version match', () => {
// toThrow apparently matches a prefix, so this works but it does actually test against the real config version
// Which... hilariously means this would fail if the version was ever 0.0.0
expect(() => assertTagMatchesSourceVersion("aptos-node-v0.0.0")).toThrow("image tag does not match cargo version: aptos-node-v0.0.0");
});
});
Loading

0 comments on commit f83e6c3

Please sign in to comment.