Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orchestrator and runner #3

Merged
merged 34 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0d22f09
Enforce presence of jq
efrecon Feb 10, 2024
68210f1
Add utility function
efrecon Feb 10, 2024
f4c95fe
Use new functions and enforce good defaults
efrecon Feb 10, 2024
00c9486
Add an "orchestrator" and a runner
efrecon Feb 10, 2024
7b77388
Rewrite to more generic env file "parser"
efrecon Feb 11, 2024
1f52637
Add simple runner test
efrecon Feb 11, 2024
c3af32c
Only print vars
efrecon Feb 11, 2024
8a4a2aa
Add ps command to check isolation
efrecon Feb 11, 2024
9642c42
Improve security through avoiding env leaks
efrecon Feb 11, 2024
bb16216
Improve logging
efrecon Feb 11, 2024
53bbda6
Remove comment. Signalling not working (yet?)
efrecon Feb 11, 2024
4f6a170
Ignore more variables
efrecon Feb 11, 2024
2ee807b
Change mount->directory
efrecon Feb 11, 2024
918101b
Enforce ephemeral runners
efrecon Feb 11, 2024
6d7b4fc
Implement host->VM mount points
efrecon Feb 11, 2024
a0a7d7d
Improve logging: use identifier
efrecon Feb 11, 2024
1d4d2bf
Install debug shell
efrecon Feb 12, 2024
5fd2cdc
Run on regular runners
efrecon Feb 12, 2024
5a09519
Add waiting debug
efrecon Feb 12, 2024
c4f743e
Revert to self-host test
efrecon Feb 12, 2024
8fcb628
Add GH runner analysis
efrecon Feb 12, 2024
57db011
Configure from installation copies
efrecon Feb 12, 2024
cd100ca
Add sleep between runner startups
efrecon Feb 12, 2024
cc3e455
Add dev CI
efrecon Feb 13, 2024
3f39442
Make docker dependencies explicit
efrecon Feb 13, 2024
715bedb
Keep tgz file and store under version name
efrecon Feb 13, 2024
95810d4
Install from tgz and fix permissions docker sock
efrecon Feb 13, 2024
caefd6e
Change workflow name
efrecon Feb 13, 2024
9166f03
Wait for podman to be running
efrecon Feb 13, 2024
332856d
Change workflow name
efrecon Feb 13, 2024
f36c86a
Change default user to runner
efrecon Feb 13, 2024
bb5dad1
Add docker test
efrecon Feb 13, 2024
9fe4ea8
Remove mount when no DIR specified
efrecon Feb 13, 2024
b4beca8
Remove test
efrecon Feb 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: dev

on:
push:
branches:
- feature/*

jobs:
build-base:
uses: ./.github/workflows/_build.yml
with:
image: ${{ github.actor }}/runner-krunvm-base
file: Dockerfile.base
platforms: linux/amd64
secrets:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

build-main:
needs:
- build-base
uses: ./.github/workflows/_build.yml
with:
image: ${{ github.actor }}/runner-krunvm
file: Dockerfile
platforms: linux/amd64
build-args: |
VERSION=${{ needs.build-base.outputs.version }}
secrets:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions base/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ BASE_DOCKER_WRAPPER=${BASE_DOCKER_WRAPPER:-$BASE_ROOTDIR/docker.sh}
. "$BASE_ROOTDIR/../lib/common.sh"

# shellcheck disable=SC2034 # Used in sourced scripts
KRUNVM_RUNNER_MAIN="Install a base GitHub runner environment in Fedora"
KRUNVM_RUNNER_DESCR="Install a base GitHub runner environment in Fedora"

while getopts "dl:vh-" opt; do
case "$opt" in
Expand Down Expand Up @@ -115,7 +115,7 @@ dnf -y install \
if [ "$BASE_DOCKER" = "1" ]; then
verbose "Installing docker"
dnf -y config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
dnf -y install docker-ce-cli
dnf -y install docker-ce-cli docker-buildx-plugin docker-compose-plugin

# Replace the real docker binary with our wrapper so we will be able to force
# running containers on the host network.
Expand Down
22 changes: 22 additions & 0 deletions docs/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,25 @@ the runner (sic). In most cases, the runner will be run as the `runner` user.

[main]: https://github.com/myoung34/docker-github-actions-runner/blob/master/Dockerfile
[entrypoint]: https://github.com/myoung34/docker-github-actions-runner/blob/master/entrypoint.sh

## Organisation of the GitHub Runners

The logged in user is called `runner`. User id `1001`, group `127`. The main
group of the user is the `docker` group. Home directory is `/home/runner`. Under
that directory is a directory called `work`, the working directory under which
repositories are checked out (by default).

Directly under the home directory of the `runner` user, there is a directory
called `runners`. It contains `tgz` files named after the version number of the
runners that have existed on the machine, e.g. `2.313.0.tgz`. It also contains
directories named after the version number and containing all the installation
files, e.g. `2.313.0`. Under these directories are the shell scripts to
configure and run, e.g. `config.sh` and `run.sh`, but also a number of hidden
files, all starting with a dot `.` containing the configuration (also live
configuration of the runner). For example, `.runner` seems to contain part of
the configuration and `.path` and `.env` being the files that seed (or are) the
files pointed at by the `GITHUB_PATH` and `GITHUB_ENV` environment variables.

The hosted tool cache is at `/opt/hostedtoolcache`. It is owned by the
`runner:docker` user:group pair. There is also a `/opt/actionarchivecache`, same
user:group pair.
54 changes: 51 additions & 3 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,68 @@ random_string() {
usage() {
# This uses the comments behind the options to show the help. Not extremly
# correct, but effective and simple.
echo "$0 -- ${KRUNVM_RUNNER_MAIN:-"Part of the gh-krunvm-runner project"}" && \
echo "$0 -- ${KRUNVM_RUNNER_DESCR:-"Part of the gh-krunvm-runner project"}" && \
grep "[[:space:]].) #" "$0" |
sed 's/#//' |
sed -r 's/([a-z-])\)/-\1/'
sed -r 's/([a-zA-Z-])\)/-\1/'
exit "${1:-0}"
}

check_command() {
trace "Checking $1 is an accessible command"
if ! command -v "$1" >/dev/null 2>&1; then
error "Command not found: $1"
fi
}

# Get the value of a variable in an env file. The function enforces sourcing in
# a separate process to avoid leaking out the sources variables.
get_env() (
if [ "$#" -ge 2 ]; then
if [ -f "$1" ]; then
# shellcheck disable=SC1090 # We want to source the file. Danger zone!
. "$1"

eval printf %s "\$$2" || true
fi
fi
)

run_krunvm() {
debug "Running krunvm $*"
buildah unshare krunvm "$@"
}

# Wait for a path to exist
# $1 is the test to perform, e.g. -f for file, -d for directory, etc.
# $2 is the path to wait for
# $3 is the timeout in seconds
# $4 is the interval in seconds
wait_path() {
_interval="${4:-1}"
_elapsed=0

while ! test "$1" "$2"; do
if [ "$_elapsed" -ge "${3:-60}" ]; then
error "Timeout waiting for $2"
fi
_elapsed=$((_elapsed+_interval))
sleep "$_interval"
debug "Waiting for $2"
done
}

# PML: Poor Man's Logging
_log() {
# Capture level and shift it away, rest will be passed blindly to printf
_lvl=${1:-LOG}; shift
if [ -z "${KRUNVM_RUNNER_BIN:-}" ]; then
KRUNVM_RUNNER_BIN=$(basename "$0")
KRUNVM_RUNNER_BIN=${KRUNVM_RUNNER_BIN%.sh}
fi
# shellcheck disable=SC2059 # We want to expand the format string
printf '[%s] [%s] [%s] %s\n' \
"$(basename "$0")" \
"${KRUNVM_RUNNER_BIN:-$(basename "$0")}" \
"$_lvl" \
"$(date +'%Y%m%d-%H%M%S')" \
"$(printf "$@")" \
Expand Down
Loading
Loading