unity-builder/src/model/docker.ts

41 lines
1.4 KiB
TypeScript
Raw Normal View History

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
class Docker {
2019-12-22 17:07:55 +00:00
static async build(buildParameters, silent = false) {
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}`;
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-12-29 20:14:15 +00:00
${ImageEnvironmentFactory.getEnvVarString(parameters)} \
2019-12-22 14:05:15 +00:00
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
--volume "${runnerTempPath}/_github_home":"/root" \
--volume "${runnerTempPath}/_github_workflow":"/github/workflow" \
2019-12-22 17:07:55 +00:00
--volume "${workspace}":"/github/workspace" \
${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}`;
await exec(command, undefined, { silent });
2019-12-22 14:05:15 +00:00
}
}
export default Docker;