Allow customization of container registry and image version

pull/596/head
Andrew Kahr 2023-11-14 19:27:21 -08:00
parent aae14202b7
commit ab9d6f5eea
7 changed files with 55 additions and 16 deletions

View File

@ -124,6 +124,14 @@ inputs:
'Isolation mode to use for the docker container. Can be one of process, hyperv, or default. Default will pick the
default mode as described by Microsoft where server versions use process and desktop versions use hyperv. Only
applicable on Windows'
containerRegistryRepository:
required: false
default: 'unityci/editor'
description: 'Container registry url to pull image from. Only applicable if customImage is not set.'
containerRegistryImageVersion:
required: false
default: '3'
description: 'Container registry image version. Only applicable if customImage is not set.'
allowDirtyBuild:
required: false
default: ''

17
dist/index.js generated vendored
View File

@ -316,6 +316,8 @@ class BuildParameters {
dockerCpuLimit: input_1.default.dockerCpuLimit,
dockerMemoryLimit: input_1.default.dockerMemoryLimit,
dockerIsolationMode: input_1.default.dockerIsolationMode,
containerRegistryRepository: input_1.default.containerRegistryRepository,
containerRegistryImageVersion: input_1.default.containerRegistryImageVersion,
providerStrategy: cloud_runner_options_1.default.providerStrategy,
buildPlatform: cloud_runner_options_1.default.buildPlatform,
kubeConfig: cloud_runner_options_1.default.kubeConfig,
@ -6386,7 +6388,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const platform_1 = __importDefault(__nccwpck_require__(9707));
class ImageTag {
constructor(imageProperties) {
const { editorVersion, targetPlatform, customImage, cloudRunnerBuilderPlatform } = imageProperties;
const { editorVersion, targetPlatform, customImage, cloudRunnerBuilderPlatform, containerRegistryRepository, containerRegistryImageVersion, } = imageProperties;
if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`);
}
@ -6394,15 +6396,14 @@ class ImageTag {
// Either
this.customImage = customImage;
// Or
this.repository = 'unityci';
this.name = 'editor';
this.repository = containerRegistryRepository;
this.editorVersion = editorVersion;
this.targetPlatform = targetPlatform;
this.cloudRunnerBuilderPlatform = cloudRunnerBuilderPlatform;
const isCloudRunnerLocal = cloudRunnerBuilderPlatform === 'local' || cloudRunnerBuilderPlatform === undefined;
this.builderPlatform = ImageTag.getTargetPlatformToTargetPlatformSuffixMap(targetPlatform, editorVersion);
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefixes(isCloudRunnerLocal ? process.platform : cloudRunnerBuilderPlatform);
this.imageRollingVersion = 3; // Will automatically roll to the latest non-breaking version.
this.imageRollingVersion = Number(containerRegistryImageVersion); // Will automatically roll to the latest non-breaking version.
}
static get versionPattern() {
return /^(20\d{2}\.\d\.\w{3,4}|3)$/;
@ -6508,7 +6509,7 @@ class ImageTag {
return `${this.imagePlatformPrefix}-${versionAndPlatform}-${this.imageRollingVersion}`;
}
get image() {
return `${this.repository}/${this.name}`.replace(/^\/+/, '');
return `${this.repository}`.replace(/^\/+/, '');
}
toString() {
const { image, tag, customImage } = this;
@ -6953,6 +6954,12 @@ class Input {
static get dockerIsolationMode() {
return Input.getInput('dockerIsolationMode') || 'default';
}
static get containerRegistryRepository() {
return Input.getInput('containerRegistryUrl');
}
static get containerRegistryImageVersion() {
return Input.getInput('containerRegistryImageVersion');
}
static ToEnvVarFormat(input) {
if (input.toUpperCase() === input) {
return input;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -44,6 +44,8 @@ class BuildParameters {
public dockerCpuLimit!: string;
public dockerMemoryLimit!: string;
public dockerIsolationMode!: string;
public containerRegistryRepository!: string;
public containerRegistryImageVersion!: string;
public customParameters!: string;
public sshAgent!: string;
@ -170,6 +172,8 @@ class BuildParameters {
dockerCpuLimit: Input.dockerCpuLimit,
dockerMemoryLimit: Input.dockerMemoryLimit,
dockerIsolationMode: Input.dockerIsolationMode,
containerRegistryRepository: Input.containerRegistryRepository,
containerRegistryImageVersion: Input.containerRegistryImageVersion,
providerStrategy: CloudRunnerOptions.providerStrategy,
buildPlatform: CloudRunnerOptions.buildPlatform,
kubeConfig: CloudRunnerOptions.kubeConfig,

View File

@ -5,11 +5,11 @@ describe('ImageTag', () => {
editorVersion: '2099.9.f9f9',
targetPlatform: 'Test',
builderPlatform: '',
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
};
const defaults = {
repository: 'unityci',
name: 'editor',
image: 'unityci/editor',
};
@ -21,8 +21,7 @@ describe('ImageTag', () => {
it('accepts parameters and sets the right properties', () => {
const image = new ImageTag(testImageParameters);
expect(image.repository).toStrictEqual('unityci');
expect(image.name).toStrictEqual('editor');
expect(image.repository).toStrictEqual('unityci/editor');
expect(image.editorVersion).toStrictEqual(testImageParameters.editorVersion);
expect(image.targetPlatform).toStrictEqual(testImageParameters.targetPlatform);
expect(image.builderPlatform).toStrictEqual(testImageParameters.builderPlatform);
@ -53,6 +52,8 @@ describe('ImageTag', () => {
const image = new ImageTag({
editorVersion: '2099.1.1111',
targetPlatform: testImageParameters.targetPlatform,
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
});
switch (process.platform) {
case 'win32':
@ -68,6 +69,8 @@ describe('ImageTag', () => {
editorVersion: '2099.1.1111',
targetPlatform: testImageParameters.targetPlatform,
customImage: `${defaults.image}:2099.1.1111@347598437689743986`,
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
});
expect(image.toString()).toStrictEqual(image.customImage);
@ -77,6 +80,8 @@ describe('ImageTag', () => {
const image = new ImageTag({
editorVersion: '2019.2.11f1',
targetPlatform: 'WebGL',
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
});
switch (process.platform) {
@ -93,6 +98,8 @@ describe('ImageTag', () => {
const image = new ImageTag({
editorVersion: '2019.2.11f1',
targetPlatform: 'NoTarget',
containerRegistryRepository: 'unityci/editor',
containerRegistryImageVersion: '3',
});
switch (process.platform) {

View File

@ -2,7 +2,6 @@ import Platform from './platform';
class ImageTag {
public repository: string;
public name: string;
public cloudRunnerBuilderPlatform!: string;
public editorVersion: string;
public targetPlatform: string;
@ -12,7 +11,14 @@ class ImageTag {
public imagePlatformPrefix: string;
constructor(imageProperties: { [key: string]: string }) {
const { editorVersion, targetPlatform, customImage, cloudRunnerBuilderPlatform } = imageProperties;
const {
editorVersion,
targetPlatform,
customImage,
cloudRunnerBuilderPlatform,
containerRegistryRepository,
containerRegistryImageVersion,
} = imageProperties;
if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`);
@ -23,8 +29,7 @@ class ImageTag {
this.customImage = customImage;
// Or
this.repository = 'unityci';
this.name = 'editor';
this.repository = containerRegistryRepository;
this.editorVersion = editorVersion;
this.targetPlatform = targetPlatform;
this.cloudRunnerBuilderPlatform = cloudRunnerBuilderPlatform;
@ -33,7 +38,7 @@ class ImageTag {
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefixes(
isCloudRunnerLocal ? process.platform : cloudRunnerBuilderPlatform,
);
this.imageRollingVersion = 3; // Will automatically roll to the latest non-breaking version.
this.imageRollingVersion = Number(containerRegistryImageVersion); // Will automatically roll to the latest non-breaking version.
}
static get versionPattern(): RegExp {
@ -156,7 +161,7 @@ class ImageTag {
}
get image(): string {
return `${this.repository}/${this.name}`.replace(/^\/+/, '');
return `${this.repository}`.replace(/^\/+/, '');
}
toString(): string {

View File

@ -256,6 +256,14 @@ class Input {
return Input.getInput('dockerIsolationMode') || 'default';
}
static get containerRegistryRepository(): string {
return Input.getInput('containerRegistryUrl')!;
}
static get containerRegistryImageVersion(): string {
return Input.getInput('containerRegistryImageVersion')!;
}
public static ToEnvVarFormat(input: string) {
if (input.toUpperCase() === input) {
return input;