From 363668d726ceede67d046c8e75e1d0a2f02faa2d Mon Sep 17 00:00:00 2001 From: leandrofars Date: Tue, 9 Apr 2024 01:04:58 -0300 Subject: [PATCH 1/4] feat: frontend with dynamic env vars --- deploy/compose/.env.frontend | 17 +++++++++++++++++ frontend/build/.dockerignore | 1 + frontend/build/Dockerfile | 24 +++++++++++++++++++++--- frontend/build/Makefile | 6 +++++- frontend/build/entrypoint.sh | 18 ++++++++++++++++++ 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 frontend/build/.dockerignore create mode 100644 frontend/build/entrypoint.sh diff --git a/deploy/compose/.env.frontend b/deploy/compose/.env.frontend index e69de29..32e4aa9 100644 --- a/deploy/compose/.env.frontend +++ b/deploy/compose/.env.frontend @@ -0,0 +1,17 @@ +# ----------------------------- Local Environment ---------------------------- # + +NEXT_PUBLIC_REST_ENPOINT="http://localhost:8000/api" +NEXT_PUBLIC_WS_ENPOINT="http://localhost:5000/" +# ---------------------------------------------------------------------------- # + +# -------------------------- Production Environment -------------------------- # + +#NEXT_PUBLIC_REST_ENPOINT="https://demo.oktopus.app.br/api" +#NEXT_PUBLIC_WS_ENPOINT="https://demo.oktopus.app.br/" +# ---------------------------------------------------------------------------- # + +# ---------------------------- Mocked Environment ---------------------------- # + +#NEXT_PUBLIC_REST_ENPOINT="https://d9962fd9-2464-4a30-9a86-a15a04b57ad0.mock.pstmn.io" + +# ---------------------------------------------------------------------------- # diff --git a/frontend/build/.dockerignore b/frontend/build/.dockerignore new file mode 100644 index 0000000..aced64b --- /dev/null +++ b/frontend/build/.dockerignore @@ -0,0 +1 @@ +.next/ \ No newline at end of file diff --git a/frontend/build/Dockerfile b/frontend/build/Dockerfile index de5d174..5c9d862 100644 --- a/frontend/build/Dockerfile +++ b/frontend/build/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16.20.2-alpine +FROM node:16.20.2-alpine as builder WORKDIR /app @@ -6,6 +6,24 @@ COPY ../ . RUN npm install -RUN npm run build +RUN NEXT_PUBLIC_REST_ENPOINT=REST_API_URL NEXT_PUBLIC_WS_ENPOINT=WS_URL npm run build -ENTRYPOINT [ "npm", "run", "start" ] \ No newline at end of file +RUN ls -la && echo "Listing directory contents done" + +FROM node:16.20.2-alpine as runner + +WORKDIR /app + +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/build/entrypoint.sh ./entrypoint.sh +COPY --from=builder /app/public ./public + + +RUN npm install + +RUN chmod 755 entrypoint.sh + +ENTRYPOINT ["/app/entrypoint.sh"] + +CMD [ "npm", "run", "start" ] \ No newline at end of file diff --git a/frontend/build/Makefile b/frontend/build/Makefile index 147c1e6..204a78b 100644 --- a/frontend/build/Makefile +++ b/frontend/build/Makefile @@ -27,6 +27,7 @@ help: @echo "logs - show logs of docker container" @echo "bash - access container shell" @echo "release - tag image as latest and push to registry" + @echo "tag - tag image as latest" build: @docker build -t ${DOCKER_USER}/${DOCKER_APP}:${DOCKER_TAG} -f Dockerfile ../ @@ -58,4 +59,7 @@ bash: release: build @docker push ${DOCKER_USER}/${DOCKER_APP}:${DOCKER_TAG} @docker tag ${DOCKER_USER}/${DOCKER_APP}:${DOCKER_TAG} ${DOCKER_USER}/${DOCKER_APP}:latest - @docker push ${DOCKER_USER}/${DOCKER_APP}:latest \ No newline at end of file + @docker push ${DOCKER_USER}/${DOCKER_APP}:latest + +tag: + docker tag ${DOCKER_USER}/${DOCKER_APP}:${DOCKER_TAG} ${DOCKER_USER}/${DOCKER_APP}:latest \ No newline at end of file diff --git a/frontend/build/entrypoint.sh b/frontend/build/entrypoint.sh new file mode 100644 index 0000000..74c569d --- /dev/null +++ b/frontend/build/entrypoint.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh +set -Ex + +function apply_path { + + echo "Check that we have NEXT_PUBLIC_REST_ENPOINT vars" + test -n "$NEXT_PUBLIC_REST_ENPOINT" + + echo "Check that we have NEXT_PUBLIC_WS_ENPOINT vars" + test -n "$NEXT_PUBLIC_WS_ENPOINT" + + find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#REST_API_URL#$NEXT_PUBLIC_REST_ENPOINT#g" + find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#WS_URL#$ENVIROMENT_VAR#g" +} + +apply_path +echo "Starting Nextjs" +exec "$@" \ No newline at end of file From 41a088998c6b14a76c656f21d8a647d23086ad3c Mon Sep 17 00:00:00 2001 From: leandrofars Date: Tue, 9 Apr 2024 01:07:11 -0300 Subject: [PATCH 2/4] fix(frontend): dynamic ws endpoint --- frontend/build/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/build/entrypoint.sh b/frontend/build/entrypoint.sh index 74c569d..f4abca7 100644 --- a/frontend/build/entrypoint.sh +++ b/frontend/build/entrypoint.sh @@ -10,7 +10,7 @@ function apply_path { test -n "$NEXT_PUBLIC_WS_ENPOINT" find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#REST_API_URL#$NEXT_PUBLIC_REST_ENPOINT#g" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#WS_URL#$ENVIROMENT_VAR#g" + find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#WS_URL#$NEXT_PUBLIC_WS_ENPOINT#g" } apply_path From a4fcfba12453efbd6e821b8e5b8978151eb4ff2c Mon Sep 17 00:00:00 2001 From: leandrofars Date: Tue, 9 Apr 2024 01:22:37 -0300 Subject: [PATCH 3/4] fix(mongo): docker data map to local volume | closes #220 --- deploy/compose/.gitignore | 4 +++- deploy/compose/docker-compose.yaml | 2 ++ deploy/compose/mongo_data/.gitkeep | 0 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 deploy/compose/mongo_data/.gitkeep diff --git a/deploy/compose/.gitignore b/deploy/compose/.gitignore index 63decb2..3b43ac1 100644 --- a/deploy/compose/.gitignore +++ b/deploy/compose/.gitignore @@ -1,2 +1,4 @@ portainer_data/* -!portainer_data/.gitkeep \ No newline at end of file +!portainer_data/.gitkeep +mongo_data/* +!mongo_data/.gitkeep \ No newline at end of file diff --git a/deploy/compose/docker-compose.yaml b/deploy/compose/docker-compose.yaml index 0d9cabc..9ce146c 100644 --- a/deploy/compose/docker-compose.yaml +++ b/deploy/compose/docker-compose.yaml @@ -39,6 +39,8 @@ services: networks: usp_network: ipv4_address: 172.16.235.4 + volumes: + - ./mongo_data:/data/db profiles: [controller,adapter] redis: diff --git a/deploy/compose/mongo_data/.gitkeep b/deploy/compose/mongo_data/.gitkeep new file mode 100644 index 0000000..e69de29 From 468a74ea88021d7e3ce44143db9db724dbff1ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20Ant=C3=B4nio=20Farias=20Machado?= <83298718+leandrofars@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:01:39 -0300 Subject: [PATCH 4/4] docs(readme): api docs link --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 7597c57..009ce85 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,6 @@ This repository aims to promote the development of a multi-vendor management pla
  • Documentation
  • -
  • - Workspace of tests and development -