feat: support self-hosted runners (#170)

* feat: support self-hosted runners

similar to https://github.com/game-ci/unity-builder/pull/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

* compile typescript files
pull/171/head
Paul Pacheco 2022-03-11 11:46:28 -06:00 committed by GitHub
parent 174e562151
commit 79715c7e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 917 additions and 871 deletions

1764
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -20,6 +20,7 @@ async function run() {
checkName, checkName,
} = Input.getFromUser(); } = Input.getFromUser();
const baseImage = new ImageTag({ version: unityVersion, customImage }); const baseImage = new ImageTag({ version: unityVersion, customImage });
const runnerTempPath = process.env.RUNNER_TEMP;
try { try {
// Build docker image // Build docker image
@ -37,6 +38,7 @@ async function run() {
sshAgent, sshAgent,
gitPrivateToken, gitPrivateToken,
githubToken, githubToken,
runnerTempPath,
}); });
} finally { } finally {
// Set output // Set output

View File

@ -1,13 +1,15 @@
import { existsSync, mkdirSync } from 'fs';
import ImageTag from './image-tag'; import ImageTag from './image-tag';
import { exec } from '@actions/exec'; import { exec } from '@actions/exec';
import path from 'path';
const Docker = { const Docker = {
async build(buildParameters, silent = false) { async build(buildParameters, silent = false) {
const { path, dockerfile, baseImage } = buildParameters; const { path: buildPath, dockerfile, baseImage } = buildParameters;
const { version } = baseImage; const { version } = baseImage;
const tag = new ImageTag({ version }); const tag = new ImageTag({ version });
const command = `docker build ${path} \ const command = `docker build ${buildPath} \
--file ${dockerfile} \ --file ${dockerfile} \
--build-arg IMAGE=${baseImage} \ --build-arg IMAGE=${baseImage} \
--tag ${tag}`; --tag ${tag}`;
@ -29,8 +31,14 @@ const Docker = {
sshAgent, sshAgent,
gitPrivateToken, gitPrivateToken,
githubToken, githubToken,
runnerTempPath,
} = parameters; } = parameters;
const githubHome = path.join(runnerTempPath, '_github_home');
if (!existsSync(githubHome)) mkdirSync(githubHome);
const githubWorkflow = path.join(runnerTempPath, '_github_workflow');
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
const command = `docker run \ const command = `docker run \
--workdir /github/workspace \ --workdir /github/workspace \
--rm \ --rm \
@ -61,10 +69,10 @@ const Docker = {
--env RUNNER_WORKSPACE \ --env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \ --env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \ ${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "/var/run/docker.sock":"/var/run/docker.sock" \ --volume "/var/run/docker.sock":"/var/run/docker.sock:z" \
--volume "/home/runner/work/_temp/_github_home":"/root" \ --volume "${githubHome}":"/root:z" \
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \ --volume "${githubWorkflow}":"/github/workflow:z" \
--volume "${workspace}":"/github/workspace" \ --volume "${workspace}":"/github/workspace:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \ ${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \ ${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
${useHostNetwork ? '--net=host' : ''} \ ${useHostNetwork ? '--net=host' : ''} \