Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker tag logic to prevent undefined in dev tag #3524

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions e2e/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const {
HOST_IP = '127.0.0.1',
GENERATE_ONLY,
TEST_OPENSEARCH = false,
TEST_PLATFORM = 'native',
KEEP_OPEN = false
TEST_PLATFORM = 'native'
} = process.env;

const TEST_HOST = TEST_OPENSEARCH ? OPENSEARCH_HOST : ELASTICSEARCH_HOST;
Expand Down Expand Up @@ -83,6 +82,5 @@ module.exports = {
newId,
TEST_HOST,
TEST_PLATFORM,
KEEP_OPEN,
TERASLICE_PORT
};
2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@terascope/scripts",
"displayName": "Scripts",
"version": "0.66.0",
"version": "0.67.0",
"description": "A collection of terascope monorepo scripts",
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/scripts#readme",
"bugs": {
Expand Down
2 changes: 0 additions & 2 deletions packages/scripts/src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ if (testElasticsearch) {

export const SEARCH_TEST_HOST = testHost;

// This should match a node version from the base-docker-image repo:
// https://github.com/terascope/base-docker-image
// This overrides the value in the Dockerfile
export const NODE_VERSION = process.env.NODE_VERSION || '18.18.2';

Expand Down
21 changes: 10 additions & 11 deletions packages/scripts/src/helpers/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
shouldNPMPublish,
formatDailyTag,
buildDevDockerImage,
removeNodeSuffixFromTag
} from './utils';
import {
yarnPublish,
Expand Down Expand Up @@ -96,7 +97,7 @@ async function publishToDocker(options: PublishOptions) {
const nodeVersionSuffix = `nodev${options.nodeVersion}`;

if (options.type === PublishType.Latest) {
imageToBuild = `${registry}:latest`;
imageToBuild = `${registry}:latest-${nodeVersionSuffix}`;
} else if (options.type === PublishType.Tag || options.type === PublishType.Prerelease) {
const mainPkgInfo = getMainPackageInfo();
if (!mainPkgInfo) {
Expand All @@ -110,32 +111,30 @@ async function publishToDocker(options: PublishOptions) {
}
}

const image = `${registry}:v${mainPkgInfo.version}`;
let exists;
if (options.nodeSuffix) {
exists = await remoteDockerImageExists(`${image}-${nodeVersionSuffix}`);
} else {
exists = await remoteDockerImageExists(image);
let image = `${registry}:v${mainPkgInfo.version}-${nodeVersionSuffix}`;
if (!options.nodeSuffix) {
image = removeNodeSuffixFromTag(image);
}
const exists = await remoteDockerImageExists(image);
if (exists) {
err = new Error(`Docker Image ${image} already exists`);
continue;
}
imageToBuild = image;
} else if (options.type === PublishType.Daily) {
const tag = await formatDailyTag();
imageToBuild = `${registry}:${tag}`;
imageToBuild = `${registry}:${tag}-${nodeVersionSuffix}`;
} else if (options.type === PublishType.Dev) {
imageToBuild = getDevDockerImage();
imageToBuild = getDevDockerImage(options.nodeVersion);
}

const startTime = Date.now();
signale.pending(`building docker for ${options.type} release`);
// TODO: perhaps this should be moved inside the block above and
// repeated for each conditional branch to avoid the duplication on line
// 113, I cant' decide which is worse.
if (options.nodeSuffix) {
imageToBuild = `${imageToBuild}-${nodeVersionSuffix}`;
if (!options.nodeSuffix) {
imageToBuild = removeNodeSuffixFromTag(imageToBuild);
}
signale.debug(`building docker image ${imageToBuild}`);

Expand Down
4 changes: 4 additions & 0 deletions packages/scripts/src/helpers/publish/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ export async function buildDevDockerImage(
signale.success(`built docker image ${devImage}, took ${toHumanTime(Date.now() - startTime)}`);
return devImage;
}

export function removeNodeSuffixFromTag(tag: string) {
return tag.split('-').filter((part) => !part.startsWith('nodev')).join('-');
}
16 changes: 15 additions & 1 deletion packages/scripts/test/publish-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'jest-extended';
import { formatDailyTag } from '../src/helpers/publish/utils';
import { formatDailyTag, removeNodeSuffixFromTag } from '../src/helpers/publish/utils';

describe('Publish', () => {
describe('->formatDailyTag', () => {
Expand All @@ -8,4 +8,18 @@ describe('Publish', () => {
expect(tag).toMatch(/^daily-\d{4}.\d{2}.\d{2}-[A-Za-z0-9]{5,12}$/);
});
});

describe('->removeNodeSuffixFromTag', () => {
it('should return a tag without the node version', async () => {
const tagBefore = 'v0.91.0-nodev18.18.2';
const tagAfter = await removeNodeSuffixFromTag(tagBefore);
expect(tagAfter).toEqual('v0.91.0');
});

it('should not modify a tag without -nodev', async () => {
const tagBefore = 'v0.91.0-v18.18.2';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an actual case that would be encountered? v0.91.0-v18.18.2

If not what are more realistic cases that could be tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could test the daily tags: daily-2024.01.12-fe31c87bf9f and daily-2024.01.12-fe31c87bf9f-nodev16.20.2
This would test a tag with a hyphen in it.

const tagAfter = await removeNodeSuffixFromTag(tagBefore);
expect(tagAfter).toEqual('v0.91.0-v18.18.2');
});
});
});
Loading