Skip to content

Commit

Permalink
Fix docker entrypoint (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
evroon authored Sep 5, 2024
1 parent 1885374 commit 4a81262
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
3 changes: 3 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ RUN set -ex \

EXPOSE 8400

HEALTHCHECK --interval=15s --timeout=5s --retries=5 \
CMD wget --spider http://localhost:8400 || exit 1

CMD pipenv run gunicorn \

Check warning on line 24 in backend/Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-push-image

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
-k uvicorn.workers.UvicornWorker \
bracket.app:app \
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.1'

networks:
bracket_lan:
driver: bridge
Expand All @@ -14,6 +12,7 @@ services:
- postgres
environment:
ENVIRONMENT: DEVELOPMENT
CORS_ORIGINS: http://localhost:3000
PG_DSN: postgresql://bracket_dev:bracket_dev@postgres:5432/bracket_dev
image: ghcr.io/evroon/bracket-backend
networks:
Expand Down
7 changes: 6 additions & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules

RUN NEXT_PUBLIC_API_BASE_URL="APP_PLACEHOLDER_NEXT_PUBLIC_API_BASE_URL" NEXT_PUBLIC_HCAPTCHA_SITE_KEY="APP_PLACEHOLDER_NEXT_PUBLIC_HCAPTCHA_SITE_KEY" yarn build
RUN NEXT_PUBLIC_API_BASE_URL=http://NEXT_PUBLIC_API_BASE_URL_PLACEHOLDER \
NEXT_PUBLIC_HCAPTCHA_SITE_KEY=NEXT_PUBLIC_HCAPTCHA_SITE_KEY_PLACEHOLDER \
yarn build

# Production image, copy all the files and run next
FROM node:18-alpine AS runner
Expand Down Expand Up @@ -47,4 +49,7 @@ EXPOSE 3000

ENTRYPOINT ["/app/entrypoint.sh"]

HEALTHCHECK --interval=15s --timeout=5s --retries=5 \
CMD wget --spider http://localhost:3000 || exit 1

CMD yarn start

Check warning on line 55 in frontend/Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-push-image

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
33 changes: 14 additions & 19 deletions frontend/docker-entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
#!/bin/bash
set -eo pipefail

# Script to replace `NEXT_PUBLIC_*` environment variables because they're set
# at build-time but we want to set them at runtime in `docker-compose.yml`
if [ -z ${NEXT_PUBLIC_API_BASE_URL+x} ];
then echo "Environment variable `NEXT_PUBLIC_API_BASE_URL` is not set, please set it in docker-compose.yml";
exit 1;
fi

# The first part wrapped in a function
makeSedCommands() {
printenv | \
grep '^NEXT_PUBLIC' | \
sed -r "s/=/ /g" | \
xargs -n 2 bash -c 'echo "sed -i \"s#APP_PLACEHOLDER_$0#$1#g\""'
}

# Set the delimiter to newlines (needed for looping over the function output)
IFS=$'\n'
# For each sed command
for c in $(makeSedCommands); do
# For each file in the .next directory
for f in $(find .next -type f); do
# Execute the command against the file
COMMAND="$c $f"
eval $COMMAND
# Replace the statically built placeholder literals from Dockerfile with run-time
# the value of the `NEXT_PUBLIC_WEBAPP_URL` environment variable
replace_placeholder() {
find .next public -type f |
while read file; do
sed -i "s|$1|$2|g" "$file" || true
done
done
}

replace_placeholder "http://NEXT_PUBLIC_API_BASE_URL_PLACEHOLDER" "$NEXT_PUBLIC_API_BASE_URL"
replace_placeholder "NEXT_PUBLIC_HCAPTCHA_SITE_KEY_PLACEHOLDER" "$NEXT_PUBLIC_HCAPTCHA_SITE_KEY"

echo "Starting Nextjs"
exec "$@"

0 comments on commit 4a81262

Please sign in to comment.