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';
|
2021-08-15 17:58:39 +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) {
|
2021-08-15 17:58:39 +00:00
|
|
|
const { workspace, runnerTempPath, sshAgent } = parameters;
|
2019-12-22 17:07:55 +00:00
|
|
|
|
2019-12-22 21:24:46 +00:00
|
|
|
const command = `docker run \
|
2019-12-22 14:05:15 +00:00
|
|
|
--workdir /github/workspace \
|
|
|
|
|
--rm \
|
2021-08-15 17:58:39 +00:00
|
|
|
${ImageEnvironmentFactory.getEnvVarString(parameters)}
|
2019-12-22 14:05:15 +00:00
|
|
|
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
|
2021-02-03 16:39:52 +00:00
|
|
|
--volume "${runnerTempPath}/_github_home":"/root" \
|
2020-08-22 15:59:08 +00:00
|
|
|
--volume "${runnerTempPath}/_github_workflow":"/github/workflow" \
|
2019-12-22 17:07:55 +00:00
|
|
|
--volume "${workspace}":"/github/workspace" \
|
2021-05-28 21:51:10 +00:00
|
|
|
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
|
|
|
|
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
|
2019-12-22 21:24:46 +00:00
|
|
|
${image}`;
|
|
|
|
|
|
2020-05-01 14:52:08 +00:00
|
|
|
await exec(command, undefined, { silent });
|
2019-12-22 14:05:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-01-20 23:06:14 +00:00
|
|
|
|
|
|
|
|
export default Docker;
|