diff --git a/backend/Dockerfile b/backend/Dockerfile index d7c7192aa..31e043dff 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -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 \ -k uvicorn.workers.UvicornWorker \ bracket.app:app \ diff --git a/docker-compose.yml b/docker-compose.yml index 500e2a832..ac7468baf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.1' - networks: bracket_lan: driver: bridge @@ -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: diff --git a/frontend/Dockerfile b/frontend/Dockerfile index f6f02efc7..6d916e1d2 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -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 @@ -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 diff --git a/frontend/docker-entrypoint.sh b/frontend/docker-entrypoint.sh old mode 100644 new mode 100755 index 113496b6b..3896bf34a --- a/frontend/docker-entrypoint.sh +++ b/frontend/docker-entrypoint.sh @@ -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 "$@"