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

Commit 1d6e2da

Browse files
authored
Merge pull request #1 from fullstack-devops/feature/init
working base
2 parents 89ada85 + b45d4b5 commit 1d6e2da

File tree

7 files changed

+257
-1
lines changed

7 files changed

+257
-1
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "docker" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "daily"

.github/workflows/build-pr.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build PR
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
generate_infos:
8+
uses: fullstack-devops/actions/.github/workflows/generate-build-infos.yml@main
9+
secrets:
10+
token: ${{ secrets.GITHUB_TOKEN }}
11+
12+
build:
13+
runs-on: ubuntu-latest
14+
needs: generate_infos
15+
steps:
16+
- name: Check out the repo
17+
uses: actions/checkout@v2
18+
19+
- name: Login to GitHub Container Registry
20+
uses: docker/login-action@v1
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.repository_owner }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v1
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v1
30+
31+
- name: Build github-runner-base
32+
uses: docker/build-push-action@v2
33+
with:
34+
context: ./
35+
push: false
36+
tags: |
37+
ghcr.io/${{ github.repository_owner }}/github-runner-base:latest
38+
ghcr.io/${{ github.repository_owner }}/github-runner-base:${{needs.generate_infos.outputs.version}}

.github/workflows/create-release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Create Release
2+
3+
concurrency:
4+
group: ci-${{ github.repository }}-release
5+
cancel-in-progress: false
6+
7+
on:
8+
push:
9+
branches:
10+
- "main"
11+
12+
jobs:
13+
create_release:
14+
uses: fullstack-devops/actions/.github/workflows/create-release.yml@main
15+
secrets:
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
18+
build:
19+
runs-on: ubuntu-latest
20+
needs: create_release
21+
steps:
22+
- name: Check out the repo
23+
uses: actions/checkout@v2
24+
25+
- name: Login to GitHub Container Registry
26+
uses: docker/login-action@v1
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.repository_owner }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v1
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@v1
36+
37+
- name: Build and push github-runner-base
38+
uses: docker/build-push-action@v2
39+
with:
40+
context: ./
41+
push: true
42+
tags: |
43+
ghcr.io/${{ github.repository_owner }}/github-runner-base:latest
44+
ghcr.io/${{ github.repository_owner }}/github-runner-base:${{needs.create_release.outputs.version}}

Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
FROM ubuntu:20.04
2+
3+
COPY export-aarch-infos.sh /export-aarch-infos.sh
4+
RUN chmod +x /export-aarch-infos.sh
5+
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
8+
ENV USERNAME="runner"
9+
ENV RUNNER_HOME="/home/${USERNAME}/runner"
10+
ENV GH_WORKDIR="/home/${USERNAME}"
11+
12+
# https://github.com/actions/runner/releases
13+
ENV GH_RUNNER_VERSION=2.289.1
14+
ENV GH_RUNNER_LABELS=ubuntu-20.04
15+
16+
ENV AWESOME_CI_VERSION 0.11.1
17+
18+
# install packages along with jq so we can parse JSON
19+
# 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+
22+
RUN apt-get update \
23+
&& apt-get install -y ${PACKAGES} \
24+
&& rm -rf /var/lib/apt/lists/* \
25+
&& apt-get clean
26+
27+
# 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} \
30+
&& mv awesome-ci_${AWESOME_CI_VERSION}_${ARCH} /usr/local/src/awesome-ci_${AWESOME_CI_VERSION}_${ARCH} \
31+
&& chmod +x /usr/local/src/awesome-ci_${AWESOME_CI_VERSION}_${ARCH} \
32+
&& ln -s /usr/local/src/awesome-ci_${AWESOME_CI_VERSION}_${ARCH} /usr/local/bin/
33+
34+
WORKDIR /home/${USERNAME}/runner
35+
36+
# add a non-sudo user
37+
RUN useradd -m $USERNAME \
38+
&& usermod -aG sudo $USERNAME \
39+
&& chown -R $USERNAME /home/${USERNAME} \
40+
&& mkdir -p ${RUNNER_HOME}
41+
42+
# Install github runner
43+
RUN export ARCH=$(/export-aarch-infos.sh x-short) \
44+
&& curl -L -O https://github.com/actions/runner/releases/download/v${GH_RUNNER_VERSION}/actions-runner-linux-${ARCH}-${GH_RUNNER_VERSION}.tar.gz \
45+
&& tar -zxf actions-runner-linux-x64-${GH_RUNNER_VERSION}.tar.gz \
46+
&& rm -f actions-runner-linux-x64-${GH_RUNNER_VERSION}.tar.gz \
47+
&& ./bin/installdependencies.sh \
48+
&& cd ./bin \
49+
&& apt-get clean
50+
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+
56+
RUN chown -R $USERNAME /home/${USERNAME}
57+
RUN chown -R $USERNAME /gh-entrypoint.sh
58+
59+
# set the entrypoint to the entrypoint.sh script
60+
ENTRYPOINT ["/gh-entrypoint.sh"]
61+
62+
USER $USERNAME

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright [2022] [eksrha]
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

export-aarch-infos.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
# https://en.wikipedia.org/wiki/Uname#Examples
3+
4+
transform_aarch() {
5+
definition=$1
6+
return_value="not-defined"
7+
case "$(uname -i)" in
8+
# AMD64 or x86-64 or x64
9+
amd64|x86_64|x64)
10+
case $definition in
11+
x-long) return_value="x86-64";;
12+
x-short) return_value="x64";;
13+
a-long) return_value="amd64";;
14+
a-short) return_value="amd64";;
15+
*) return_value="not-defined";;
16+
esac
17+
;;
18+
x86)
19+
case $definition in
20+
x-long) return_value="x86";;
21+
x-short) return_value="x86";;
22+
a-long) return_value="amd32";;
23+
a-short) return_value="amd";;
24+
*) return_value="not-defined";;
25+
esac
26+
;;
27+
esac
28+
echo -n "$return_value"
29+
}
30+
31+
echo $(transform_aarch $1)

gh-entrypoint.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
if [ -z ${GH_ACCESS_TOKEN} ];
4+
then
5+
echo "Environment variable 'GH_ACCESS_TOKEN' is not set"
6+
exit 1
7+
fi
8+
9+
if [ -z ${GH_URL} ];
10+
then
11+
echo "Environment variable 'GH_URL' is not set"
12+
echo "Using public github.com!"
13+
GH_URL="https://github.com/"
14+
fi
15+
### Add trailing slash to GH_URL if needed
16+
last_char="${GH_URL: -1}"
17+
[[ $last_char != "/" ]] && GH_URL="$GH_URL/"; :
18+
19+
if [ -z ${GH_API_URL} ];
20+
then
21+
echo "Environment variable 'GH_API_URL' is not set"
22+
echo "Using public github.com!"
23+
GH_API_URL="https://api.github.com/"
24+
fi
25+
### Add trailing slash to GH_API_URL if needed
26+
last_char="${GH_API_URL: -1}"
27+
[[ $last_char != "/" ]] && GH_API_URL="$GH_API_URL/"; :
28+
29+
ACCESS_TOKEN=$GH_ACCESS_TOKEN
30+
unset GH_ACCESS_TOKEN
31+
32+
if [ -z ${GH_ORGANIZATION} ];
33+
then
34+
echo "Environment variable 'GH_ORGANIZATION' is not set"
35+
exit 1
36+
fi
37+
38+
if [ -z ${RUNNER_HOME} ];
39+
then
40+
echo "Environment variable 'RUNNER_HOME' is not set"
41+
exit 1
42+
fi
43+
44+
REG_TOKEN=$(curl -s -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $ACCESS_TOKEN" ${GH_API_URL}orgs/${GH_ORGANIZATION}/actions/runners/registration-token | jq .token --raw-output)
45+
46+
echo "Individual Runner Name: $HOSTNAME"
47+
echo "Runner Home: $RUNNER_HOME"
48+
49+
${RUNNER_HOME}/config.sh \
50+
--name ${HOSTNAME} \
51+
--token ${REG_TOKEN} \
52+
--work ${GH_WORKDIR} \
53+
--url "${GH_URL}${GH_ORGANIZATION}" \
54+
--labels ${GH_RUNNER_LABELS} \
55+
--unattended \
56+
--replace
57+
echo "Runner configured"
58+
59+
cleanup() {
60+
echo "Removing runner..."
61+
REG_TOKEN=$(curl -s -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${ACCESS_TOKEN}" ${GH_API_URL}orgs/${GH_ORGANIZATION}/actions/runners/registration-token | jq .token --raw-output)
62+
${RUNNER_HOME}/config.sh remove --token ${REG_TOKEN}
63+
exit 1
64+
}
65+
66+
trap cleanup 0
67+
${RUNNER_HOME}/run.sh &
68+
69+
echo $! > /tmp/runner_pid
70+
wait $!

0 commit comments

Comments
 (0)