fix(docker): make OPENAI_API_KEY optional in docker run (#448)

This commit is contained in:
Guy Ben-Aharon
2024-11-26 12:32:20 +02:00
committed by GitHub
parent 24db32369a
commit 4bb4766e1a
7 changed files with 24 additions and 3 deletions

View File

@@ -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"]

View File

@@ -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;

7
entrypoint.sh Normal file
View File

@@ -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;"

View File

@@ -12,6 +12,7 @@
href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,100..900;1,100..900&display=swap"
rel="stylesheet"
/>
<script src="/config.js"></script>
<script
src="https://cdn.usefathom.com/script.js"
data-site="PRHIVBNN"

0
public/config.js Normal file
View File

View File

@@ -219,7 +219,7 @@ export const exportSQL = async (
]);
const openai = createOpenAI({
apiKey: OPENAI_API_KEY,
apiKey: window?.env?.OPENAI_API_KEY ?? OPENAI_API_KEY,
});
const prompt = generateSQLPrompt(databaseType, sqlScript);

6
src/window.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
declare global {
interface Window {
env: Record<string, string>;
}
}
export {};