From 9fdbcd56cf0c817dbd3e6d2fdf30e2486e3c1031 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 5 May 2020 23:31:01 +0200 Subject: [PATCH] Add docker run script to change api url on startup --- Dockerfile | 9 +++++---- run.sh | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100755 run.sh diff --git a/Dockerfile b/Dockerfile index d7a7771371..cd090961b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,7 @@ COPY . ./ RUN \ # Build the frontend yarn install --frozen-lockfile && \ - yarn run build && \ - # Override config - sed -i 's/http\:\/\/localhost\:3456\/api\/v1/\/api\/v1/g' dist/index.html + yarn run build # Stage 2: copy FROM nginx @@ -22,8 +20,11 @@ RUN apt-get update && apt-get install -y apt-utils openssl && \ openssl x509 -req -days 3650 -in /etc/nginx/ssl/dummy.csr -signkey /etc/nginx/ssl/dummy.key -out /etc/nginx/ssl/dummy.crt COPY nginx.conf /etc/nginx/nginx.conf +COPY run.sh /run.sh # copy compiled files from stage 1 COPY --from=compile-image /build/dist /usr/share/nginx/html -LABEL maintainer="maintainers@vikunja.io" \ No newline at end of file +LABEL maintainer="maintainers@vikunja.io" + +CMD "/run.sh" \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000000..d917f12d02 --- /dev/null +++ b/run.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# This shell script sets the api url based on an environment variable and starts nginx in foreground. + +if [ -z "$VIKUNJA_API_URL" ]; then + VIKUNJA_API_URL="/api/v1" +fi + +# Escape the variable to prevent sed from complaining +VIKUNJA_API_URL=$(echo $VIKUNJA_API_URL |sed 's/\//\\\//g') + +sed -i "s/http\:\/\/localhost\:3456\/api\/v1/$VIKUNJA_API_URL/g" /usr/share/nginx/html/index.html + +nginx -g "daemon off;"