Skip to content

Commit c1d31c1

Browse files
committed
Use /var/cache/ci-storage (potentially persisted-mounted from the host) to speed up action runner self-updating
1 parent d75f6ef commit c1d31c1

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

ci-storage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def action_load(
248248
if layer:
249249
print(f"{prefix} {storage} has no slots, so exiting with a no-op")
250250
else:
251-
print(f"{prefix} {storage} has no slots, so cleaning f{local_dir}")
251+
print(f"{prefix} {storage} has no slots, so cleaning {local_dir}")
252252
action_clean(
253253
local_dir=local_dir,
254254
exclude=exclude,

docker/ci-runner/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ services:
7070
- CI_STORAGE_HOST=127.0.0.1:10022
7171
- BTIME
7272
volumes:
73-
# ~/.ssh/ci-storage must exist on the docker host to access ci-storage
74-
# remote container at $FORWARD_HOST
73+
# ~/.ssh/ci-storage private key file must exist on the docker host to
74+
# access ci-storage remote container at $FORWARD_HOST.
7575
- ~/.ssh/ci-storage:/run/secrets/CI_STORAGE_PRIVATE_KEY
76+
# This volume will survive the container restart.
77+
- ~/.ci-storage-cache:/var/cache/ci-storage
7678
tmpfs:
7779
# Having work directory on tmpfs makes latency predictable, which is very
7880
# handy while debugging the CI perf bottlenecks.
79-
- /mnt:exec
81+
- /mnt:exec,size=80%
8082
```
8183
8284
Example for your custom Dockerfile mentioned above. This Dockerfile allows to

docker/ci-runner/guest/entrypoint.03-update.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,29 @@ if [[ "$(find . -name "$updated_at_file" -mtime +21)" != "" ]]; then
1717
aarch64|arm64) arch=linux-arm64 ;;
1818
*) echo >&2 "unsupported architecture: $arch"; exit 1 ;;
1919
esac
20-
say "Fetching the latest runner version..."
20+
21+
say "Getting the latest runner version (previously updated at $(cat $updated_at_file))..."
2122
runner_version=$(curl --silent "https://api.github.com/repos/actions/runner/releases/latest" | jq -r ".tag_name[1:]")
22-
say "Updating runner to \"$runner_version\" (previously updated on $(cat $updated_at_file))..."
23-
curl --no-progress-meter -L "https://github.com/actions/runner/releases/download/v$runner_version/actions-runner-$arch-$runner_version.tar.gz" | tar xz
24-
say "Updated runner to $runner_version (previously updated on $(cat $updated_at_file))."
25-
date > $updated_at_file
23+
24+
file="actions-runner-$arch-$runner_version.tar.gz"
25+
path="$CACHE_DIR/$file"
26+
url="https://github.com/actions/runner/releases/download/v$runner_version/$file"
27+
28+
say "Content of $CACHE_DIR:"
29+
ls -la "$CACHE_DIR"
30+
31+
if [[ ! -r "$path" ]]; then
32+
say "Downloading $url to $CACHE_DIR..."
33+
curl --no-progress-meter -L "$url" > "$path.tmp"
34+
mv -f "$path.tmp" "$path"
35+
else
36+
say "Using previously downloaded $path"
37+
fi
38+
39+
tar xzf "$path"
40+
date > "$updated_at_file"
41+
42+
say "Updated runner to $runner_version from $path"
2643
else
27-
say "Runner is new enough (last updated on $(cat $updated_at_file)), skipping the update."
44+
say "Runner is new enough (previously updated at $(cat $updated_at_file)), skipping the update."
2845
fi

docker/ci-runner/root/entrypoint.00-helpers.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ set -u -e
77
# GitHub Runner's work directory (encouraged to be mounted on tmpfs).
88
export WORK_DIR="/mnt"
99

10+
# Cache directory that potentially survives the container restarts.
11+
export CACHE_DIR="/var/cache/ci-storage"
12+
1013
# We don't use ec2metadata CLI tool, because it does not allow to configure
1114
# timeout. In case the container is run outside of AWS infra (e.g. during local
1215
# development), the absense of timeout causes problems. Prints an empty value

docker/ci-runner/root/entrypoint.02-permissions.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
#
55
set -u -e
66

7+
mkdir -p "$WORK_DIR"
78
chown guest:guest "$WORK_DIR"
89
chmod 700 "$WORK_DIR"
10+
11+
mkdir -p "$CACHE_DIR"
12+
chown guest:guest "$CACHE_DIR"
13+
chmod 700 "$CACHE_DIR"

docker/compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,16 @@ services:
6363
- DEBUG_SHUTDOWN_DELAY_SEC=1
6464
secrets:
6565
- CI_STORAGE_PRIVATE_KEY
66+
volumes:
67+
- ci-storage-cache:/var/cache/ci-storage
6668
tmpfs:
6769
- /mnt:exec
6870

6971
volumes:
7072
ci-storage-mnt:
7173
external: false
74+
ci-storage-cache:
75+
external: false
7276

7377
secrets:
7478
CI_STORAGE_PUBLIC_KEY:

0 commit comments

Comments
 (0)