2019-12-22 14:05:15 +00:00
|
|
|
import { exec } from '@actions/exec';
|
2019-12-22 17:07:55 +00:00
|
|
|
import ImageTag from './image-tag';
|
2022-02-01 02:31:20 +00:00
|
|
|
import ImageEnvironmentFactory from './image-environment-factory';
|
2019-12-22 14:05:15 +00:00
|
|
|
|
2020-01-20 23:06:14 +00:00
|
|
|
class Docker {
|
2019-12-22 17:07:55 +00:00
|
|
|
static async build(buildParameters, silent = false) {
|
2020-10-22 08:20:12 +00:00
|
|
|
const { path, dockerfile, baseImage } = buildParameters;
|
2019-12-22 17:07:55 +00:00
|
|
|
const { version, platform } = baseImage;
|
2019-12-22 14:05:15 +00:00
|
|
|
|
2019-12-22 17:07:55 +00:00
|
|
|
const tag = new ImageTag({ repository: '', name: 'unity-builder', version, platform });
|
|
|
|
const command = `docker build ${path} \
|
|
|
|
--file ${dockerfile} \
|
|
|
|
--build-arg IMAGE=${baseImage} \
|
|
|
|
--tag ${tag}`;
|
|
|
|
|
2020-05-01 14:52:08 +00:00
|
|
|
await exec(command, undefined, { silent });
|
2019-12-22 14:05:15 +00:00
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2019-12-22 21:24:46 +00:00
|
|
|
static async run(image, parameters, silent = false) {
|
2022-02-01 02:31:20 +00:00
|
|
|
const { workspace, unitySerial, runnerTempPath, sshAgent } = parameters;
|
2019-12-22 17:07:55 +00:00
|
|
|
|
2022-01-25 21:18:15 +00:00
|
|
|
const baseOsSpecificArguments = this.getBaseOsSpecificArguments(
|
|
|
|
process.platform,
|
|
|
|
workspace,
|
|
|
|
unitySerial,
|
|
|
|
runnerTempPath,
|
|
|
|
sshAgent,
|
|
|
|
);
|
2019-12-22 21:24:46 +00:00
|
|
|
|
2022-01-25 21:18:15 +00:00
|
|
|
const runCommand = `docker run \
|
|
|
|
--workdir /github/workspace \
|
|
|
|
--rm \
|
2022-02-01 02:31:20 +00:00
|
|
|
${ImageEnvironmentFactory.getEnvVarString(parameters)} \
|
2022-01-25 21:18:15 +00:00
|
|
|
${baseOsSpecificArguments} \
|
|
|
|
${image}`;
|
|
|
|
|
|
|
|
await exec(runCommand, undefined, { silent });
|
|
|
|
}
|
|
|
|
|
|
|
|
static getBaseOsSpecificArguments(baseOs, workspace, unitySerial, runnerTemporaryPath, sshAgent): string {
|
|
|
|
switch (baseOs) {
|
|
|
|
case 'linux':
|
|
|
|
return `--env UNITY_SERIAL \
|
2022-02-02 09:15:37 +00:00
|
|
|
--env GITHUB_WORKSPACE=/github/workspace \
|
2022-01-25 21:18:15 +00:00
|
|
|
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
|
|
|
|
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
|
|
|
|
--volume "${runnerTemporaryPath}/_github_home":"/root" \
|
|
|
|
--volume "${runnerTemporaryPath}/_github_workflow":"/github/workflow" \
|
|
|
|
--volume "${workspace}":"/github/workspace" \
|
|
|
|
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
|
|
|
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''}`;
|
|
|
|
case 'win32':
|
|
|
|
return `--env UNITY_SERIAL="${unitySerial}" \
|
2022-02-02 09:15:37 +00:00
|
|
|
--env GITHUB_WORKSPACE=c:/github/workspace \
|
2022-01-25 21:18:15 +00:00
|
|
|
--volume "${workspace}":"c:/github/workspace" \
|
|
|
|
--volume "c:/regkeys":"c:/regkeys" \
|
|
|
|
--volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \
|
|
|
|
--volume "C:/Program Files (x86)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \
|
|
|
|
--volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio"`;
|
|
|
|
//Note: When upgrading to Server 2022, we will need to move to just "program files" since VS will be 64-bit
|
|
|
|
}
|
|
|
|
return '';
|
2019-12-22 14:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-20 23:06:14 +00:00
|
|
|
|
|
|
|
export default Docker;
|