Skip to content

Commit

Permalink
Change mount->directory
Browse files Browse the repository at this point in the history
  • Loading branch information
efrecon committed Feb 11, 2024
1 parent 4f6a170 commit 2ee807b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
27 changes: 24 additions & 3 deletions orchestrator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,33 @@ ORCHESTRATOR_LOG=${ORCHESTRATOR_LOG:-2}
# Name of the OCI image (fully-qualified) to use. You need to have access.
ORCHESTRATOR_IMAGE=${ORCHESTRATOR_IMAGE:-"ghcr.io/efrecon/runner-krunvm:main"}

# Memory to allocate to the VM (in MB). Regular runners use more than the
# default.
ORCHESTRATOR_MEMORY=${ORCHESTRATOR_MEMORY:-"1024"}

# Number of vCPUs to allocate to the VM. Regular runners use more than the
# default.
ORCHESTRATOR_CPUS=${ORCHESTRATOR_CPUS:-"2"}

# Name of the VM to create (krunvm create)
ORCHESTRATOR_NAME=${ORCHESTRATOR_NAME:-"runner"}

# DNS to use on the VM. This is the same as the default in krunvm.
ORCHESTRATOR_DNS=${ORCHESTRATOR_DNS:-"1.1.1.1"}

# Host->VM mount points, pairs of directories separated by a colon.
ORCHESTRATOR_MOUNT=${ORCHESTRATOR_MOUNT:-""}

# Name of top directory in VM where to host a copy of the root directory of this
# script. When this is set, the runner starter script from that directory will
# be used -- instead of the one already in the OCI image. This option is mainly
# usefull for development and testing.
ORCHESTRATOR_DIR=${ORCHESTRATOR_DIR:-""}

# Should the runner be isolated in its own environment. This will pass all
# configuration down to the runner starter script as an environment variable to
# avoid leaking secrets in the command line. The file will be removed as soon as
# used.
ORCHESTRATOR_ISOLATION=${ORCHESTRATOR_ISOLATION:-"1"}

# GitHub host, e.g. github.com or github.example.com
Expand Down Expand Up @@ -82,12 +100,14 @@ RUNNER_UPDATE=${RUNNER_UPDATE:-"0"}
KRUNVM_RUNNER_MAIN="Run several krunvm-based GitHub runners on a single host"


while getopts "c:d:g:G:i:Il:L:m:M:n:p:s:t:T:u:Uvh-" opt; do
while getopts "c:d:D:g:G:i:Il:L:m:M:n:p:s:t:T:u:Uvh-" opt; do
case "$opt" in
c) # Number of CPUs to allocate to the VM
ORCHESTRATOR_CPUS="$OPTARG";;
d) # DNS server to use in VM
ORCHESTRATOR_DNS=$OPTARG;;
D) # Local top VM directory where to host a copy of the root directory of this script (for dev and testing).
ORCHESTRATOR_DIR=$OPTARG;;
g) # GitHub host, e.g. github.com or github.example.com
RUNNER_GITHUB="$OPTARG";;
G) # Group to attach the runners to
Expand Down Expand Up @@ -171,7 +191,8 @@ set -- \
--mem "$ORCHESTRATOR_MEMORY" \
--dns "$ORCHESTRATOR_DNS" \
--name "$ORCHESTRATOR_NAME"
set -- "$@" --volume "${ORCHESTRATOR_ROOTDIR}:${ORCHESTRATOR_MOUNT}"
# TODO: Implement mounts
set -- "$@" --volume "${ORCHESTRATOR_ROOTDIR}:${ORCHESTRATOR_DIR}"
if [ -n "${ORCHESTRATOR_ENVIRONMENT:-}" ]; then
set -- "$@" --volume "${ORCHESTRATOR_ENVIRONMENT}:/_environment"
fi
Expand Down Expand Up @@ -199,7 +220,7 @@ for i in $(seq 1 "$runners"); do
verbose "Creating runner loop $i"
"$ORCHESTRATOR_ROOTDIR/runner.sh" \
-n "$ORCHESTRATOR_NAME" \
-M "$ORCHESTRATOR_MOUNT" \
-D "$ORCHESTRATOR_DIR" \
-E "${ORCHESTRATOR_ENVIRONMENT:-}" &
set -- "$@" "$!"
fi
Expand Down
15 changes: 12 additions & 3 deletions runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ RUNNER_UPDATE=${RUNNER_UPDATE:-"0"}
# Name of the microVM to run from
RUNNER_NAME=${RUNNER_NAME:-"runner"}

# Name of top directory in VM where to host a copy of the root directory of this
# script. When this is set, the runner starter script from that directory will
# be used -- instead of the one already in the OCI image. This option is mainly
# usefull for development and testing.
RUNNER_DIR=${RUNNER_DIR:-""}

RUNNER_MOUNT=${RUNNER_MOUNT:-""}

# Location (at host) where to place environment files for each run.
Expand All @@ -76,8 +82,10 @@ RUNNER_ENVIRONMENT=${RUNNER_ENVIRONMENT:-""}
KRUNVM_RUNNER_MAIN="Create runners forever using krunvm"


while getopts "E:g:G:l:L:M:n:p:s:T:u:Uvh-" opt; do
while getopts "D:E:g:G:l:L:M:n:p:s:T:u:Uvh-" opt; do
case "$opt" in
D) # Local top VM directory where to host a copy of the root directory of this script (for dev and testing).
RUNNER_DIR=$OPTARG;;
E) # Location (at host) where to place environment files for each run.
RUNNER_ENVIRONMENT="$OPTARG";;
g) # GitHub host, e.g. github.com or github.example.com
Expand Down Expand Up @@ -118,10 +126,11 @@ KRUNVM_RUNNER_VERBOSE=$RUNNER_VERBOSE

# Decide which runner.sh implementation (this is the "entrypoint" of the
# microVM) to use: the one from the mount point, or the built-in one.
if [ -z "$RUNNER_MOUNT" ]; then
if [ -z "$RUNNER_DIR" ]; then
runner=/opt/gh-runner-krunvm/bin/runner.sh
else
runner=${RUNNER_MOUNT%/}/runner/runner.sh
check_command "${RUNNER_ROOTDIR}/runner/runner.sh"
runner=${RUNNER_DIR%/}/runner/runner.sh
fi

while true; do
Expand Down

0 comments on commit 2ee807b

Please sign in to comment.