Switch to version 1 images (#374)

* feat: upgrade to images of version 1 (rolling tag)

* chore: indicate what needs to move out of the input class
This commit is contained in:
Webber Takken
2022-04-03 17:59:14 +02:00
committed by GitHub
parent 1bc7130fea
commit 441be81543
17 changed files with 175 additions and 139 deletions

View File

@@ -1,35 +1,42 @@
import Platform from './platform';
import BuildParameters from './build-parameters';
class ImageTag {
public repository: string;
public name: string;
public version: string;
public platform: any;
public editorVersion: string;
public targetPlatform: any;
public builderPlatform: string;
public customImage: any;
public imageRollingVersion: number;
public imagePlatformPrefix: string;
constructor(imageProperties) {
const { repository = 'unityci', name = 'editor', version = '2019.2.11f1', platform, customImage } = imageProperties;
constructor(imageProperties: Partial<BuildParameters>) {
const { editorVersion = '2019.2.11f1', targetPlatform, customImage } = imageProperties;
if (!ImageTag.versionPattern.test(version)) {
throw new Error(`Invalid version "${version}".`);
if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`);
}
const builderPlatform = ImageTag.getTargetPlatformToImageSuffixMap(platform, version);
this.repository = repository;
this.name = name;
this.version = version;
this.platform = platform;
this.builderPlatform = builderPlatform;
// Todo we might as well skip this class for customImage.
// Either
this.customImage = customImage;
// Or
this.repository = 'unityci';
this.name = 'editor';
this.editorVersion = editorVersion;
this.targetPlatform = targetPlatform;
this.builderPlatform = ImageTag.getTargetPlatformToTargetPlatformSuffixMap(targetPlatform, editorVersion);
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefixes(process.platform);
this.imageRollingVersion = 1; // will automatically roll to the latest non-breaking version.
}
static get versionPattern() {
return /^20\d{2}\.\d\.\w{3,4}|3$/;
}
static get imageSuffixes() {
static get targetPlatformSuffixes() {
return {
generic: '',
webgl: 'webgl',
@@ -46,9 +53,20 @@ class ImageTag {
};
}
static getTargetPlatformToImageSuffixMap(platform, version) {
static getImagePlatformPrefixes(platform) {
switch (platform) {
case 'win32':
return 'windows';
case 'linux':
return 'ubuntu';
default:
throw new Error('The Operating System of this runner is not yet supported.');
}
}
static getTargetPlatformToTargetPlatformSuffixMap(platform, version) {
const { generic, webgl, mac, windows, windowsIl2cpp, wsaPlayer, linux, linuxIl2cpp, android, ios, tvos, facebook } =
ImageTag.imageSuffixes;
ImageTag.targetPlatformSuffixes;
const [major, minor] = version.split('.').map((digit) => Number(digit));
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
@@ -120,15 +138,9 @@ class ImageTag {
}
get tag() {
//We check the host os so we know what type of the images we need to pull
switch (process.platform) {
case 'win32':
return `windows-${this.version}-${this.builderPlatform}`.replace(/-+$/, '');
case 'linux':
return `${this.version}-${this.builderPlatform}`.replace(/-+$/, '');
default:
break;
}
const versionAndPlatform = `${this.editorVersion}-${this.builderPlatform}`.replace(/-+$/, '');
return `${this.imagePlatformPrefix}-${versionAndPlatform}-${this.imageRollingVersion}`;
}
get image() {
@@ -138,11 +150,9 @@ class ImageTag {
toString() {
const { image, tag, customImage } = this;
if (customImage && customImage !== '') {
return customImage;
}
if (customImage) return customImage;
return `${image}:${tag}-0`; // '0' here represents the docker repo version
return `${image}:${tag}`; // '0' here represents the docker repo version
}
}