Skip to content

Commit c171de2

Browse files
committed
feat: support self-hosted runners
similar to game-ci/unity-builder#355 * Use $RUNNER_TEMP variable instead of hardcoded path for _github_home and _github_workflow * create the folders if they don't exist * mount volumes with :z for compatibility with SELinux
1 parent 174e562 commit c171de2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async function run() {
2020
checkName,
2121
} = Input.getFromUser();
2222
const baseImage = new ImageTag({ version: unityVersion, customImage });
23+
const runnerTempPath = process.env.RUNNER_TEMP;
2324

2425
try {
2526
// Build docker image
@@ -37,6 +38,7 @@ async function run() {
3738
sshAgent,
3839
gitPrivateToken,
3940
githubToken,
41+
runnerTempPath,
4042
});
4143
} finally {
4244
// Set output

src/model/docker.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import { existsSync, mkdirSync } from 'fs';
12
import ImageTag from './image-tag';
23
import { exec } from '@actions/exec';
4+
import path from 'path';
35

46
const Docker = {
57
async build(buildParameters, silent = false) {
6-
const { path, dockerfile, baseImage } = buildParameters;
8+
const { path: buildPath, dockerfile, baseImage } = buildParameters;
79
const { version } = baseImage;
810

911
const tag = new ImageTag({ version });
10-
const command = `docker build ${path} \
12+
const command = `docker build ${buildPath} \
1113
--file ${dockerfile} \
1214
--build-arg IMAGE=${baseImage} \
1315
--tag ${tag}`;
@@ -29,8 +31,14 @@ const Docker = {
2931
sshAgent,
3032
gitPrivateToken,
3133
githubToken,
34+
runnerTempPath,
3235
} = parameters;
3336

37+
const githubHome = path.join(runnerTempPath, '_github_home');
38+
if (!existsSync(githubHome)) mkdirSync(githubHome);
39+
const githubWorkflow = path.join(runnerTempPath, '_github_workflow');
40+
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
41+
3442
const command = `docker run \
3543
--workdir /github/workspace \
3644
--rm \
@@ -62,9 +70,9 @@ const Docker = {
6270
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
6371
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
6472
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
65-
--volume "/home/runner/work/_temp/_github_home":"/root" \
66-
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
67-
--volume "${workspace}":"/github/workspace" \
73+
--volume "${githubHome}":"/root:z" \
74+
--volume "${githubWorkflow}":"/github/workflow:z" \
75+
--volume "${workspace}":"/github/workspace:z" \
6876
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
6977
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
7078
${useHostNetwork ? '--net=host' : ''} \

0 commit comments

Comments
 (0)