Bootstrap docker from js

This commit is contained in:
Webber
2019-12-17 22:48:54 +01:00
committed by Webber Takken
parent 0bb0dbd7be
commit dccdec9d3b
9 changed files with 184 additions and 91 deletions

View File

@@ -3,44 +3,23 @@ const path = require('path');
const { exec } = require('@actions/exec');
async function action() {
// Path to the project to open with Unity
const projectPath = core.getInput('projectPath', {
required: false,
default: './',
});
// Explicitly notify about platform support
if (process.platform !== 'linux') {
throw new Error('Currently only Linux-based platforms are supported');
}
// Target platform for the build
const buildTarget = core.getInput('buildTarget', {
required: false,
default: 'WebGL',
});
// Name of the build
const buildName = core.getInput('buildName', {
required: false,
default: 'TestBuild',
});
// Path where build will be stored
const buildsPath = core.getInput('buildsPath', {
required: false,
default: 'build',
});
// Method to execute within unity. Must be static
const buildMethod = core.getInput('buildMethod', {
required: false,
default: '',
});
// Input variables specified in workflows using "with" prop.
const projectPath = core.getInput('projectPath', { default: './' });
const buildTarget = core.getInput('buildTarget', { default: 'WebGL' });
const buildName = core.getInput('buildName', { default: 'TestBuild' });
const buildsPath = core.getInput('buildsPath', { default: 'build' });
const buildMethod = core.getInput('buildMethod', { default: '' });
// Run appropriate docker image with given args
await exec(path.join(__dirname, 'run-unity-builder.sh'), [
projectPath,
buildTarget,
buildName,
buildsPath,
buildMethod,
]);
const bootstrapper = path.join(__dirname, 'run-unity-builder.sh');
await exec(`ls ${bootstrapper}`);
await exec(`chmod +x ${bootstrapper}`);
await exec(bootstrapper, [projectPath, buildTarget, buildName, buildsPath, buildMethod]);
}
action().catch(error => {

View File

@@ -1,19 +1,73 @@
#!/usr/bin/env sh
#!/bin/sh
#
# Input variables
#
PROJECT_PATH=$1
UNITY_VERSION="2019.2.11f1"
BUILD_TARGET=$2
BUILD_NAME=$3
BUILDS_PATH=$4
BUILD_METHOD=$5
DOCKER_IMAGE_TAG=unity-builder-image
#
# Default variables
#
echo "Running docker container with specific tag"
# PROJECT_PATH = test-project
# BUILD_TARGET =
# BUILD_NAME =
# BUILDS_PATH =
# BUILD_METHOD =
# HOME = /home/runner
# GITHUB_REF = refs/pull/8/merge
# GITHUB_SHA = 0e697e1f2d80e0e8505c0e0dcff76d24bc7a4f36
# GITHUB_REPOSITORY = webbertakken/unity-builder
# GITHUB_ACTOR = webbertakken
# GITHUB_WORKFLOW = Actions 😎
# GITHUB_HEAD_REF = prepare-for-multi-target
# GITHUB_BASE_REF = master
# GITHUB_EVENT_NAME = pull_request
# GITHUB_WORKSPACE = /home/runner/work/unity-builder/unity-builder
# GITHUB_ACTION = self
# GITHUB_EVENT_PATH = /home/runner/work/_temp/_github_workflow/event.json
# RUNNER_OS = Linux
# RUNNER_TOOL_CACHE = /opt/hostedtoolcache
# RUNNER_TEMP = /home/runner/work/_temp
# RUNNER_WORKSPACE = /home/runner/work/unity-builder
docker build \
--file ../Dockerfile \
--tag DOCKER_IMAGE_TAG \
../
#
# Internal variables
#
ACTION_ROOT=$(dirname $(dirname $(readlink -fm "$0")))
DOCKER_IMAGE_TAG=webber-unity:$UNITY_VERSION-$BUILD_TARGET
# TODO - Remove debug statements below
echo "Listing ACTION_ROOT"
ls $ACTION_ROOT
echo ""
echo "Listing GITHUB_WORKSPACE"
ls $GITHUB_WORKSPACE
echo ""
echo "Listing RUNNER_WORKSPACE"
ls $RUNNER_WORKSPACE
echo ""
#
# Build image
#
echo "Building docker images for $BUILD_TARGET"
docker build $GITHUB_WORKSPACE \
--file $ACTION_ROOT/Dockerfile \
--tag $DOCKER_IMAGE_TAG
#
# Run specified container
#
docker run \
--workdir /github/workspace \
@@ -23,7 +77,7 @@ docker run \
--env BUILD_NAME \
--env BUILDS_PATH \
--env BUILD_METHOD \
--env HOME \
--env HOME=/github/home \
--env GITHUB_REF \
--env GITHUB_SHA \
--env GITHUB_REPOSITORY \
@@ -32,7 +86,7 @@ docker run \
--env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE \
--env GITHUB_WORKSPACE=/github/workspace \
--env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \
--env RUNNER_OS \
@@ -43,4 +97,4 @@ docker run \
--volume "/home/runner/work/_temp/_github_home":"/github/home" \
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
--volume "${PWD}":"/github/workspace" \
DOCKER_IMAGE_TAG
$DOCKER_IMAGE_TAG