Skip to content

Commit 93d6cd6

Browse files
committed
Split shell scripts based on usage
1 parent f8c1c36 commit 93d6cd6

File tree

8 files changed

+75
-68
lines changed

8 files changed

+75
-68
lines changed

.github/workflows/test-runner.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ jobs:
2222
- name: Verify 'python'
2323
run: python -V
2424
shell: bash
25-
- name: Verify 'rust'
25+
- name: Verify 'rustc'
2626
run: rustc --version
2727
shell: bash
28+
- name: Verify 'cargo'
29+
run: cargo --version
30+
shell: bash
31+
- name: Verify 'rustfmt'
32+
run: rustfmt --version
33+
shell: bash
2834
- name: Verify 'go'
2935
run: go version
3036
shell: bash

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
# IntelIJ
12
.DS_Store
23
.idea
34

4-
#Docker variables
5+
# Docker variables
56
*.env
67
.env
78

8-
#VSCODE
9+
# VSCode
910
.vscode/*
10-
11-
# Built Visual Studio Code Extensions
12-
*.vsix

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN apt-get update -y && \
1616
apt-get upgrade -y && \
1717
useradd -m docker
1818

19-
# install the packages and dependencies along with jq so we can parse JSON (add additional packages as necessary)
19+
# Install the packages and dependencies
2020
RUN apt-get install -y --no-install-recommends \
2121
curl \
2222
wget \
@@ -32,7 +32,7 @@ RUN apt-get install -y --no-install-recommends \
3232
python3.10-dev \
3333
python3-pip \
3434
nodejs \
35-
npm \
35+
npm \
3636
golang-go
3737

3838
# Create a symbolic link for python pointing to python3.10
@@ -52,7 +52,9 @@ RUN chown -R docker ~docker && /home/docker/actions-runner/bin/installdependenci
5252

5353
# Add start script and make it executable
5454
ADD scripts/start.sh start.sh
55+
ADD scripts/detector.sh detector.sh
5556
RUN chmod +x start.sh
57+
RUN chmod +x detector.sh
5658

5759
# Set the user to "docker" so all subsequent commands are run as the docker user
5860
USER docker

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Build a self-hosted GitHub action runner as an Ubuntu linux container
55
### Build
66

77
```shell
8-
docker build --build-arg RUNNER_VERSION=2.319.1 -t runner .
8+
docker build -t runner .
99
```
1010

1111
### Run

docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ services:
77
args:
88
RUNNER_VERSION: '2.319.1'
99
restart: always
10-
env_file:
11-
- './.env'
10+
env_file: '.env'
1211
environment:
1312
GIT_TOKEN: ${GIT_TOKEN}
1413
GIT_OWNER: ${GIT_OWNER}
@@ -17,5 +16,5 @@ services:
1716
RUNNER_NAME: ${RUNNER_NAME}
1817
WORK_DIR: ${WORK_DIR}
1918
LABELS: ${LABELS}
20-
container_name: docker-github-runner-linux
19+
container_name: github-runner-linux
2120
working_dir: /home/docker

samples/docker-compose.yml

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

scripts/detector.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# NOTE: `uname -m` is more accurate and universal than `arch`
4+
# See https://en.wikipedia.org/wiki/Uname
5+
unamem="$(uname -m)"
6+
case $unamem in
7+
*aarch64*|arm64)
8+
architecture="arm64";;
9+
*64*)
10+
architecture="amd64";;
11+
*86*)
12+
architecture="386";;
13+
*armv5*)
14+
architecture="armv5";;
15+
*armv6*)
16+
architecture="armv6";;
17+
*armv7*)
18+
architecture="armv7";;
19+
*)
20+
echo "Unknown architecture: $unamem"
21+
;;
22+
esac
23+
export architecture="${architecture}"
24+
25+
unameu="$(tr '[:lower:]' '[:upper:]' <<< "$(uname)")"
26+
if [[ $unameu == *DARWIN* ]]; then
27+
os_name="darwin"
28+
elif [[ $unameu == *LINUX* ]]; then
29+
os_name="linux"
30+
elif [[ $unameu == *FREEBSD* ]]; then
31+
os_name="freebsd"
32+
elif [[ $unameu == *NETBSD* ]]; then
33+
os_name="netbsd"
34+
elif [[ $unameu == *OPENBSD* ]]; then
35+
os_name="openbsd"
36+
elif [[ $unameu == *WIN* || $unameu == MSYS* ]]; then
37+
# Should catch cygwin
38+
os_name="windows"
39+
else
40+
echo "Unknown OS: $(uname)"
41+
fi
42+
export os_name="${os_name}"

scripts/start.sh

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,26 @@
11
#!/bin/bash
2+
# 'set -e' stops the execution of a script if a command or pipeline has an error.
3+
# This is the opposite of the default shell behaviour, which is to ignore errors in scripts.
4+
set -e
25

3-
# NOTE: `uname -m` is more accurate and universal than `arch`
4-
# See https://en.wikipedia.org/wiki/Uname
5-
unamem="$(uname -m)"
6-
case $unamem in
7-
*aarch64*|arm64)
8-
architecture="arm64";;
9-
*64*)
10-
architecture="amd64";;
11-
*86*)
12-
architecture="386";;
13-
*armv5*)
14-
architecture="armv5";;
15-
*armv6*)
16-
architecture="armv6";;
17-
*armv7*)
18-
architecture="armv7";;
19-
*)
20-
echo "Unknown architecture: $unamem"
21-
;;
22-
esac
6+
# Set defaults
7+
os_name=""
8+
architecture=""
239

24-
unameu="$(tr '[:lower:]' '[:upper:]' <<< "$(uname)")"
25-
if [[ $unameu == *DARWIN* ]]; then
26-
os_name="darwin"
27-
elif [[ $unameu == *LINUX* ]]; then
28-
os_name="linux"
29-
elif [[ $unameu == *FREEBSD* ]]; then
30-
os_name="freebsd"
31-
elif [[ $unameu == *NETBSD* ]]; then
32-
os_name="netbsd"
33-
elif [[ $unameu == *OPENBSD* ]]; then
34-
os_name="openbsd"
35-
elif [[ $unameu == *WIN* || $unameu == MSYS* ]]; then
36-
# Should catch cygwin
37-
os_name="windows"
38-
else
39-
echo "Unknown OS: $(uname)"
40-
fi
10+
# Get to the current directory
11+
current_dir="$(dirname "$(realpath "$0")")"
12+
source "${current_dir}/detector.sh"
4113

4214
instance_id() {
4315
# Use randomly generated instance IDs (AWS format) as default runner names
4416
letters=$(tr -dc '[:lower:]' < /dev/urandom | head -c 4)
4517
digits=$(tr -dc '0-9' < /dev/urandom | head -c 12)
4618
eid=$(echo "$letters$digits" | fold -w1 | shuf | tr -d '\n')
47-
echo "0$eid"
19+
echo "i-0$eid"
4820
}
4921

5022
# Env vars (docker-compose.yml)
51-
RUNNER_NAME="${RUNNER_NAME:-"i-$(instance_id)"}"
23+
RUNNER_NAME="${RUNNER_NAME:-"$(instance_id)"}"
5224
RUNNER_GROUP="${RUNNER_GROUP:-"default"}"
5325
WORK_DIR="${WORK_DIR:-"_work"}"
5426
LABELS="${LABELS:-"docker-node,$os_name-$architecture"}"
@@ -57,7 +29,7 @@ repo_level_runner() {
5729
# https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository
5830
REG_TOKEN=$(curl -sX POST \
5931
-H "Accept: application/vnd.github.v3+json" \
60-
-H "Authorization: token ${GIT_TOKEN}" \
32+
-H "Authorization: Bearer ${GIT_TOKEN}" \
6133
"https://api.github.com/repos/${GIT_OWNER}/${GIT_REPOSITORY}/actions/runners/registration-token" \
6234
| jq .token --raw-output)
6335
cd "/home/docker/actions-runner" || exit 1
@@ -76,7 +48,7 @@ org_level_runner() {
7648
# https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-an-organization
7749
REG_TOKEN=$(curl -sX POST \
7850
-H "Accept: application/vnd.github.v3+json" \
79-
-H "Authorization: token ${GIT_TOKEN}" \
51+
-H "Authorization: Bearer ${GIT_TOKEN}" \
8052
"https://api.github.com/orgs/${GIT_OWNER}/actions/runners/registration-token" \
8153
| jq .token --raw-output)
8254
cd "/home/docker/actions-runner" || exit 1
@@ -90,10 +62,10 @@ org_level_runner() {
9062
}
9163

9264
if [ -n "${GIT_REPOSITORY}" ]; then
93-
echo "Creating repository level self-hosted runner ['${RUNNER_NAME}'] for ${GIT_REPOSITORY}"
65+
echo "Creating a repository level self-hosted runner ['${RUNNER_NAME}'] for ${GIT_REPOSITORY}"
9466
repo_level_runner
9567
else
96-
echo "Creating organization level self-hosted runner '${RUNNER_NAME}'"
68+
echo "Creating an organization level self-hosted runner '${RUNNER_NAME}'"
9769
org_level_runner
9870
fi
9971

@@ -105,4 +77,4 @@ cleanup() {
10577
trap 'cleanup; exit 130' INT
10678
trap 'cleanup; exit 143' TERM
10779

108-
./run.sh & wait $!
80+
./run.sh & wait $!

0 commit comments

Comments
 (0)