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
Paul Pacheco 2022-04-03 05:14:39 -05:00 committed by GitHub
parent f87ed30c30
commit 50a3bd4138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 88 deletions

17
dist/Dockerfile vendored
View File

@ -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"]

30
dist/index.js generated vendored
View File

@ -41,15 +41,15 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
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 baseImage = new model_1.ImageTag({ version: unityVersion, customImage });
const runnerTempPath = process.env.RUNNER_TEMP;
try {
// Build docker image
const actionImage = yield model_1.Docker.build({ path: actionFolder, dockerfile, baseImage });
// Run docker image
yield model_1.Docker.run(actionImage, {
yield model_1.Docker.run(baseImage, {
actionFolder,
unityVersion,
workspace,
projectPath,
@ -116,9 +116,6 @@ const Action = {
get actionFolder() {
return `${Action.rootFolder}/dist`;
},
get dockerfile() {
return `${Action.actionFolder}/Dockerfile`;
},
get workspace() {
return process.env.GITHUB_WORKSPACE;
},
@ -153,26 +150,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const fs_1 = __nccwpck_require__(7147);
const image_tag_1 = __importDefault(__nccwpck_require__(7648));
const exec_1 = __nccwpck_require__(1514);
const path_1 = __importDefault(__nccwpck_require__(1017));
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) {
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');
if (!(0, fs_1.existsSync)(githubHome))
(0, fs_1.mkdirSync)(githubHome);
@ -212,11 +195,14 @@ const Docker = {
--volume "${githubHome}":"/root:z" \
--volume "${githubWorkflow}":"/github/workflow: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 /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
${useHostNetwork ? '--net=host' : ''} \
${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 });
});
},

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@ async function run() {
try {
Action.checkCompatibility();
const { dockerfile, workspace, actionFolder } = Action;
const { workspace, actionFolder } = Action;
const {
unityVersion,
customImage,
@ -23,11 +23,8 @@ async function run() {
const runnerTempPath = process.env.RUNNER_TEMP;
try {
// Build docker image
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
// Run docker image
await Docker.run(actionImage, {
await Docker.run(baseImage, {
actionFolder,
unityVersion,
workspace,
projectPath,

View File

@ -26,11 +26,4 @@ describe('Action', () => {
expect(path.basename(actionFolder)).toStrictEqual('dist');
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);
});
});

View File

@ -29,10 +29,6 @@ const Action = {
return `${Action.rootFolder}/dist`;
},
get dockerfile() {
return `${Action.actionFolder}/Dockerfile`;
},
get workspace() {
return process.env.GITHUB_WORKSPACE;
},

View File

@ -1,21 +1,7 @@
import Action from './action';
import Docker from './docker';
import ImageTag from './image-tag';
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 () => {
const image = 'unity-builder:2019.2.11f1-webgl';
const parameters = {

View File

@ -1,26 +1,11 @@
import { existsSync, mkdirSync } from 'fs';
import ImageTag from './image-tag';
import { exec } from '@actions/exec';
import path from 'path';
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) {
const {
actionFolder,
unityVersion,
workspace,
projectPath,
@ -72,11 +57,14 @@ const Docker = {
--volume "${githubHome}":"/root:z" \
--volume "${githubWorkflow}":"/github/workflow: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 /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image}`;
${image} \
/bin/bash /entrypoint.sh`;
await exec(command, undefined, { silent });
},