From d9e7161743264b6a271dfc079f4085f878d22531 Mon Sep 17 00:00:00 2001 From: Rachid F <109089247+rflihxyz@users.noreply.github.com> Date: Wed, 6 Dec 2023 20:32:46 +0000 Subject: [PATCH 1/4] :construction: Added env variables for frontend in docker-compose & dockerfile Added env variables for frontend in docker-compose & dockerfile --- .env.example | 10 ++++++---- apps/webapp/Dockerfile | 7 +++++++ docker-compose.yml | 5 ++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 12f5fbcf4..893bb9021 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ # environement details +#backend ENV=dev DISTRIBUTION=selfhosted @@ -6,9 +7,10 @@ POSTGRES_USER=my_user POSTGRES_PASSWORD=my_password POSTGRES_DB=panora_db POSTGRES_HOST=postgres - JWT_SECRET=secret_jwt - - OAUTH_REDIRECT_BASE=https://api-staging.panora.dev -ENCRYPT_CRYPTO_SECRET_KEY=selfhosted123 \ No newline at end of file +ENCRYPT_CRYPTO_SECRET_KEY=selfhosted123 + +# webapp settings +VITE_BACKEND_DOMAIN=https://api-staging.panora.dev #could be http://api:3000 +VITE_FRONTEND_DOMAIN=https://app.panora.dev #http://webapp:80 \ No newline at end of file diff --git a/apps/webapp/Dockerfile b/apps/webapp/Dockerfile index 30d972a3f..5c6d2615d 100644 --- a/apps/webapp/Dockerfile +++ b/apps/webapp/Dockerfile @@ -25,6 +25,10 @@ RUN apk update # Set pnpm ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" + +ENV VITE_BACKEND_DOMAIN=$VITE_BACKEND_DOMAIN +ENV VITE_BACKEND_DOMAIN=$VITE_BACKEND_DOMAIN + RUN corepack enable WORKDIR /app @@ -42,6 +46,9 @@ RUN pnpm turbo run build --filter=webapp... # ======================================================================== FROM nginx:stable-alpine as runner +ENV VITE_BACKEND_DOMAIN=$VITE_BACKEND_DOMAIN +ENV VITE_BACKEND_DOMAIN=$VITE_BACKEND_DOMAIN + COPY --from=installer ./app/apps/webapp/dist/ /usr/share/nginx/html EXPOSE 80 diff --git a/docker-compose.yml b/docker-compose.yml index 7cc2faff3..e33193a39 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,9 +34,12 @@ services: build: dockerfile: ./apps/webapp/Dockerfile context: ./ + environment: + VITE_BACKEND_DOMAIN: ${VITE_BACKEND_DOMAIN} + VITE_FRONTEND_DOMAIN: ${VITE_FRONTEND_DOMAIN} restart: unless-stopped ports: - 80:80 depends_on: - - postgres + - api From 717457fde02853015d12c338585369e6ce641662 Mon Sep 17 00:00:00 2001 From: Rachid F <109089247+rflihxyz@users.noreply.github.com> Date: Wed, 6 Dec 2023 21:21:48 +0000 Subject: [PATCH 2/4] :ambulance: Docker compose front fix docker compose front fix --- .env.example | 2 +- apps/webapp/Dockerfile | 8 ++++---- docker-compose.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 893bb9021..95f8f898e 100644 --- a/.env.example +++ b/.env.example @@ -13,4 +13,4 @@ ENCRYPT_CRYPTO_SECRET_KEY=selfhosted123 # webapp settings VITE_BACKEND_DOMAIN=https://api-staging.panora.dev #could be http://api:3000 -VITE_FRONTEND_DOMAIN=https://app.panora.dev #http://webapp:80 \ No newline at end of file +#VITE_FRONTEND_DOMAIN=https://app.panora.dev #http://webapp:80 \ No newline at end of file diff --git a/apps/webapp/Dockerfile b/apps/webapp/Dockerfile index 5c6d2615d..479f6d17d 100644 --- a/apps/webapp/Dockerfile +++ b/apps/webapp/Dockerfile @@ -26,8 +26,8 @@ RUN apk update ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" -ENV VITE_BACKEND_DOMAIN=$VITE_BACKEND_DOMAIN -ENV VITE_BACKEND_DOMAIN=$VITE_BACKEND_DOMAIN +ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" +ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" RUN corepack enable @@ -46,8 +46,8 @@ RUN pnpm turbo run build --filter=webapp... # ======================================================================== FROM nginx:stable-alpine as runner -ENV VITE_BACKEND_DOMAIN=$VITE_BACKEND_DOMAIN -ENV VITE_BACKEND_DOMAIN=$VITE_BACKEND_DOMAIN +ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" +ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" COPY --from=installer ./app/apps/webapp/dist/ /usr/share/nginx/html diff --git a/docker-compose.yml b/docker-compose.yml index e33193a39..e42a86c09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,7 +36,7 @@ services: context: ./ environment: VITE_BACKEND_DOMAIN: ${VITE_BACKEND_DOMAIN} - VITE_FRONTEND_DOMAIN: ${VITE_FRONTEND_DOMAIN} + VITE_FRONTEND_DOMAIN: webapp restart: unless-stopped ports: From dcccf26a8bba457445904e019d208715aa70050d Mon Sep 17 00:00:00 2001 From: nael Date: Wed, 6 Dec 2023 23:05:30 +0100 Subject: [PATCH 3/4] feat: fixed dockerfile env --- apps/webapp/Dockerfile | 6 +++--- docker-compose.yml | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/webapp/Dockerfile b/apps/webapp/Dockerfile index 479f6d17d..dbd782a58 100644 --- a/apps/webapp/Dockerfile +++ b/apps/webapp/Dockerfile @@ -26,13 +26,13 @@ RUN apk update ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" -ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" +ARG VITE_BACKEND_DOMAIN ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" RUN corepack enable WORKDIR /app - + # First install the dependencies (as they change less often) COPY .gitignore .gitignore COPY --from=builder /app/out/json/ . @@ -46,7 +46,7 @@ RUN pnpm turbo run build --filter=webapp... # ======================================================================== FROM nginx:stable-alpine as runner -ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" +ARG VITE_BACKEND_DOMAIN ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" COPY --from=installer ./app/apps/webapp/dist/ /usr/share/nginx/html diff --git a/docker-compose.yml b/docker-compose.yml index e42a86c09..1ebe9522d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,8 +34,10 @@ services: build: dockerfile: ./apps/webapp/Dockerfile context: ./ + args: + VITE_BACKEND_DOMAIN: https://api-staging.panora.dev environment: - VITE_BACKEND_DOMAIN: ${VITE_BACKEND_DOMAIN} + #VITE_BACKEND_DOMAIN: ${VITE_BACKEND_DOMAIN} VITE_FRONTEND_DOMAIN: webapp restart: unless-stopped From 5215c8b0520b16169bfacc8c65800c192b9aa5cc Mon Sep 17 00:00:00 2001 From: Rachid F <109089247+rflihxyz@users.noreply.github.com> Date: Wed, 6 Dec 2023 23:28:54 +0000 Subject: [PATCH 4/4] :bug: Fixed broken frontend base URLs in docker-compose Fixed broken frontend base URLs in docker-compose --- .env.example | 7 ++++--- apps/webapp/Dockerfile | 10 ++++++---- docker-compose.yml | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 95f8f898e..51620ddef 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,7 @@ JWT_SECRET=secret_jwt OAUTH_REDIRECT_BASE=https://api-staging.panora.dev ENCRYPT_CRYPTO_SECRET_KEY=selfhosted123 -# webapp settings -VITE_BACKEND_DOMAIN=https://api-staging.panora.dev #could be http://api:3000 -#VITE_FRONTEND_DOMAIN=https://app.panora.dev #http://webapp:80 \ No newline at end of file +# Webapp settings +# Must be set in the perspective of the end user browser +VITE_BACKEND_DOMAIN=http://localhost:3000 +VITE_FRONTEND_DOMAIN=http://localhost \ No newline at end of file diff --git a/apps/webapp/Dockerfile b/apps/webapp/Dockerfile index dbd782a58..4a0d3c9a8 100644 --- a/apps/webapp/Dockerfile +++ b/apps/webapp/Dockerfile @@ -27,8 +27,9 @@ ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" ARG VITE_BACKEND_DOMAIN +ARG VITE_FRONTEND_DOMAIN ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" - +ENV VITE_FRONTEND_DOMAIN="$VITE_FRONTEND_DOMAIN" RUN corepack enable WORKDIR /app @@ -46,9 +47,10 @@ RUN pnpm turbo run build --filter=webapp... # ======================================================================== FROM nginx:stable-alpine as runner -ARG VITE_BACKEND_DOMAIN -ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" - +#ARG VITE_BACKEND_DOMAIN +#ARG VITE_FRONTEND_DOMAIN +#ENV VITE_BACKEND_DOMAIN="$VITE_BACKEND_DOMAIN" +#ENV VITE_FRONTEND_DOMAIN="$VITE_FRONTEND_DOMAIN" COPY --from=installer ./app/apps/webapp/dist/ /usr/share/nginx/html EXPOSE 80 diff --git a/docker-compose.yml b/docker-compose.yml index 1ebe9522d..a736797fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,11 @@ name: panora version: '3.8' -services: +networks: + frontend: + backend: +services: postgres: image: postgres:16.1 environment: @@ -14,6 +17,8 @@ services: volumes: - ./pg_data:/var/lib/postgresql/data - ./packages/api/scripts/init.sql:/docker-entrypoint-initdb.d/init.sql + networks: + - backend api: build: @@ -29,19 +34,22 @@ services: - 3000:3000 depends_on: - postgres + networks: + - backend webapp: build: dockerfile: ./apps/webapp/Dockerfile context: ./ args: - VITE_BACKEND_DOMAIN: https://api-staging.panora.dev - environment: - #VITE_BACKEND_DOMAIN: ${VITE_BACKEND_DOMAIN} - VITE_FRONTEND_DOMAIN: webapp + VITE_BACKEND_DOMAIN: ${VITE_BACKEND_DOMAIN} + VITE_FRONTEND_DOMAIN: ${VITE_FRONTEND_DOMAIN} restart: unless-stopped ports: - 80:80 depends_on: - api + networks: + - backend + - frontend