From 80baa8d05418bcc18781f590a1a0bbbfde66276d Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Fri, 11 Mar 2022 07:01:11 -0600 Subject: [PATCH 1/6] feat: compatibility with self-hosted runners with SELinux When using a self-hosted runner with SELinux (fedora) volumes need to be mounted with ":z" in order to have write access these flags are documented [here](https://docs.docker.com/storage/bind-mounts/#configure-the-selinux-label) --- src/model/docker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/model/docker.ts b/src/model/docker.ts index 5d22f8a00..286fd2651 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -45,10 +45,10 @@ class Docker { return `--env UNITY_SERIAL \ --env GITHUB_WORKSPACE=/github/workspace \ ${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \ - --volume "/var/run/docker.sock":"/var/run/docker.sock" \ - --volume "${runnerTemporaryPath}/_github_home":"/root" \ - --volume "${runnerTemporaryPath}/_github_workflow":"/github/workflow" \ - --volume "${workspace}":"/github/workspace" \ + --volume "/var/run/docker.sock":"/var/run/docker.sock:z" \ + --volume "${runnerTemporaryPath}/_github_home":"/root:z" \ + --volume "${runnerTemporaryPath}/_github_workflow":"/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': From 777186b015249c0530a22d831b3454302172d9c3 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Fri, 11 Mar 2022 07:47:31 -0600 Subject: [PATCH 2/6] Ensure folders are created --- src/model/docker.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/model/docker.ts b/src/model/docker.ts index 286fd2651..7f9e69db6 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -1,6 +1,8 @@ import { exec } from '@actions/exec'; import ImageTag from './image-tag'; import ImageEnvironmentFactory from './image-environment-factory'; +import { existsSync, mkdirSync } from 'fs'; +import { join } from 'path'; class Docker { static async build(buildParameters, silent = false) { @@ -42,12 +44,17 @@ class Docker { static getBaseOsSpecificArguments(baseOs, workspace, unitySerial, runnerTemporaryPath, sshAgent): string { switch (baseOs) { case 'linux': + const github_home = join(runnerTemporaryPath, "_github_home"); + existsSync(github_home) || mkdirSync(github_home); + const github_workflow = join(runnerTemporaryPath, "_github_workflow"); + existsSync(github_workflow) || mkdirSync(github_workflow); + return `--env UNITY_SERIAL \ --env GITHUB_WORKSPACE=/github/workspace \ ${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \ --volume "/var/run/docker.sock":"/var/run/docker.sock:z" \ - --volume "${runnerTemporaryPath}/_github_home":"/root:z" \ - --volume "${runnerTemporaryPath}/_github_workflow":"/github/workflow:z" \ + --volume "${github_home}":"/root:z" \ + --volume "${github_workflow}":"/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' : ''}`; From dc7a0d34b339123f94c067d650c699d306ed51c4 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Fri, 11 Mar 2022 08:01:24 -0600 Subject: [PATCH 3/6] use if instead of short circuit --- src/model/docker.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/model/docker.ts b/src/model/docker.ts index 7f9e69db6..07b4d1523 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -45,9 +45,11 @@ class Docker { switch (baseOs) { case 'linux': const github_home = join(runnerTemporaryPath, "_github_home"); - existsSync(github_home) || mkdirSync(github_home); + if (!existsSync(github_home)) + mkdirSync(github_home); const github_workflow = join(runnerTemporaryPath, "_github_workflow"); - existsSync(github_workflow) || mkdirSync(github_workflow); + if (!existsSync(github_workflow)) + mkdirSync(github_workflow); return `--env UNITY_SERIAL \ --env GITHUB_WORKSPACE=/github/workspace \ From a5240d3e47c0c4179d0509e43db6cfb7f3bd1465 Mon Sep 17 00:00:00 2001 From: Webber Takken Date: Fri, 11 Mar 2022 16:08:38 +0100 Subject: [PATCH 4/6] ts convention either inline or use braces --- src/model/docker.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/model/docker.ts b/src/model/docker.ts index 07b4d1523..bd2875cf8 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -45,11 +45,9 @@ class Docker { switch (baseOs) { case 'linux': const github_home = join(runnerTemporaryPath, "_github_home"); - if (!existsSync(github_home)) - mkdirSync(github_home); + if (!existsSync(github_home)) mkdirSync(github_home); const github_workflow = join(runnerTemporaryPath, "_github_workflow"); - if (!existsSync(github_workflow)) - mkdirSync(github_workflow); + if (!existsSync(github_workflow)) mkdirSync(github_workflow); return `--env UNITY_SERIAL \ --env GITHUB_WORKSPACE=/github/workspace \ From 02bb450d73828ddbfff84c80e99cc12f6b333ad0 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Fri, 11 Mar 2022 09:53:45 -0600 Subject: [PATCH 5/6] Fix linting --- src/model/docker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/model/docker.ts b/src/model/docker.ts index bd2875cf8..fe1ad1411 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -44,9 +44,9 @@ class Docker { static getBaseOsSpecificArguments(baseOs, workspace, unitySerial, runnerTemporaryPath, sshAgent): string { switch (baseOs) { case 'linux': - const github_home = join(runnerTemporaryPath, "_github_home"); + const github_home = join(runnerTemporaryPath, '_github_home'); if (!existsSync(github_home)) mkdirSync(github_home); - const github_workflow = join(runnerTemporaryPath, "_github_workflow"); + const github_workflow = join(runnerTemporaryPath, '_github_workflow'); if (!existsSync(github_workflow)) mkdirSync(github_workflow); return `--env UNITY_SERIAL \ From baa853a94d3326d8166d95c68a11a250bba978a1 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Fri, 11 Mar 2022 10:21:13 -0600 Subject: [PATCH 6/6] fix linting errors --- src/model/docker.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/model/docker.ts b/src/model/docker.ts index fe1ad1411..4b77a9a62 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -2,15 +2,15 @@ import { exec } from '@actions/exec'; import ImageTag from './image-tag'; import ImageEnvironmentFactory from './image-environment-factory'; import { existsSync, mkdirSync } from 'fs'; -import { join } from 'path'; +import path from 'path'; class Docker { static async build(buildParameters, silent = false) { - const { path, dockerfile, baseImage } = buildParameters; + const { path: buildPath, dockerfile, baseImage } = buildParameters; const { version, platform } = baseImage; const tag = new ImageTag({ repository: '', name: 'unity-builder', version, platform }); - const command = `docker build ${path} \ + const command = `docker build ${buildPath} \ --file ${dockerfile} \ --build-arg IMAGE=${baseImage} \ --tag ${tag}`; @@ -43,21 +43,22 @@ class Docker { static getBaseOsSpecificArguments(baseOs, workspace, unitySerial, runnerTemporaryPath, sshAgent): string { switch (baseOs) { - case 'linux': - const github_home = join(runnerTemporaryPath, '_github_home'); - if (!existsSync(github_home)) mkdirSync(github_home); - const github_workflow = join(runnerTemporaryPath, '_github_workflow'); - if (!existsSync(github_workflow)) mkdirSync(github_workflow); + 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); return `--env UNITY_SERIAL \ --env GITHUB_WORKSPACE=/github/workspace \ ${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \ --volume "/var/run/docker.sock":"/var/run/docker.sock:z" \ - --volume "${github_home}":"/root:z" \ - --volume "${github_workflow}":"/github/workflow:z" \ + --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 \