-
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: image factory runner container image
- Loading branch information
Silvija Tovernic
committed
Sep 18, 2024
1 parent
79dc570
commit 9b4ee60
Showing
2 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
FROM ubuntu:22.04 | ||
|
||
ARG RUNNER_VERSION=2.319.1 | ||
ARG RUNNER_ARCH=arm64 | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive \ | ||
USER_NAME=gha \ | ||
USER_GROUP=gha \ | ||
USER_UID=1001 \ | ||
USER_GID=1001 \ | ||
USER_HOME=/opt/gha | ||
|
||
# Update and install packadges and dependencies | ||
RUN apt-get update -y && \ | ||
apt-get upgrade -y && \ | ||
apt-get install --no-install-recommends -y \ | ||
ca-certificates \ | ||
curl \ | ||
wget \ | ||
unzip \ | ||
vim \ | ||
git \ | ||
jq | ||
|
||
|
||
# Create runner user | ||
RUN mkdir -p ${USER_HOME} && \ | ||
groupadd -g ${USER_GID} ${USER_GROUP} && \ | ||
useradd -r -u ${USER_UID} -g ${USER_GID} -d ${USER_HOME} -s /sbin/nologin -c "GitHub Actions User" ${USER_NAME} && \ | ||
chown ${USER_GROUP}:${USER_NAME} ${USER_HOME} | ||
|
||
WORKDIR ${USER_HOME} | ||
|
||
# Download GitHub Actions runner | ||
RUN mkdir actions-runner && \ | ||
cd actions-runner && \ | ||
curl -o actions-runner-linux-${RUNNER_ARCH}-${RUNNER_VERSION}.tar.gz -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-${RUNNER_ARCH}-${RUNNER_VERSION}.tar.gz && \ | ||
tar xzf ./actions-runner-linux-${RUNNER_ARCH}-${RUNNER_VERSION}.tar.gz | ||
|
||
# Install additional dependencies | ||
RUN actions-runner/bin/installdependencies.sh | ||
|
||
# Add start script and make it executable | ||
ADD scripts/start-github-runner.sh start-github-runner.sh | ||
RUN chmod +x start-github-runner.sh | ||
|
||
# Set runner user | ||
USER ${USER_NAME} | ||
|
||
# Set start script as an entrypoint | ||
ENTRYPOINT ["./start-github-runner.sh"] |
27 changes: 27 additions & 0 deletions
27
images/docker/image-factory-runner/scripts/start-github-runner.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,27 @@ | ||
#!/bin/bash | ||
|
||
GITHUB_OWNER=$GITHUB_OWNER | ||
GITHUB_REPOSITORY=$GITHUB_REPOSITORY | ||
GITHUB_TOKEN=$(cat /.pat/.token) | ||
GITHUB_RUNNER_NAME=$(hostname) | ||
|
||
echo "Getting runner registration token from GitHub..." | ||
REG_TOKEN=$(curl -sX POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPOSITORY}/actions/runners/registration-token | jq .token --raw-output) | ||
|
||
# Add this part once PAT token generation is set up on the runner host VM - new PAT token will be generated on each start | ||
# | ||
# echo "Removing PAT token from runner filesystem" | ||
# rm -rf /.pat/.token | ||
|
||
echo "Connect runner to GitHub:" | ||
cd actions-runner | ||
./config.sh \ | ||
--url https://github.com/${GITHUB_OWNER}/${GITHUB_REPOSITORY} \ | ||
--token ${REG_TOKEN} \ | ||
--name ${RUNNER_NAME} \ | ||
--unattended \ | ||
--ephemeral \ | ||
--replace \ | ||
--disableupdate | ||
|
||
./run.sh & wait $! |