Skip to content

Commit 24e9c18

Browse files
authored
Fix file ownership issues for self-hosted runners. (#141)
1 parent 92cfb31 commit 24e9c18

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

action/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
ARG IMAGE
22
FROM $IMAGE
33

4+
ARG UNAME=runner
5+
ARG UID=1000
6+
ARG GID=1000
7+
48
LABEL "com.github.actions.name"="Unity - Builder"
59
LABEL "com.github.actions.description"="Build Unity projects for different platforms."
610
LABEL "com.github.actions.icon"="box"
@@ -10,9 +14,15 @@ LABEL "repository"="http://github.com/webbertakken/unity-actions"
1014
LABEL "homepage"="http://github.com/webbertakken/unity-actions"
1115
LABEL "maintainer"="Webber Takken <webber@takken.io>"
1216

17+
RUN bash -c 'mkdir -p /github/{home,workflow,workspace}' && chown $UID:$GID -R /github/
18+
RUN getent group $GID || groupadd -g $GID $UNAME
19+
RUN id -u $UID &>/dev/null || useradd -m -u $UID -g $GID -s /bin/bash -d /github/home $UNAME
20+
1321
ADD default-build-script /UnityBuilderAction
1422
ADD steps /steps
1523
RUN chmod -R +x /steps
1624
ADD entrypoint.sh /entrypoint.sh
1725
RUN chmod +x /entrypoint.sh
1826
ENTRYPOINT ["/entrypoint.sh"]
27+
28+
USER $UID:$GID

action/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ async function action() {
1616
} else {
1717
// Build docker image
1818
// TODO: No image required (instead use a version published to dockerhub for the action, supply credentials for github cloning)
19-
const builtImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
19+
const builtImage = await Docker.build({
20+
path: actionFolder,
21+
dockerfile,
22+
baseImage,
23+
uid: buildParameters.uid,
24+
gid: buildParameters.gid,
25+
});
2026
await Docker.run(builtImage, { workspace, ...buildParameters });
2127
}
2228
}

src/model/build-parameters.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os from 'os';
12
import AndroidVersioning from './android-versioning';
23
import Input from './input';
34
import Platform from './platform';
@@ -20,8 +21,12 @@ class BuildParameters {
2021
Input.androidVersionCode,
2122
);
2223

24+
const { uid, gid } = os.userInfo();
25+
2326
return {
2427
version: Input.unityVersion,
28+
uid,
29+
gid,
2530
runnerTempPath: process.env.RUNNER_TEMP,
2631
platform: Input.targetPlatform,
2732
projectPath: Input.projectPath,

src/model/docker.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
import fs from 'fs';
12
import { exec } from '@actions/exec';
23
import ImageTag from './image-tag';
34

45
class Docker {
56
static async build(buildParameters, silent = false) {
6-
const { path, dockerfile, baseImage } = buildParameters;
7+
const { path, dockerfile, baseImage, uid, gid } = buildParameters;
78
const { version, platform } = baseImage;
89

910
const tag = new ImageTag({ repository: '', name: 'unity-builder', version, platform });
1011
const command = `docker build ${path} \
1112
--file ${dockerfile} \
1213
--build-arg IMAGE=${baseImage} \
14+
--build-arg UID=${uid} \
15+
--build-arg GID=${gid} \
1316
--tag ${tag}`;
1417

1518
await exec(command, undefined, { silent });
@@ -83,6 +86,9 @@ class Docker {
8386
--volume "${workspace}":"/github/workspace" \
8487
${image}`;
8588

89+
fs.mkdirSync(`${runnerTempPath}/_github_home`, { recursive: true });
90+
fs.mkdirSync(`${runnerTempPath}/_github_workflow`, { recursive: true });
91+
8692
await exec(command, undefined, { silent });
8793
}
8894
}

0 commit comments

Comments
 (0)