Skip to content

Commit 186120d

Browse files
Merge pull request #29 from gabriel-samfira/use-overlayfs
Use overlayfs on system that supports it for cached runner
2 parents d0fe679 + 5abc75c commit 186120d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cloudconfig/templates.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ set -x
3535
CALLBACK_URL="{{ .CallbackURL }}"
3636
METADATA_URL="{{ .MetadataURL }}"
3737
BEARER_TOKEN="{{ .CallbackToken }}"
38+
{{- if .ExtraContext.OFS_DIR }}
39+
OFS_DIR_E="{{ .ExtraContext.OFS_DIR }}"
40+
{{- end }}
41+
OFS_DIR=${OFS_DIR_E:-"/opt/work"}
3842
3943
if [ -z "$METADATA_URL" ];then
4044
echo "no token is available and METADATA_URL is not set"
@@ -126,8 +130,16 @@ if [ -z "$CACHED_RUNNER" ];then
126130
sudo ./bin/installdependencies.sh || fail "failed to install dependencies"
127131
else
128132
sendStatus "using cached runner found in $CACHED_RUNNER"
129-
sudo cp -a "$CACHED_RUNNER" "/home/{{ .RunnerUsername }}/actions-runner"
130-
sudo chown {{ .RunnerUsername }}:{{ .RunnerGroup }} -R "/home/{{ .RunnerUsername }}/actions-runner" || fail "failed to change owner"
133+
OFS_AVAIL=1
134+
RUN_HOME="/home/{{ .RunnerUsername }}/actions-runner"
135+
sudo mkdir -p $OFS_DIR/upper-layer $OFS_DIR/work-layer $RUN_HOME
136+
sudo chown {{ .RunnerUsername }}:{{ .RunnerGroup }} -R $OFS_DIR/upper-layer $OFS_DIR/work-layer $CACHED_RUNNER $RUN_HOME
137+
sudo mount -t overlay overlay -o lowerdir=$CACHED_RUNNER,upperdir=$OFS_DIR/upper-layer,workdir=$OFS_DIR/work-layer $RUN_HOME || OFS_AVAIL=0
138+
if [ $OFS_AVAIL -eq 0 ];then
139+
sendStatus "falling back to non-overlayfs mode"
140+
sudo cp -a "$CACHED_RUNNER/." $RUN_HOME || fail "failed to copy cached runner"
141+
sudo chown {{ .RunnerUsername }}:{{ .RunnerGroup }} -R "$RUN_HOME" || fail "failed to change owner"
142+
fi
131143
cd /home/{{ .RunnerUsername }}/actions-runner
132144
fi
133145

0 commit comments

Comments
 (0)