From 4e0b64e5068c0a9c7c23dd313e0a975fa2a53c52 Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 15 Aug 2022 12:19:43 +0200 Subject: [PATCH] Fix env variables --- Dockerfile | 4 ++++ entrypoint-wrapper | 12 ++++++++++++ parse-database-url | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100755 entrypoint-wrapper create mode 100755 parse-database-url diff --git a/Dockerfile b/Dockerfile index 28bf7b1..9b4cb80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,6 @@ FROM gitea/gitea:1.16.9 +COPY entrypoint-wrapper parse-database-url /usr/bin/ +RUN chmod 755 /usr/bin/entrypoint-wrapper /usr/bin/parse-database-url + +ENTRYPOINT ["/usr/bin/entrypoint-wrapper"] diff --git a/entrypoint-wrapper b/entrypoint-wrapper new file mode 100755 index 0000000..9cb514f --- /dev/null +++ b/entrypoint-wrapper @@ -0,0 +1,12 @@ +#!/bin/sh +# vim: set ts=2 sw=2 et ft=bash: + +eval "$(/usr/bin/parse-database-url "${DATABASE_URL:-}" GITEA__database__ |sed -e 's/^/export /')" + +# Rename variables +GITEA__database__DB_TYPE="$GITEA__database__PROTO" +GITEA__database__PASSWD="$GITEA__database__PASS" +export GITEA__database__DB_TYPE +export GITEA__database__PASSWD + +exec /usr/bin/entrypoint "$@" diff --git a/parse-database-url b/parse-database-url new file mode 100755 index 0000000..b0e87a0 --- /dev/null +++ b/parse-database-url @@ -0,0 +1,35 @@ +#!/bin/sh +# Referenced and tweaked from http://stackoverflow.com/questions/6174220/parse-url-in-shell-script#6174447 + +url="$1" +prefix="$2" +proto="$(echo "$url" | grep :// | sed -e 's,^\(.*\)://.*,\1,g')" +# remove the protocol +workurl="$(echo "$url" |sed -e "s,^$proto://,,")" +# extract the user (if any) +userpass="$(echo "$workurl" | grep @ | cut -d@ -f1)" +pass="$(echo "$userpass"| grep : | cut -d: -f2)" +if [ -n "$pass" ]; then + user="$(echo "$userpass" | grep : | cut -d: -f1)" +else + user="$userpass" +fi + +# extract the host +hostport="$(echo "$workurl" |sed -e "s,$userpass@,," | cut -d/ -f1)" +# by request - try to extract the port +port="$(echo "$hostport" | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')" +host="$(echo "$hostport" | cut -d: -f1)" +# extract the path (if any) +path="/$(echo "$workurl" | grep / | cut -d/ -f2-)" +name="$(echo "$workurl" | grep / | cut -d/ -f2-)" + +echo "${prefix}_URL=\"$url\"" +echo "${prefix}_PROTO=\"$proto\"" +echo "${prefix}_USER=\"$user\"" +echo "${prefix}_PASS=\"$pass\"" +echo "${prefix}_HOST=\"$host\"" +echo "${prefix}_PORT=\"$port\"" +echo "${prefix}_PATH=\"$path\"" +echo "${prefix}_NAME=\"$name\"" +