diff --git a/dist/index.js b/dist/index.js index 24fbfd20..465e9add 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.js.map b/dist/index.js.map index 249c5e3f..93feb4f3 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/dist/platforms/ubuntu/Dockerfile b/dist/platforms/ubuntu/Dockerfile deleted file mode 100644 index 2cb677c3..00000000 --- a/dist/platforms/ubuntu/Dockerfile +++ /dev/null @@ -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 " - -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"] diff --git a/dist/platforms/windows/Dockerfile b/dist/platforms/windows/Dockerfile deleted file mode 100644 index 2e3c1d6d..00000000 --- a/dist/platforms/windows/Dockerfile +++ /dev/null @@ -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 " - -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"] diff --git a/src/index.ts b/src/index.ts index ed79bcb1..8459f9fd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 }); } } diff --git a/src/model/action.test.ts b/src/model/action.test.ts index f537f298..76fef312 100644 --- a/src/model/action.test.ts +++ b/src/model/action.test.ts @@ -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); - }); }); diff --git a/src/model/action.ts b/src/model/action.ts index 06ee1ccd..28d07963 100644 --- a/src/model/action.ts +++ b/src/model/action.ts @@ -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; } diff --git a/src/model/docker.test.ts b/src/model/docker.test.ts index 0c81f643..290d19bf 100644 --- a/src/model/docker.test.ts +++ b/src/model/docker.test.ts @@ -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 = { diff --git a/src/model/docker.ts b/src/model/docker.ts index 39799561..1ded47cc 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -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`; } }