From 7a6fe7c97700b27adbd001df1a34256820c92a0f Mon Sep 17 00:00:00 2001
From: istmxrein <maximilian.reinheimer@stud.h-da.de>
Date: Tue, 13 Sep 2022 12:00:50 +0200
Subject: [PATCH] refactor Dockerfile

- use python docker image
- download gitlab-runner from binary
---
 Dockerfile                | 28 ++++++++++++++++++++++++++++
 start.sh => entrypoint.sh | 10 +++++-----
 2 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 Dockerfile
 rename start.sh => entrypoint.sh (57%)

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..21e50aa
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,28 @@
+FROM python:3-slim
+
+ARG GITLAB_RUNNER_VERSION=v15.2.1
+ENV GITLAB_RUNNER_URL="https://gitlab-runner-downloads.s3.amazonaws.com/${GITLAB_RUNNER_VERSION}/binaries/gitlab-runner-linux-amd64"
+
+LABEL maintainer="Max Reinheimer <max@reinheimer.dev>" \
+      io.openshift.tags="gitlab,ci,runner" \
+      name="openstack-gitlab-runner" \
+      io.k8s.display-name="GitLab runner" \
+      summary="GitLab runner" \
+      description="A GitLab runner image with openstack custom executor." \
+      io.k8s.description="A GitLab runner image with openstack custom executor."
+
+COPY cleanup.py env.py config.sh prepare.py run.py requirements.txt /data/
+COPY entrypoint.sh /usr/bin/entrypoint
+
+RUN apt-get update && apt-get -y install curl dumb-init gcc libffi-dev && \
+    curl -L --output /usr/bin/gitlab-runner "${GITLAB_RUNNER_URL}" && \
+    pip3 install -r /data/requirements.txt && \
+    chmod +x /data/* /usr/bin/entrypoint /usr/bin/gitlab-runner && \
+    useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash && \
+    apt-get remove -y gcc curl && apt autoremove && apt-get clean
+
+USER gitlab-runner
+WORKDIR /data
+
+ENTRYPOINT ["dumb-init", "--"]
+CMD ["entrypoint"]
diff --git a/start.sh b/entrypoint.sh
similarity index 57%
rename from start.sh
rename to entrypoint.sh
index 4cce533..9fba9a8 100644
--- a/start.sh
+++ b/entrypoint.sh
@@ -16,13 +16,13 @@ echo "$PRIVATE_KEY" > "$HOME"/priv_key
 
 gitlab-runner register --non-interactive \
                        --executor=custom \
-                       --custom-config-exec="$HOME"/config.sh \
-                       --custom-prepare-exec="$HOME"/prepare.py \
-                       --custom-run-exec="$HOME"/run.py \
-                       --custom-cleanup-exec="$HOME"/cleanup.py
+                       --custom-config-exec=/data/config.sh \
+                       --custom-prepare-exec=/data/prepare.py \
+                       --custom-run-exec=/data/run.py \
+                       --custom-cleanup-exec=/data/cleanup.py
 
 if [[ "$CONCURRENT" ]]; then
-    sed -i "s/concurrent = .*/concurrent = $CONCURRENT/g" "$HOME"/.gitlab-runner/config.toml
+    sed -i "s/concurrent = .*/concurrent = $CONCURRENT/g" $HOME/.gitlab-runner/config.toml
 fi
 
 gitlab-runner run
-- 
GitLab