Skip to content

Commit

Permalink
Update caching for the Linux Runner
Browse files Browse the repository at this point in the history
  • Loading branch information
fabi200123 committed Oct 9, 2024
1 parent 7979634 commit fff8fc8
Showing 1 changed file with 7 additions and 37 deletions.
44 changes: 7 additions & 37 deletions cloudconfig/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,6 @@ function fail() {
exit 1
}
# This will echo the version number in the filename. Given a file name like: actions-runner-osx-x64-2.299.1.tar.gz
# this will output: 2.299.1
function getRunnerVersion() {
FILENAME="{{ .FileName }}"
[[ $FILENAME =~ ([0-9]+\.[0-9]+\.[0-9+]) ]]
echo $BASH_REMATCH
}
function getCachedToolsPath() {
CACHED_RUNNER="/opt/cache/actions-runner/latest"
if [ -d "$CACHED_RUNNER" ];then
echo "$CACHED_RUNNER"
return 0
fi
VERSION=$(getRunnerVersion)
if [ -z "$VERSION" ]; then
return 0
fi
CACHED_RUNNER="/opt/cache/actions-runner/$VERSION"
if [ -d "$CACHED_RUNNER" ];then
echo "$CACHED_RUNNER"
return 0
fi
return 0
}
function downloadAndExtractRunner() {
sendStatus "downloading tools from {{ .DownloadURL }}"
if [ ! -z "{{ .TempDownloadToken }}" ]; then
Expand All @@ -122,25 +94,23 @@ function downloadAndExtractRunner() {
# chown {{ .RunnerUsername }}:{{ .RunnerGroup }} -R /home/{{ .RunnerUsername }}/actions-runner/ || fail "failed to change owner"
}
CACHED_RUNNER=$(getCachedToolsPath)
if [ -z "$CACHED_RUNNER" ];then
RUN_HOME="/home/{{ .RunnerUsername }}/actions-runner"
if [! -d "$RUN_HOME" ];then
downloadAndExtractRunner
sendStatus "installing dependencies"
cd /home/{{ .RunnerUsername }}/actions-runner
cd "$RUN_HOME"
sudo ./bin/installdependencies.sh || fail "failed to install dependencies"
else
sendStatus "using cached runner found in $CACHED_RUNNER"
sendStatus "using cached runner found in $RUN_HOME"
OFS_AVAIL=1
RUN_HOME="/home/{{ .RunnerUsername }}/actions-runner"
sudo mkdir -p $OFS_DIR/upper-layer $OFS_DIR/work-layer $RUN_HOME
sudo chown {{ .RunnerUsername }}:{{ .RunnerGroup }} -R $OFS_DIR/upper-layer $OFS_DIR/work-layer $CACHED_RUNNER $RUN_HOME
sudo mount -t overlay overlay -o lowerdir=$CACHED_RUNNER,upperdir=$OFS_DIR/upper-layer,workdir=$OFS_DIR/work-layer $RUN_HOME || OFS_AVAIL=0
sudo chown {{ .RunnerUsername }}:{{ .RunnerGroup }} -R $OFS_DIR/upper-layer $OFS_DIR/work-layer $RUN_HOME $RUN_HOME
sudo mount -t overlay overlay -o lowerdir=$RUN_HOME,upperdir=$OFS_DIR/upper-layer,workdir=$OFS_DIR/work-layer $RUN_HOME || OFS_AVAIL=0
if [ $OFS_AVAIL -eq 0 ];then
sendStatus "falling back to non-overlayfs mode"
sudo cp -a "$CACHED_RUNNER/." $RUN_HOME || fail "failed to copy cached runner"
sudo chown {{ .RunnerUsername }}:{{ .RunnerGroup }} -R "$RUN_HOME" || fail "failed to change owner"
fi
cd /home/{{ .RunnerUsername }}/actions-runner
cd "$RUN_HOME"
fi
Expand Down

0 comments on commit fff8fc8

Please sign in to comment.