Skip to content

Commit

Permalink
fix heredoc literal
Browse files Browse the repository at this point in the history
  • Loading branch information
tom committed Mar 21, 2024
1 parent 063d0d0 commit 836e3c7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
13 changes: 10 additions & 3 deletions search/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ WORKDIR /usr/share/nginx/html

COPY --from=build /app/dist /usr/share/nginx/html
# below hack only seems to work if the container isn't built with corresponding vite variable
COPY <<EOF /docker-entrypoint.d/99-insert.sh
#!/bin/sh

COPY <<'EOF' /docker-entrypoint.d/01-insert-window-variable.sh
#!/bin/sh

set -eu

if [ -n "$API_HOST" ]; then
echo "window.API_HOST = '$API_HOST';"
echo API_HOST variable found
echo "window.API_HOST='$API_HOST';" >> /usr/share/nginx/html/env.js
fi
EOF

RUN chmod +x /docker-entrypoint.d/01-insert-window-variable.sh

EXPOSE 80

9 changes: 8 additions & 1 deletion search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ Build with vite env's and run with docker run / compose

If you want to configure API_HOST at runtime, build without vite envs

`docker run -p 8080:80 --env API_HOST="localhost:1234" nginx-test`
`docker run -p 8080:80 --env API_HOST="localhost:1234" nginx-test`

Alternatively you can mount env.js as a docker volume under `/usr/share/nginx/html/env.js`


``` env.js
window.API_HOST=http://localhost:4321;"
```
3 changes: 2 additions & 1 deletion search/public/env.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// add window objects here
// add window variables here

0 comments on commit 836e3c7

Please sign in to comment.