From 4bb4766e1ac8d69e138668eb8a46de5affe62ceb Mon Sep 17 00:00:00 2001 From: Guy Ben-Aharon Date: Tue, 26 Nov 2024 12:32:20 +0200 Subject: [PATCH] fix(docker): make OPENAI_API_KEY optional in docker run (#448) --- Dockerfile | 6 ++++-- default.conf => default.conf.template | 5 +++++ entrypoint.sh | 7 +++++++ index.html | 1 + public/config.js | 0 src/lib/data/export-metadata/export-sql-script.ts | 2 +- src/window.d.ts | 6 ++++++ 7 files changed, 24 insertions(+), 3 deletions(-) rename default.conf => default.conf.template (66%) create mode 100644 entrypoint.sh create mode 100644 public/config.js create mode 100644 src/window.d.ts diff --git a/Dockerfile b/Dockerfile index 6c81357c..9672d1fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,9 +16,11 @@ RUN npm run build FROM nginx:stable-alpine AS production COPY --from=builder /usr/src/app/dist /usr/share/nginx/html -COPY ./default.conf /etc/nginx/conf.d/default.conf +COPY ./default.conf.template /etc/nginx/conf.d/default.conf.template +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh # Expose the default port for the Nginx web server EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] +ENTRYPOINT ["/entrypoint.sh"] diff --git a/default.conf b/default.conf.template similarity index 66% rename from default.conf rename to default.conf.template index 171ca3cb..82325096 100644 --- a/default.conf +++ b/default.conf.template @@ -8,6 +8,11 @@ server { try_files $uri $uri/ /index.html; } + location /config.js { + default_type application/javascript; + return 200 "window.env = { OPENAI_API_KEY: \"$OPENAI_API_KEY\" };"; + } + error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..7a883abd --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Replace placeholders in nginx.conf +envsubst '${OPENAI_API_KEY}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf + +# Start Nginx +nginx -g "daemon off;" diff --git a/index.html b/index.html index b840c1db..420fe35f 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,7 @@ href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet" /> +