-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ci-storage-host container, add ci-storage call when self-hosted-r…
…unner initializes
- Loading branch information
Showing
7 changed files
with
126 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
ARG BASE_IMAGE="ubuntu:22.04" | ||
|
||
FROM $BASE_IMAGE | ||
|
||
ENV GH_REPOSITORY="" | ||
ENV CI_STORAGE_HOST_SSH_KEY="" | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN true \ | ||
&& apt-get update -y \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y --no-install-recommends \ | ||
awscli rsync openssh-server \ | ||
mc gcc git curl wget pv psmisc unzip vim nano telnet net-tools bash-completion \ | ||
libssl-dev apt-transport-https build-essential ca-certificates locales pkg-config \ | ||
&& sed -i -e "s|#PermitRootLogin.*|PermitRootLogin no|" /etc/ssh/sshd_config \ | ||
&& useradd -m ubuntu \ | ||
&& mkdir -p /home/ubuntu/.ssh \ | ||
&& chown -R ubuntu:ubuntu /home/ubuntu/.ssh \ | ||
&& chmod 700 /home/ubuntu/.ssh | ||
|
||
COPY --chmod=755 entrypoint.sh / | ||
|
||
WORKDIR / | ||
EXPOSE 22/tcp | ||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
# | ||
# A container which holds ci-storage saved slots. Its ~ubuntu/ci-storage should | ||
# be persistent across container restarts. | ||
# | ||
set -u -e | ||
|
||
if [ "${CI_STORAGE_HOST_SSH_KEY:-}" = "" ]; then | ||
echo "CI_STORAGE_HOST_SSH_KEY is not set, exiting..." | ||
exit 1 | ||
fi | ||
|
||
cd /home/ubuntu | ||
|
||
echo "$CI_STORAGE_HOST_SSH_KEY" > .ssh/id_ed25519 | ||
chmod 600 .ssh/id_ed25519 | ||
ssh-keygen -f .ssh/id_ed25519 -y > .ssh/authorized_keys | ||
chown -R ubuntu:ubuntu .ssh | ||
|
||
# This code is for simplifying the CI tests and allow self-hosted-runner to boot | ||
# in docker-compose. In real world, the 1st slot created should contain the real | ||
# files (e.g. a cloned git repo). | ||
if [ ! -e ci-storage -a "${GH_REPOSITORY:-}" != "" ]; then | ||
mkdir -p ci-storage/$GH_REPOSITORY/initial | ||
chown -R ubuntu:ubuntu ci-storage | ||
fi | ||
|
||
mkdir -p /var/run/sshd | ||
exec /usr/sbin/sshd -D -o ListenAddress=0.0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
version: "3.4" | ||
services: | ||
ci-storage: | ||
ci-storage-host: | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile | ||
context: ci-storage-host | ||
dockerfile: Dockerfile | ||
ports: | ||
- 10022:22 | ||
environment: | ||
- GH_REPOSITORY | ||
- CI_STORAGE_HOST_SSH_KEY | ||
self-hosted-runner: | ||
build: | ||
context: self-hosted-runner | ||
additional_contexts: | ||
root: .. | ||
dockerfile: Dockerfile | ||
environment: | ||
- GH_REPOSITORY | ||
- GH_LABELS | ||
- GH_TOKEN | ||
- CI_STORAGE_HOST=ci-storage-host | ||
- CI_STORAGE_HOST_SSH_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Auto-Scaling Self-Hosted Runner Image | ||
|
||
You can build an image from this Dockerfile and use it to launch as many | ||
self-hosted runners as you want. An example scenario: | ||
|
||
1. Build an image based off this Dockerfile and publish it. You'll likely want | ||
to install some more software into that image (e.g. Node, Python etc.), so it | ||
may make sense to extend the base image with your own commands. | ||
2. Run AWS ECS cluster (with e.g. AWS Fargate) and use the image you just | ||
published. Configure its environment variables accordingly: GH_REPOSITORY, | ||
GH_LABELS, GH_TOKEN etc. - see details in entrypoint.sh. | ||
3. Set up auto-scaling rules in the ECS cluster based on the containers' CPU | ||
usage. The running containers are safe to shut down at anytime if it's done | ||
gracefully and with high timeout (to let all the running workflow jobs finish | ||
there and de-register the runner). | ||
4. And here comes the perf magic: when the container first boots, but before it | ||
becomes available for the jobs, it pre-initializes its work directory from | ||
ci-storage slots storage (see CI_STORAGE_HOST). So when a job is picked up, | ||
it already has its work directory pre-created and having most of the build | ||
artifacts of someone else. If the job then uses ci-storage GitHub action to | ||
restore the files from a slot, it will be very quick, because most of the | ||
files are already there. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters