-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding hmpps-github-actions-runner image
- Loading branch information
Showing
3 changed files
with
136 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
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,78 @@ | ||
#checkov:skip=CKV_DOCKER_2:actions/runner does not provider a mechanism for checking the health of the service | ||
FROM public.ecr.aws/ubuntu/ubuntu@sha256:4f5ca1c8b7abe2bd1162e629cafbd824c303b98954b1a168526aca6021f8affe | ||
|
||
LABEL org.opencontainers.image.vendor="Ministry of Justice" \ | ||
org.opencontainers.image.authors="HMPPS DPS" \ | ||
org.opencontainers.image.title="Actions Runner" \ | ||
org.opencontainers.image.description="Actions Runner image for HMPPS DPS" \ | ||
org.opencontainers.image.url="https://github.com/ministryofjustice/hmpps-utility-container-images" | ||
|
||
ENV CONTAINER_USER="runner" \ | ||
CONTAINER_UID="10000" \ | ||
CONTAINER_GROUP="runner" \ | ||
CONTAINER_GID="10000" \ | ||
CONTAINER_HOME="/actions-runner" \ | ||
DEBIAN_FRONTEND="noninteractive" | ||
|
||
# Checked by renovate | ||
ENV ACTIONS_RUNNER_VERSION="2.321.0" | ||
|
||
SHELL ["/bin/bash", "-e", "-u", "-o", "pipefail", "-c"] | ||
|
||
RUN <<EOF | ||
groupadd \ | ||
--gid ${CONTAINER_GID} \ | ||
--system \ | ||
${CONTAINER_GROUP} | ||
|
||
useradd \ | ||
--uid ${CONTAINER_UID} \ | ||
--gid ${CONTAINER_GROUP} \ | ||
--create-home \ | ||
${CONTAINER_USER} | ||
|
||
mkdir --parents ${CONTAINER_HOME} | ||
|
||
chown --recursive ${CONTAINER_USER}:${CONTAINER_GROUP} ${CONTAINER_HOME} | ||
|
||
apt-get update | ||
|
||
apt-get install --yes --no-install-recommends \ | ||
"apt-transport-https" \ | ||
"ca-certificates" \ | ||
"curl" \ | ||
"git" \ | ||
"jq" \ | ||
"libicu-dev" \ | ||
"lsb-release" \ | ||
"gcc" \ | ||
"libsqlite3-dev" \ | ||
"python3" \ | ||
"httpie" | ||
|
||
apt-get clean | ||
|
||
rm -rf /var/lib/apt/lists/* | ||
|
||
curl --location "https://github.com/actions/runner/releases/download/v${ACTIONS_RUNNER_VERSION}/actions-runner-linux-x64-${ACTIONS_RUNNER_VERSION}.tar.gz" \ | ||
--output "actions-runner-linux-x64-${ACTIONS_RUNNER_VERSION}.tar.gz" | ||
|
||
# Validate the checksum | ||
ACTIONS_RUNNER_PKG_SHA=$(curl -s --location "https://github.com/actions/runner/releases/tag/v${ACTIONS_RUNNER_VERSION}" | grep -A10 "SHA-256 Checksums" | grep actions-runner-linux-x64-${ACTIONS_RUNNER_VERSION} | awk -F'[<> ]' '{print $4}') | ||
echo "Release ACTIONS_RUNNER_PKG_SHA : ${ACTIONS_RUNNER_PKG_SHA}" | ||
echo "Downloaded ACTIONS_RUNNER_PKG_SHA: $(sha256sum -b actions-runner-linux-x64-${ACTIONS_RUNNER_VERSION}.tar.gz) | cut -d\ -f1" | ||
|
||
echo "${ACTIONS_RUNNER_PKG_SHA}" "actions-runner-linux-x64-${ACTIONS_RUNNER_VERSION}.tar.gz" | /usr/bin/sha256sum --check | ||
|
||
tar --extract --gzip --file="actions-runner-linux-x64-${ACTIONS_RUNNER_VERSION}.tar.gz" --directory="${CONTAINER_HOME}" | ||
|
||
rm --force "actions-runner-linux-x64-${ACTIONS_RUNNER_VERSION}.tar.gz" | ||
EOF | ||
|
||
COPY --chown=nobody:nobody --chmod=0755 src/usr/local/bin/entrypoint.sh /usr/local/bin/entrypoint.sh | ||
|
||
USER ${CONTAINER_UID} | ||
|
||
WORKDIR ${CONTAINER_HOME} | ||
|
||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] |
57 changes: 57 additions & 0 deletions
57
hmpps-github-actions-runner/src/usr/local/bin/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,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
ACTIONS_RUNNER_DIRECTORY="/actions-runner" | ||
EPHEMERAL="${EPHEMERAL:-"false"}" | ||
|
||
echo "Runner parameters:" | ||
echo " Repository: ${GITHUB_REPOSITORY}" | ||
echo " Runner Name: $(hostname)" | ||
echo " Runner Labels: ${RUNNER_LABELS}" | ||
|
||
echo "Obtaining registration token" | ||
getRegistrationToken=$( | ||
curl \ | ||
--silent \ | ||
--location \ | ||
--request "POST" \ | ||
--header "X-GitHub-Api-Version: 2022-11-28" \ | ||
--header "Authorization: Bearer ${GH_AUTH_TOKEN}" \ | ||
https://api.github.com/repos/"${GITHUB_REPOSITORY}"/actions/runners/registration-token | jq -r '.token' | ||
) | ||
export getRegistrationToken | ||
|
||
echo "Checking if registration token exists" | ||
if [[ -z "${getRegistrationToken}" ]]; then | ||
echo "Failed to obtain registration token" | ||
exit 1 | ||
else | ||
echo "Registration token obtained successfully" | ||
REPO_TOKEN="${getRegistrationToken}" | ||
fi | ||
|
||
if [[ "${EPHEMERAL}" == "true" ]]; then | ||
EPHEMERAL_FLAG="--ephemeral" | ||
trap 'echo "Shutting down runner"; exit' SIGINT SIGQUIT SIGTERM INT TERM QUIT | ||
else | ||
EPHEMERAL_FLAG="" | ||
fi | ||
|
||
echo "Checking the runner" | ||
bash "${ACTIONS_RUNNER_DIRECTORY}/config.sh" --check --url "https://github.com/${GITHUB_REPOSITORY}" --pat ${GH_AUTH_TOKEN} | ||
|
||
echo "Configuring runner" | ||
bash "${ACTIONS_RUNNER_DIRECTORY}/config.sh" ${EPHEMERAL_FLAG} \ | ||
--unattended \ | ||
--disableupdate \ | ||
--url "https://github.com/${GITHUB_REPOSITORY}" \ | ||
--token "${REPO_TOKEN}" \ | ||
--name "$(hostname)" \ | ||
--labels "${RUNNER_LABELS}" | ||
|
||
echo "Setting the 'ready' flag for Kubernetes liveness probe" | ||
touch /tmp/runner.ready | ||
|
||
echo "Starting runner" | ||
bash "${ACTIONS_RUNNER_DIRECTORY}/run.sh" |