-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR makes the following changes: - Add `images` cmd to scripts - `images list` creates a list of images that CI will need - `images save` will use the list to pull and save those images - Update `test.yml` workflow to check for a docker image cache, create one if needed, then use the cache to load images on all jobs. - Update `test-runner` to load images from cache if in CI - Update `scripts` from 0.80.0 to 0.81.0 ref: #3676 --------- Co-authored-by: Joseph Soto <[email protected]> Co-authored-by: sotojn <[email protected]>
- Loading branch information
1 parent
580d454
commit 7b08514
Showing
14 changed files
with
459 additions
and
30 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,6 @@ website/i18n/* | |
docs/packages/*/api | ||
|
||
.ts-test-config | ||
|
||
# CI test files | ||
images/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { CommandModule } from 'yargs'; | ||
import { ImagesAction } from '../helpers/images/interfaces'; | ||
import { images } from '../helpers/images'; | ||
import { GlobalCMDOptions } from '../helpers/interfaces'; | ||
|
||
interface Options { | ||
action?: ImagesAction; | ||
} | ||
|
||
const cmd: CommandModule<GlobalCMDOptions, Options> = { | ||
command: 'images <action>', | ||
describe: 'Helper function related to docker images.', | ||
builder(yargs) { | ||
return yargs | ||
.example('$0 images list', 'Get the list of docker images needed for a test.') | ||
.example('$0 images save', 'Save the docker images needed for a test.') | ||
.positional('action', { | ||
description: 'The action to take', | ||
choices: Object.values(ImagesAction), | ||
coerce(arg): ImagesAction { | ||
return arg; | ||
}, | ||
}) | ||
.requiresArg('action'); | ||
}, | ||
async handler(argv) { | ||
if (argv.action) { | ||
await images(argv.action); | ||
} | ||
}, | ||
}; | ||
|
||
export = cmd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import fse from 'fs-extra'; | ||
import execa from 'execa'; | ||
import path from 'node:path'; | ||
import * as config from '../config'; | ||
import { ImagesAction } from './interfaces'; | ||
import signale from '../signale'; | ||
|
||
export async function images(action: ImagesAction): Promise<void> { | ||
if (action === ImagesAction.List) { | ||
return createImageList(config.DOCKER_IMAGES_PATH); | ||
} | ||
|
||
if (action === ImagesAction.Save) { | ||
return saveImages(config.DOCKER_CACHE_PATH, config.DOCKER_IMAGES_PATH); | ||
} | ||
} | ||
|
||
/** | ||
* Builds a list of all docker images needed for the teraslice CI pipeline | ||
* @returns Record<string, string> | ||
*/ | ||
async function createImageList(imagesTxtPath: string): Promise<void> { | ||
const filePath = path.join(imagesTxtPath, `${config.DOCKER_LIST_FILE_NAME}`); | ||
|
||
signale.info(`Creating Docker image list at ${filePath}`); | ||
|
||
const list = 'terascope/node-base:18.19.1\n' | ||
+ 'terascope/node-base:20.11.1\n' | ||
+ 'terascope/node-base:22.2.0\n' | ||
+ `${config.ELASTICSEARCH_DOCKER_IMAGE}:6.8.6\n` | ||
+ `${config.ELASTICSEARCH_DOCKER_IMAGE}:7.9.3\n` | ||
+ `${config.OPENSEARCH_DOCKER_IMAGE}:1.3.10\n` | ||
+ `${config.OPENSEARCH_DOCKER_IMAGE}:2.8.0\n` | ||
+ `${config.KAFKA_DOCKER_IMAGE}:7.1.9\n` | ||
+ `${config.ZOOKEEPER_DOCKER_IMAGE}:7.1.9\n` | ||
+ `${config.MINIO_DOCKER_IMAGE}:RELEASE.2020-02-07T23-28-16Z\n` | ||
+ 'kindest/node:v1.30.0'; | ||
|
||
if (!fse.existsSync(imagesTxtPath)) { | ||
await fse.emptyDir(imagesTxtPath); | ||
} | ||
fse.writeFileSync(filePath, list); | ||
} | ||
|
||
async function saveAndZip(imageName:string, imageSavePath: string) { | ||
const fileName = imageName.replace(/[/:]/g, '_'); | ||
const filePath = path.join(imageSavePath, `${fileName}.tar`); | ||
const command = `docker save ${imageName} | gzip > ${filePath}.gz`; | ||
await execa.command(command, { shell: true }); | ||
} | ||
|
||
async function saveImages(imageSavePath: string, imageTxtPath: string): Promise<void> { | ||
try { | ||
if (fse.existsSync(imageSavePath)) { | ||
fse.rmSync(imageSavePath, { recursive: true, force: true }); | ||
} | ||
fse.mkdirSync(imageSavePath); | ||
const imagesString = fse.readFileSync(path.join(imageTxtPath, config.DOCKER_LIST_FILE_NAME), 'utf-8'); | ||
const imagesArray = imagesString.split('\n'); | ||
const pullPromises = imagesArray.map(async (imageName) => { | ||
signale.info(`Pulling Docker image ${imageName}`); | ||
await execa.command(`docker pull ${imageName}`); | ||
}); | ||
await Promise.all(pullPromises); | ||
|
||
for (let i = 0; i < imagesArray.length; i += 2) { | ||
if (typeof imagesArray[i + 1] === 'string') { | ||
await Promise.all([ | ||
saveAndZip(imagesArray[i], imageSavePath), | ||
saveAndZip(imagesArray[i + 1], imageSavePath) | ||
]); | ||
} else { | ||
await saveAndZip(imagesArray[i], imageSavePath); | ||
} | ||
} | ||
} catch (err) { | ||
throw new Error(`Unable to pull and save images due to error: ${err}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum ImagesAction { | ||
List = 'list', | ||
Save = 'save' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
### | ||
## This checks the docker rate limit | ||
### | ||
TOKEN=$(curl -Ss --user "$USER:$PASS" "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" | jq -r .token) | ||
result=$(curl -Ss --head -H "Authorization: Bearer $TOKEN" https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest) | ||
|
||
echo "$result" |