Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit b4a6d21

Browse files
committed
add helper-scripts
1 parent 65d0176 commit b4a6d21

File tree

6 files changed

+188
-91
lines changed

6 files changed

+188
-91
lines changed

Dockerfile

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
FROM ubuntu:20.04
22

3-
COPY export-aarch-infos.sh /export-aarch-infos.sh
4-
RUN chmod +x /export-aarch-infos.sh
5-
63
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG PACKAGES="libffi-dev libicu-dev build-essential libssl-dev ca-certificates jq sed grep git curl wget zip"
75

86
ENV USERNAME="runner"
97
ENV RUNNER_HOME="/home/${USERNAME}/runner"
10-
ENV GH_WORKDIR="/home/${USERNAME}"
8+
9+
ENV GH_RUNNER_WORKDIR="/home/${USERNAME}"
10+
ENV GH_KANIKO_WORKDIR="/kaniko/workspace"
1111

1212
# https://github.com/actions/runner/releases
1313
ENV GH_RUNNER_VERSION=2.289.1
1414
ENV GH_RUNNER_LABELS=ubuntu-20.04
1515

1616
ENV AWESOME_CI_VERSION 0.11.1
1717

18+
# making nessecarry directories
19+
RUN mkdir /helper-scripts \
20+
&& mkdir -p /kaniko/workspace
21+
22+
# Copy image helper scripts
23+
COPY ./helper-scripts/gh-entrypoint.sh /helper-scripts/gh-entrypoint.sh
24+
COPY ./helper-scripts/kaniko-wrapper.sh /helper-scripts/kaniko-wrapper.sh
25+
COPY ./helper-scripts/translate-aarch.sh /helper-scripts/translate-aarch.sh
26+
27+
RUN chmod -R 755 /helper-scripts
28+
1829
# install packages along with jq so we can parse JSON
1930
# add additional packages as necessary
20-
ARG PACKAGES="libffi-dev libicu-dev build-essential libssl-dev ca-certificates jq sed grep git curl wget zip"
21-
2231
RUN apt-get update \
2332
&& apt-get install -y ${PACKAGES} \
2433
&& rm -rf /var/lib/apt/lists/* \
2534
&& apt-get clean
2635

2736
# install awesoeme ci
28-
RUN export ARCH=$(/export-aarch-infos.sh a-short) \
29-
&& curl -L -O https://github.com/eksrvb/awesome-ci/releases/download/${AWESOME_CI_VERSION}/awesome-ci_${AWESOME_CI_VERSION}_${ARCH} \
37+
RUN export ARCH=$(/helper-scripts/translate-aarch.sh a-short) \
38+
&& curl -L -O https://github.com/fullstack-devops/awesome-ci/releases/download/${AWESOME_CI_VERSION}/awesome-ci_${AWESOME_CI_VERSION}_${ARCH} \
3039
&& mv awesome-ci_${AWESOME_CI_VERSION}_${ARCH} /usr/local/src/awesome-ci_${AWESOME_CI_VERSION}_${ARCH} \
3140
&& chmod +x /usr/local/src/awesome-ci_${AWESOME_CI_VERSION}_${ARCH} \
3241
&& ln -s /usr/local/src/awesome-ci_${AWESOME_CI_VERSION}_${ARCH} /usr/local/bin/
@@ -40,23 +49,17 @@ RUN useradd -m $USERNAME \
4049
&& mkdir -p ${RUNNER_HOME}
4150

4251
# Install github runner
43-
RUN export ARCH=$(/export-aarch-infos.sh x-short) \
52+
RUN export ARCH=$(/helper-scripts/translate-aarch.sh x-short) \
4453
&& curl -L -O https://github.com/actions/runner/releases/download/v${GH_RUNNER_VERSION}/actions-runner-linux-${ARCH}-${GH_RUNNER_VERSION}.tar.gz \
4554
&& tar -zxf actions-runner-linux-x64-${GH_RUNNER_VERSION}.tar.gz \
4655
&& rm -f actions-runner-linux-x64-${GH_RUNNER_VERSION}.tar.gz \
4756
&& ./bin/installdependencies.sh \
4857
&& cd ./bin \
4958
&& apt-get clean
5059

51-
# copy over the start script
52-
COPY gh-entrypoint.sh /gh-entrypoint.sh
53-
# make the script executable
54-
RUN chmod +x /gh-entrypoint.sh
55-
5660
RUN chown -R $USERNAME /home/${USERNAME}
57-
RUN chown -R $USERNAME /gh-entrypoint.sh
5861

5962
# set the entrypoint to the entrypoint.sh script
60-
ENTRYPOINT ["/gh-entrypoint.sh"]
63+
ENTRYPOINT ["/helper-scripts/gh-entrypoint.sh"]
6164

6265
USER $USERNAME

README.md

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,80 @@ Base Image for github runner images in repo @fullstack-devops/github-runner. Can
99

1010
| Variable | Type | Description |
1111
|-------------------|--------|-------------------------------------------------------------------------------------------------------------------|
12-
| `GH_ORGANIZATION` | string | Points to the GitHub Organisation where the runner should be installed |
12+
| `GH_ORG` | string | Points to the GitHub Organisation where the runner should be installed |
1313
| `GH_ACCESS_TOKEN` | string | Developer Token vor the GitHub Organisation<br> This Token can be personal and is onlv needed during installation |
1414

1515
### Optional environmental variables
1616

1717
For the helm values see the [values.yaml](helm/values.yaml), section `envValues`
1818

19-
| Variable | Type | Default | Description |
20-
|--------------|--------|--------------------------|----------------------------------------------------------------------|
21-
| `GH_URL` | string | `https://github.com` | For GitHub Enterprise support |
22-
| `GH_API_URL` | string | `https://api.github.com` | For GitHub Enterprise support eg.: `https://git.example.com/api/v3/` |
19+
| Variable | Type | Default | Description |
20+
|-------------------|--------|--------------------------|----------------------------------------------------------------------|
21+
| `GH_URL` | string | `https://github.com` | For GitHub Enterprise support |
22+
| `GH_API_ENDPOINT` | string | `https://api.github.com` | For GitHub Enterprise support eg.: `https://git.example.com/api/v3/` |
23+
| `GH_REPO` | string | | installing a runner to a spezific repository |
24+
25+
---
26+
27+
## Examples
28+
29+
### docker or podman
30+
31+
If you are using `docker` or `podman` the options and commands are basically the same.
32+
33+
Run registerd to an Organisation:
34+
```bash
35+
podman run -e GH_ORG=fullstack-devops -e GH_ACCESS_TOKEN=ghp_**** github-runner-base:latest
36+
```
37+
38+
Run registerd to an Organisation and Repo:
39+
```bash
40+
podman run -e GH_ORG=fullstack-devops -e GH_REPO=github-runner-testing -e GH_ACCESS_TOKEN=ghp_**** github-runner-base:latest
41+
```
42+
43+
> Replace the `ghp_****` with your own valid personal access token
44+
45+
### docker-compose
46+
47+
```yaml
48+
version: "3"
49+
50+
services:
51+
github-runner:
52+
image: github-runner-base:latest
53+
environment:
54+
GH_ORG: fullstack-devops
55+
GH_ACCESS_TOKEN: ghp_****
56+
```
57+
58+
Build images with kaniko:
59+
```yaml
60+
version: "3"
61+
62+
volumes:
63+
kaniko_workspace:
64+
driver: local
65+
66+
services:
67+
github-action-runner:
68+
image: github-action-runner:base-latest
69+
environment:
70+
GH_ORG: fullstack-devops
71+
GH_ACCESS_TOKEN: ghp_****
72+
volumes:
73+
- kaniko_workspace:/kaniko/workspace
74+
75+
github-action-runner-kaniko:
76+
image: github-action-runner:kaniko-sidecar-latest
77+
volumes:
78+
- kaniko_workspace:/kaniko/workspace
79+
80+
```
81+
82+
### kubernetes pod
83+
84+
tbd
85+
86+
### helm
87+
88+
tbd

gh-entrypoint.sh

Lines changed: 0 additions & 70 deletions
This file was deleted.

helper-scripts/gh-entrypoint.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# connection details
4+
last_char="${GH_URL: -1}"
5+
[[ $last_char == "/" ]] && GH_URL="${GH_URL::-1}"
6+
readonly _GH_URL="${GH_URL:-https://github.com}"
7+
8+
last_char="${GH_API_ENDPOINT: -1}"
9+
[[ $last_char == "/" ]] && GH_API_ENDPOINT="${GH_API_ENDPOINT::-1}"
10+
readonly _GH_API_ENDPOINT="${GH_API_ENDPOINT:-https://api.github.com}"
11+
12+
# Org/ Repo details
13+
if [ -z "$GH_ORG" ]; then
14+
echo "Please provide Organisation detail by setting GH_ORG"
15+
exit 255
16+
fi
17+
if [ -z "$GH_REPO" ]; then
18+
readonly RUNNER_URL="${_GH_URL}/${GH_ORG}"
19+
readonly RUNNER_REG_TOKEN_URL="${_GH_API_ENDPOINT}/orgs/${GH_ORG}/actions/runners/registration-token"
20+
else
21+
readonly RUNNER_URL="${_GH_URL}/${GH_ORG}/${GH_REPO}"
22+
readonly RUNNER_REG_TOKEN_URL="${_GH_API_ENDPOINT}/repos/${GH_ORG}/${GH_REPO}/actions/runners/registration-token"
23+
fi
24+
25+
# access details
26+
if [ ! -z "$RUNNER_TOKEN" ]; then
27+
readonly REG_TOKEN=$RUNNER_TOKEN
28+
unset RUNNER_TOKEN
29+
elif [ ! -z $GH_ACCESS_TOKEN ]; then
30+
readonly REG_TOKEN=$(curl -s -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GH_ACCESS_TOKEN" $RUNNER_REG_TOKEN_URL | jq .token --raw-output)
31+
unset GH_ACCESS_TOKEN
32+
else
33+
echo "Please provide one of the Environment Variables:"
34+
echo "GH_ACCESS_TOKEN, RUNNER_TOKEN"
35+
exit 255
36+
fi
37+
38+
if [ -z ${RUNNER_HOME} ]; then
39+
echo "Environment variable 'RUNNER_HOME' is not set"
40+
exit 1
41+
fi
42+
43+
if [ "$KANIKO_ENABLED" == "1" ]; then
44+
readonly GH_WORKDIR=$GH_KANIKO_WORKDIR
45+
echo "Build container via Kaniko: enabled"
46+
else
47+
readonly GH_WORKDIR=$GH_RUNNER_WORKDIR
48+
echo "Build container via Kaniko: disabled"
49+
fi
50+
51+
echo "Connecting runner to: $RUNNER_URL"
52+
echo "Individual Runner Name: $HOSTNAME"
53+
echo "Runner Home: $RUNNER_HOME"
54+
55+
${RUNNER_HOME}/config.sh \
56+
--name $HOSTNAME \
57+
--token $REG_TOKEN \
58+
--work $GH_WORKDIR \
59+
--url "$RUNNER_URL" \
60+
--labels $GH_RUNNER_LABELS \
61+
--unattended \
62+
--replace
63+
echo "Runner configured"
64+
65+
cleanup() {
66+
echo "Removing runner..."
67+
${RUNNER_HOME}/config.sh remove --token ${REG_TOKEN}
68+
exit 1
69+
}
70+
71+
trap cleanup 0
72+
${RUNNER_HOME}/run.sh $RUNNER_ARGS &
73+
74+
echo $! >/tmp/runner_pid
75+
wait $!

helper-scripts/kaniko-wrapper.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
logpipe=/kaniko/workspace/log
3+
returnpipe=/kaniko/workspace/returncode
4+
if [ -p $logpipe ]; then
5+
cat 0<> "$logpipe" <"$logpipe"
6+
rm $logpipe
7+
echo "Warning: removed stale communication file with kaniko"
8+
fi
9+
if [ -p $returnpipe ]; then
10+
cat 0<> "$returnpipe" <"$returnpipe"
11+
rm $returnpipe
12+
echo "Warning: removed stale communication returncode file with kaniko"
13+
fi
14+
echo "cd ${PWD}" > /kaniko/workspace/start.sh
15+
echo "/kaniko/executor --cleanup $@" >> /kaniko/workspace/start.sh
16+
mkfifo $returnpipe
17+
mkfifo $logpipe
18+
cat $logpipe
19+
rm $logpipe
20+
returncode=`cat $returnpipe | tr -d "\n"`
21+
rm $returnpipe
22+
echo ${returncode}
23+
exit ${returncode}
File renamed without changes.

0 commit comments

Comments
 (0)