Skip to content

Commit

Permalink
Create repo specific images lists (#3702)
Browse files Browse the repository at this point in the history
This PR makes the following changes:
- Add ability to get the repo name out of the root `package.json`. This
allows other repos that use ts-scripts to get a custom docker image list
to use to create a cache specific to that repo. Valid repos are
`elasticsearch-assets`, `kafka-asset-bundle`, `file-asssets-bundle`, and
`teraslice-workspace`.
- Update tests 
- Bump scripts from version 0.81.4 to 0.82.0
  • Loading branch information
busma13 authored Jul 25, 2024
1 parent 6ebe35d commit ef270af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
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.81.4",
"version": "0.82.0",
"description": "A collection of terascope monorepo scripts",
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/scripts#readme",
"bugs": {
Expand Down
24 changes: 20 additions & 4 deletions packages/scripts/src/helpers/images/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as config from '../config';
import { ImagesAction } from './interfaces';
import signale from '../signale';
import { dockerPull, saveAndZip } from '../scripts';
import { getRootInfo } from '../misc';

export async function images(action: ImagesAction): Promise<void> {
if (action === ImagesAction.List) {
Expand All @@ -20,11 +21,23 @@ export async function images(action: ImagesAction): Promise<void> {
*/
export async function createImageList(): Promise<void> {
signale.info(`Creating Docker image list at ${config.DOCKER_IMAGE_LIST_PATH}`);
const repo = getRootInfo().name;
let list;
if (repo === 'elasticsearch-assets') {
list = `${config.ELASTICSEARCH_DOCKER_IMAGE}:${config.__DEFAULT_ELASTICSEARCH6_VERSION}\n`
+ `${config.ELASTICSEARCH_DOCKER_IMAGE}:${config.__DEFAULT_ELASTICSEARCH7_VERSION}\n`
+ `${config.OPENSEARCH_DOCKER_IMAGE}:${config.__DEFAULT_OPENSEARCH1_VERSION}\n`
+ `${config.OPENSEARCH_DOCKER_IMAGE}:${config.__DEFAULT_OPENSEARCH2_VERSION}`;
} else if (repo === 'kafka-asset-bundle') {
list = `${config.KAFKA_DOCKER_IMAGE}:${config.KAFKA_IMAGE_VERSION}\n`
+ `${config.ZOOKEEPER_DOCKER_IMAGE}:${config.KAFKA_IMAGE_VERSION}`;
} else if (repo === 'file-assets-bundle') {
list = `${config.MINIO_DOCKER_IMAGE}:${config.MINIO_VERSION}`;
} else if (repo === 'teraslice-workspace') {
const baseImages: string = config.TEST_NODE_VERSIONS
.reduce((acc: string, version: string) => `${acc}${config.BASE_DOCKER_IMAGE}:${version}\n`, '');

const baseImages: string = config.TEST_NODE_VERSIONS
.reduce((acc: string, version: string) => `${acc}${config.BASE_DOCKER_IMAGE}:${version}\n`, '');

const list = `${baseImages}`
list = `${baseImages}`
+ `${config.ELASTICSEARCH_DOCKER_IMAGE}:${config.__DEFAULT_ELASTICSEARCH6_VERSION}\n`
+ `${config.ELASTICSEARCH_DOCKER_IMAGE}:${config.__DEFAULT_ELASTICSEARCH7_VERSION}\n`
+ `${config.OPENSEARCH_DOCKER_IMAGE}:${config.__DEFAULT_OPENSEARCH1_VERSION}\n`
Expand All @@ -33,6 +46,9 @@ export async function createImageList(): Promise<void> {
+ `${config.ZOOKEEPER_DOCKER_IMAGE}:${config.KAFKA_IMAGE_VERSION}\n`
+ `${config.MINIO_DOCKER_IMAGE}:${config.MINIO_VERSION}\n`
+ `${config.KIND_DOCKER_IMAGE}:${config.KIND_VERSION}`;
} else {
throw new Error(`Repo ${repo} is not supported.`);
}

if (!fse.existsSync(config.DOCKER_IMAGES_PATH)) {
await fse.emptyDir(config.DOCKER_IMAGES_PATH);
Expand Down
9 changes: 8 additions & 1 deletion packages/scripts/test/images-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import * as scripts from '../src/helpers/scripts';
import * as config from '../src/helpers/config';

describe('images', () => {
afterEach(() => {
if (fs.existsSync(config.DOCKER_IMAGES_PATH)) {
fs.rmSync(config.DOCKER_IMAGES_PATH, { recursive: true, force: true });
}
});

describe('list', () => {
it('should create a txt file containing a list of images', async () => {
it('should create a txt file containing a list of images for teraslice testing', async () => {
await createImageList();
expect(fs.existsSync(config.DOCKER_IMAGE_LIST_PATH)).toBe(true);
const fileContents = fs.readFileSync(config.DOCKER_IMAGE_LIST_PATH, 'utf-8');
Expand All @@ -30,6 +36,7 @@ describe('images', () => {
});

it('should call dockerPull and saveAndZip for all images from DOCKER_IMAGE_LIST_PATH', async () => {
await createImageList();
await saveImages();
expect(fs.existsSync(config.DOCKER_CACHE_PATH)).toBe(true);
expect(scripts.dockerPull).toHaveBeenCalledTimes(11);
Expand Down

0 comments on commit ef270af

Please sign in to comment.