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 '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 default mode as described by Microsoft where server versions use process and desktop versions use hyperv. Only
applicable on Windows' 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: allowDirtyBuild:
required: false required: false
default: '' default: ''

17
dist/index.js generated vendored
View File

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

View File

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

View File

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

View File

@ -256,6 +256,14 @@ class Input {
return Input.getInput('dockerIsolationMode') || 'default'; 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) { public static ToEnvVarFormat(input: string) {
if (input.toUpperCase() === input) { if (input.toUpperCase() === input) {
return input; return input;