perf: avoid creating temporary docker image (#177)
* avoid building custom image * Rebuild * fix wrong folder for entrypoint.sh * run with bash * fix path to bash * Mount with permissions * Rebuild * add missing continuation * rebuild * Fix docker invocation * delete unused code * Fix test * remove old comment * Fix code styles Co-authored-by: Webber Takken <webber.nl@gmail.com>pull/179/head
parent
f87ed30c30
commit
50a3bd4138
|
@ -1,17 +0,0 @@
|
||||||
ARG IMAGE
|
|
||||||
FROM $IMAGE
|
|
||||||
|
|
||||||
LABEL "com.github.actions.name"="Unity - Test runner"
|
|
||||||
LABEL "com.github.actions.description"="Run tests for any Unity project."
|
|
||||||
LABEL "com.github.actions.icon"="box"
|
|
||||||
LABEL "com.github.actions.color"="gray-dark"
|
|
||||||
|
|
||||||
LABEL "repository"="http://github.com/webbertakken/unity-actions"
|
|
||||||
LABEL "homepage"="http://github.com/webbertakken/unity-actions"
|
|
||||||
LABEL "maintainer"="Webber Takken <webber@takken.io>"
|
|
||||||
|
|
||||||
ADD steps /steps
|
|
||||||
RUN chmod -R +x /steps
|
|
||||||
ADD entrypoint.sh /entrypoint.sh
|
|
||||||
RUN chmod +x /entrypoint.sh
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
@ -41,15 +41,15 @@ function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
model_1.Action.checkCompatibility();
|
model_1.Action.checkCompatibility();
|
||||||
const { dockerfile, workspace, actionFolder } = model_1.Action;
|
const { workspace, actionFolder } = model_1.Action;
|
||||||
const { unityVersion, customImage, projectPath, customParameters, testMode, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, } = model_1.Input.getFromUser();
|
const { unityVersion, customImage, projectPath, customParameters, testMode, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, } = model_1.Input.getFromUser();
|
||||||
const baseImage = new model_1.ImageTag({ version: unityVersion, customImage });
|
const baseImage = new model_1.ImageTag({ version: unityVersion, customImage });
|
||||||
const runnerTempPath = process.env.RUNNER_TEMP;
|
const runnerTempPath = process.env.RUNNER_TEMP;
|
||||||
try {
|
try {
|
||||||
// Build docker image
|
// Build docker image
|
||||||
const actionImage = yield model_1.Docker.build({ path: actionFolder, dockerfile, baseImage });
|
|
||||||
// Run docker image
|
// Run docker image
|
||||||
yield model_1.Docker.run(actionImage, {
|
yield model_1.Docker.run(baseImage, {
|
||||||
|
actionFolder,
|
||||||
unityVersion,
|
unityVersion,
|
||||||
workspace,
|
workspace,
|
||||||
projectPath,
|
projectPath,
|
||||||
|
@ -116,9 +116,6 @@ const Action = {
|
||||||
get actionFolder() {
|
get actionFolder() {
|
||||||
return `${Action.rootFolder}/dist`;
|
return `${Action.rootFolder}/dist`;
|
||||||
},
|
},
|
||||||
get dockerfile() {
|
|
||||||
return `${Action.actionFolder}/Dockerfile`;
|
|
||||||
},
|
|
||||||
get workspace() {
|
get workspace() {
|
||||||
return process.env.GITHUB_WORKSPACE;
|
return process.env.GITHUB_WORKSPACE;
|
||||||
},
|
},
|
||||||
|
@ -153,26 +150,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const fs_1 = __nccwpck_require__(7147);
|
const fs_1 = __nccwpck_require__(7147);
|
||||||
const image_tag_1 = __importDefault(__nccwpck_require__(7648));
|
|
||||||
const exec_1 = __nccwpck_require__(1514);
|
const exec_1 = __nccwpck_require__(1514);
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
const Docker = {
|
const Docker = {
|
||||||
build(buildParameters, silent = false) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const { path: buildPath, dockerfile, baseImage } = buildParameters;
|
|
||||||
const { version } = baseImage;
|
|
||||||
const tag = new image_tag_1.default({ version });
|
|
||||||
const command = `docker build ${buildPath} \
|
|
||||||
--file ${dockerfile} \
|
|
||||||
--build-arg IMAGE=${baseImage} \
|
|
||||||
--tag ${tag}`;
|
|
||||||
yield (0, exec_1.exec)(command, undefined, { silent });
|
|
||||||
return tag;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
run(image, parameters, silent = false) {
|
run(image, parameters, silent = false) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const { unityVersion, workspace, projectPath, customParameters, testMode, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTempPath, } = parameters;
|
const { actionFolder, unityVersion, workspace, projectPath, customParameters, testMode, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTempPath, } = parameters;
|
||||||
const githubHome = path_1.default.join(runnerTempPath, '_github_home');
|
const githubHome = path_1.default.join(runnerTempPath, '_github_home');
|
||||||
if (!(0, fs_1.existsSync)(githubHome))
|
if (!(0, fs_1.existsSync)(githubHome))
|
||||||
(0, fs_1.mkdirSync)(githubHome);
|
(0, fs_1.mkdirSync)(githubHome);
|
||||||
|
@ -212,11 +195,14 @@ const Docker = {
|
||||||
--volume "${githubHome}":"/root:z" \
|
--volume "${githubHome}":"/root:z" \
|
||||||
--volume "${githubWorkflow}":"/github/workflow:z" \
|
--volume "${githubWorkflow}":"/github/workflow:z" \
|
||||||
--volume "${workspace}":"/github/workspace:z" \
|
--volume "${workspace}":"/github/workspace:z" \
|
||||||
|
--volume "${actionFolder}/steps":"/steps:z" \
|
||||||
|
--volume "${actionFolder}/entrypoint.sh":"/entrypoint.sh:z" \
|
||||||
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
||||||
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
|
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
|
||||||
${useHostNetwork ? '--net=host' : ''} \
|
${useHostNetwork ? '--net=host' : ''} \
|
||||||
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
|
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
|
||||||
${image}`;
|
${image} \
|
||||||
|
/bin/bash /entrypoint.sh`;
|
||||||
yield (0, exec_1.exec)(command, undefined, { silent });
|
yield (0, exec_1.exec)(command, undefined, { silent });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5,7 +5,7 @@ async function run() {
|
||||||
try {
|
try {
|
||||||
Action.checkCompatibility();
|
Action.checkCompatibility();
|
||||||
|
|
||||||
const { dockerfile, workspace, actionFolder } = Action;
|
const { workspace, actionFolder } = Action;
|
||||||
const {
|
const {
|
||||||
unityVersion,
|
unityVersion,
|
||||||
customImage,
|
customImage,
|
||||||
|
@ -23,11 +23,8 @@ async function run() {
|
||||||
const runnerTempPath = process.env.RUNNER_TEMP;
|
const runnerTempPath = process.env.RUNNER_TEMP;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Build docker image
|
await Docker.run(baseImage, {
|
||||||
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
|
actionFolder,
|
||||||
|
|
||||||
// Run docker image
|
|
||||||
await Docker.run(actionImage, {
|
|
||||||
unityVersion,
|
unityVersion,
|
||||||
workspace,
|
workspace,
|
||||||
projectPath,
|
projectPath,
|
||||||
|
|
|
@ -26,11 +26,4 @@ describe('Action', () => {
|
||||||
expect(path.basename(actionFolder)).toStrictEqual('dist');
|
expect(path.basename(actionFolder)).toStrictEqual('dist');
|
||||||
expect(fs.existsSync(actionFolder)).toStrictEqual(true);
|
expect(fs.existsSync(actionFolder)).toStrictEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the docker file', () => {
|
|
||||||
const { dockerfile } = Action;
|
|
||||||
|
|
||||||
expect(path.basename(dockerfile)).toStrictEqual('Dockerfile');
|
|
||||||
expect(fs.existsSync(dockerfile)).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,10 +29,6 @@ const Action = {
|
||||||
return `${Action.rootFolder}/dist`;
|
return `${Action.rootFolder}/dist`;
|
||||||
},
|
},
|
||||||
|
|
||||||
get dockerfile() {
|
|
||||||
return `${Action.actionFolder}/Dockerfile`;
|
|
||||||
},
|
|
||||||
|
|
||||||
get workspace() {
|
get workspace() {
|
||||||
return process.env.GITHUB_WORKSPACE;
|
return process.env.GITHUB_WORKSPACE;
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,21 +1,7 @@
|
||||||
import Action from './action';
|
import Action from './action';
|
||||||
import Docker from './docker';
|
import Docker from './docker';
|
||||||
import ImageTag from './image-tag';
|
|
||||||
|
|
||||||
describe('Docker', () => {
|
describe('Docker', () => {
|
||||||
it.skip('builds', async () => {
|
|
||||||
const path = Action.actionFolder;
|
|
||||||
const dockerfile = `${path}/Dockerfile`;
|
|
||||||
const baseImage = new ImageTag({
|
|
||||||
repository: '',
|
|
||||||
name: 'alpine',
|
|
||||||
version: '3',
|
|
||||||
platform: 'Test',
|
|
||||||
});
|
|
||||||
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
|
|
||||||
expect(tag).toBeInstanceOf(ImageTag);
|
|
||||||
expect(tag.toString()).toStrictEqual('unity-builder:3');
|
|
||||||
}, 240_000);
|
|
||||||
it.skip('runs', async () => {
|
it.skip('runs', async () => {
|
||||||
const image = 'unity-builder:2019.2.11f1-webgl';
|
const image = 'unity-builder:2019.2.11f1-webgl';
|
||||||
const parameters = {
|
const parameters = {
|
||||||
|
|
|
@ -1,26 +1,11 @@
|
||||||
import { existsSync, mkdirSync } from 'fs';
|
import { existsSync, mkdirSync } from 'fs';
|
||||||
import ImageTag from './image-tag';
|
|
||||||
import { exec } from '@actions/exec';
|
import { exec } from '@actions/exec';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
const Docker = {
|
const Docker = {
|
||||||
async build(buildParameters, silent = false) {
|
|
||||||
const { path: buildPath, dockerfile, baseImage } = buildParameters;
|
|
||||||
const { version } = baseImage;
|
|
||||||
|
|
||||||
const tag = new ImageTag({ version });
|
|
||||||
const command = `docker build ${buildPath} \
|
|
||||||
--file ${dockerfile} \
|
|
||||||
--build-arg IMAGE=${baseImage} \
|
|
||||||
--tag ${tag}`;
|
|
||||||
|
|
||||||
await exec(command, undefined, { silent });
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
},
|
|
||||||
|
|
||||||
async run(image, parameters, silent = false) {
|
async run(image, parameters, silent = false) {
|
||||||
const {
|
const {
|
||||||
|
actionFolder,
|
||||||
unityVersion,
|
unityVersion,
|
||||||
workspace,
|
workspace,
|
||||||
projectPath,
|
projectPath,
|
||||||
|
@ -72,11 +57,14 @@ const Docker = {
|
||||||
--volume "${githubHome}":"/root:z" \
|
--volume "${githubHome}":"/root:z" \
|
||||||
--volume "${githubWorkflow}":"/github/workflow:z" \
|
--volume "${githubWorkflow}":"/github/workflow:z" \
|
||||||
--volume "${workspace}":"/github/workspace:z" \
|
--volume "${workspace}":"/github/workspace:z" \
|
||||||
|
--volume "${actionFolder}/steps":"/steps:z" \
|
||||||
|
--volume "${actionFolder}/entrypoint.sh":"/entrypoint.sh:z" \
|
||||||
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
||||||
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
|
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
|
||||||
${useHostNetwork ? '--net=host' : ''} \
|
${useHostNetwork ? '--net=host' : ''} \
|
||||||
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
|
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
|
||||||
${image}`;
|
${image} \
|
||||||
|
/bin/bash /entrypoint.sh`;
|
||||||
|
|
||||||
await exec(command, undefined, { silent });
|
await exec(command, undefined, { silent });
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue