mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
perf: avoid building docker image (#365)
* avoid building a custom image * fix: remove unnecessary double-dash * Rebuild with -- fix * linting * Remove unused variable * support windows as well * Fix -- command not found * Fix unused import, remove docker build test * no dockerfile anymore Co-authored-by: Webber Takken <webber.nl@gmail.com>
This commit is contained in:
parent
9a40b8903e
commit
b72639aac0
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
20
dist/platforms/ubuntu/Dockerfile
vendored
20
dist/platforms/ubuntu/Dockerfile
vendored
@ -1,20 +0,0 @@
|
||||
ARG IMAGE
|
||||
FROM $IMAGE
|
||||
|
||||
LABEL "com.github.actions.name"="Unity - Builder"
|
||||
LABEL "com.github.actions.description"="Build Unity projects for different platforms."
|
||||
LABEL "com.github.actions.icon"="box"
|
||||
LABEL "com.github.actions.color"="gray-dark"
|
||||
|
||||
LABEL "repository"="http://github.com/game-ci/unity-actions"
|
||||
LABEL "homepage"="http://github.com/game-ci/unity-actions"
|
||||
LABEL "maintainer"="Webber Takken <webber@takken.io>"
|
||||
|
||||
COPY default-build-script /UnityBuilderAction
|
||||
COPY platforms/ubuntu/steps /steps
|
||||
RUN chmod -R +x /steps
|
||||
COPY platforms/ubuntu/entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
RUN ls
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
19
dist/platforms/windows/Dockerfile
vendored
19
dist/platforms/windows/Dockerfile
vendored
@ -1,19 +0,0 @@
|
||||
ARG IMAGE
|
||||
FROM $IMAGE
|
||||
|
||||
LABEL "com.github.actions.name"="Unity - Builder"
|
||||
LABEL "com.github.actions.description"="Build Unity projects for different platforms."
|
||||
LABEL "com.github.actions.icon"="box"
|
||||
LABEL "com.github.actions.color"="gray-dark"
|
||||
|
||||
LABEL "repository"="http://github.com/game-ci/unity-actions"
|
||||
LABEL "homepage"="http://github.com/game-ci/unity-actions"
|
||||
LABEL "maintainer"="Webber Takken <webber@takken.io>"
|
||||
|
||||
COPY default-build-script c:/UnityBuilderAction
|
||||
COPY platforms/windows/steps c:/steps
|
||||
COPY platforms/windows/entrypoint.ps1 c:/entrypoint.ps1
|
||||
COPY BlankProject c:/BlankProject
|
||||
RUN dir
|
||||
|
||||
ENTRYPOINT ["powershell", "c:/entrypoint.ps1"]
|
@ -8,13 +8,11 @@ async function runMain() {
|
||||
Action.checkCompatibility();
|
||||
Cache.verify();
|
||||
|
||||
const { dockerfile, workspace, actionFolder } = Action;
|
||||
const { workspace, actionFolder } = Action;
|
||||
|
||||
const buildParameters = await BuildParameters.create();
|
||||
const baseImage = new ImageTag(buildParameters);
|
||||
|
||||
let builtImage;
|
||||
|
||||
if (
|
||||
buildParameters.cloudRunnerCluster &&
|
||||
buildParameters.cloudRunnerCluster !== '' &&
|
||||
@ -27,8 +25,7 @@ async function runMain() {
|
||||
if (process.platform === 'darwin') {
|
||||
MacBuilder.run(actionFolder, workspace, buildParameters);
|
||||
} else {
|
||||
builtImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
|
||||
await Docker.run(builtImage, { workspace, ...buildParameters });
|
||||
await Docker.run(baseImage, { workspace, actionFolder, ...buildParameters });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,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);
|
||||
});
|
||||
});
|
||||
|
@ -29,20 +29,6 @@ class Action {
|
||||
return `${Action.rootFolder}/dist`;
|
||||
}
|
||||
|
||||
static get dockerfile() {
|
||||
const currentPlatform = process.platform;
|
||||
switch (currentPlatform) {
|
||||
case 'linux':
|
||||
return `${Action.actionFolder}/platforms/ubuntu/Dockerfile`;
|
||||
case 'win32':
|
||||
return `${Action.actionFolder}/platforms/windows/Dockerfile`;
|
||||
case 'darwin':
|
||||
return 'unused'; //Mac doesn't use a container
|
||||
default:
|
||||
throw new Error(`No Dockerfile for currently unsupported platform: ${currentPlatform}`);
|
||||
}
|
||||
}
|
||||
|
||||
static get workspace() {
|
||||
return process.env.GITHUB_WORKSPACE;
|
||||
}
|
||||
|
@ -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');
|
||||
}, 240000);
|
||||
it.skip('runs', async () => {
|
||||
const image = 'unity-builder:2019.2.11f1-webgl';
|
||||
const parameters = {
|
||||
|
@ -1,74 +1,67 @@
|
||||
import { exec } from '@actions/exec';
|
||||
import ImageTag from './image-tag';
|
||||
import ImageEnvironmentFactory from './image-environment-factory';
|
||||
import { existsSync, mkdirSync } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
class Docker {
|
||||
static async build(buildParameters, silent = false) {
|
||||
const { path: buildPath, dockerfile, baseImage } = buildParameters;
|
||||
const { version, platform } = baseImage;
|
||||
|
||||
const tag = new ImageTag({ repository: '', name: 'unity-builder', version, platform });
|
||||
const command = `docker build ${buildPath} \
|
||||
--file ${dockerfile} \
|
||||
--build-arg IMAGE=${baseImage} \
|
||||
--tag ${tag}`;
|
||||
|
||||
await exec(command, undefined, { silent });
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
static async run(image, parameters, silent = false) {
|
||||
const { workspace, unitySerial, runnerTempPath, sshAgent } = parameters;
|
||||
|
||||
const baseOsSpecificArguments = this.getBaseOsSpecificArguments(
|
||||
process.platform,
|
||||
workspace,
|
||||
unitySerial,
|
||||
runnerTempPath,
|
||||
sshAgent,
|
||||
);
|
||||
|
||||
const runCommand = `docker run \
|
||||
--workdir /github/workspace \
|
||||
--rm \
|
||||
${ImageEnvironmentFactory.getEnvVarString(parameters)} \
|
||||
${baseOsSpecificArguments} \
|
||||
${image}`;
|
||||
|
||||
let runCommand = '';
|
||||
switch (process.platform) {
|
||||
case 'linux':
|
||||
runCommand = this.getLinuxCommand(image, parameters);
|
||||
break;
|
||||
case 'win32':
|
||||
runCommand = this.getWindowsCommand(image, parameters);
|
||||
}
|
||||
await exec(runCommand, undefined, { silent });
|
||||
}
|
||||
|
||||
static getBaseOsSpecificArguments(baseOs, workspace, unitySerial, runnerTemporaryPath, sshAgent): string {
|
||||
switch (baseOs) {
|
||||
case 'linux': {
|
||||
const githubHome = path.join(runnerTemporaryPath, '_github_home');
|
||||
if (!existsSync(githubHome)) mkdirSync(githubHome);
|
||||
const githubWorkflow = path.join(runnerTemporaryPath, '_github_workflow');
|
||||
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
|
||||
static getLinuxCommand(image, parameters): string {
|
||||
const { workspace, actionFolder, runnerTempPath, sshAgent } = parameters;
|
||||
|
||||
return `--env UNITY_SERIAL \
|
||||
--env GITHUB_WORKSPACE=/github/workspace \
|
||||
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
|
||||
--volume "${githubHome}":"/root:z" \
|
||||
--volume "${githubWorkflow}":"/github/workflow:z" \
|
||||
--volume "${workspace}":"/github/workspace:z" \
|
||||
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
||||
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''}`;
|
||||
}
|
||||
case 'win32':
|
||||
return `--env UNITY_SERIAL="${unitySerial}" \
|
||||
--env GITHUB_WORKSPACE=c:/github/workspace \
|
||||
--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 '';
|
||||
const githubHome = path.join(runnerTempPath, '_github_home');
|
||||
if (!existsSync(githubHome)) mkdirSync(githubHome);
|
||||
const githubWorkflow = path.join(runnerTempPath, '_github_workflow');
|
||||
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
|
||||
|
||||
return `docker run \
|
||||
--workdir /github/workspace \
|
||||
--rm \
|
||||
${ImageEnvironmentFactory.getEnvVarString(parameters)} \
|
||||
--env UNITY_SERIAL \
|
||||
--env GITHUB_WORKSPACE=/github/workspace \
|
||||
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
|
||||
--volume "${githubHome}":"/root:z" \
|
||||
--volume "${githubWorkflow}":"/github/workflow:z" \
|
||||
--volume "${workspace}":"/github/workspace:z" \
|
||||
--volume "${actionFolder}/default-build-script:/UnityBuilderAction:z" \
|
||||
--volume "${actionFolder}/platforms/ubuntu/steps:/steps:z" \
|
||||
--volume "${actionFolder}/platforms/ubuntu/entrypoint.sh:/entrypoint.sh:z" \
|
||||
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
||||
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
|
||||
${image} \
|
||||
/bin/bash -c /entrypoint.sh`;
|
||||
}
|
||||
|
||||
static getWindowsCommand(image: any, parameters: any): string {
|
||||
const { workspace, actionFolder, unitySerial } = parameters;
|
||||
return `docker run \
|
||||
--workdir /github/workspace \
|
||||
--rm \
|
||||
${ImageEnvironmentFactory.getEnvVarString(parameters)} \
|
||||
--env UNITY_SERIAL="${unitySerial}" \
|
||||
--env GITHUB_WORKSPACE=c:/github/workspace \
|
||||
--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" \
|
||||
--volume "${actionFolder}/default-build-script":"c:/UnityBuilderAction" \
|
||||
--volume "${actionFolder}/platforms/ubuntu/steps":"c:/steps" \
|
||||
--volume "${actionFolder}/platforms/windows/entrypoint.ps1":"c:/entrypoint.ps1" \
|
||||
--volume "${actionFolder}/BlankProject":"c:/BlankProject" \
|
||||
${image} \
|
||||
powershell c:/entrypoint.ps1`;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user