From a6e59933c729e1911a9ff9a4c07afeb20b949551 Mon Sep 17 00:00:00 2001 From: Sarvesh Limaye Date: Thu, 5 Jan 2023 17:02:56 +0000 Subject: [PATCH 1/8] improved dockerfile to support hot-reload --- app/docker-compose.yml | 5 +++++ app/next.config.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/app/docker-compose.yml b/app/docker-compose.yml index a228d170..11c1ed19 100644 --- a/app/docker-compose.yml +++ b/app/docker-compose.yml @@ -9,6 +9,11 @@ services: container_name: rc4conf restart: unless-stopped working_dir: /app + volumes: + - ./pages:/app/pages + - ./public:/app/public + - ./styles:/app/styles + - ./components:/app/components networks: - spnet - oesnet diff --git a/app/next.config.js b/app/next.config.js index 59dd6bc3..b1e12009 100644 --- a/app/next.config.js +++ b/app/next.config.js @@ -16,6 +16,10 @@ module.exports = { fs: false } } + config.watchOptions = { + poll: 1000, + aggregateTimeout: 300 + } return config } } From 482a5f6076e624ad95a4f143040986e92de484c5 Mon Sep 17 00:00:00 2001 From: Sarvesh Limaye Date: Thu, 12 Jan 2023 08:57:52 +0000 Subject: [PATCH 2/8] added dockefile for development --- app/Dockerfile.development | 31 ++++++++++++++++++++++++++++++ app/docker-compose.development.yml | 25 ++++++++++++++++++++++++ app/lib/api.js | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 app/Dockerfile.development create mode 100644 app/docker-compose.development.yml diff --git a/app/Dockerfile.development b/app/Dockerfile.development new file mode 100644 index 00000000..62cb4061 --- /dev/null +++ b/app/Dockerfile.development @@ -0,0 +1,31 @@ +# Dockerfile + +# Use node alpine as it's a small node image +FROM node:16-alpine + + +# Set /app as the working directory +WORKDIR /app + +# Copy package.json and package-lock.json +# to the /app working directory +COPY package.json package-lock.json ./ + +# Install dependencies in /app +RUN npm i + +# Copy the rest of our Next.js folder into /app +COPY next.config.js ./next.config.js +COPY apollo-client.js ./apollo-client.js + +COPY pages ./pages +COPY public ./public +COPY styles ./styles +COPY components ./components +COPY lib ./lib + +# Ensure port 3000 is accessible to our system +EXPOSE 3000 + +# Run npm run dev, as we would via the command line +CMD [ "npm", "run", "dev" ] \ No newline at end of file diff --git a/app/docker-compose.development.yml b/app/docker-compose.development.yml new file mode 100644 index 00000000..b41d8e06 --- /dev/null +++ b/app/docker-compose.development.yml @@ -0,0 +1,25 @@ +# docker-compose.yml + +version: "3" + +services: + app: + image: docker-nextjs-dev + build: + dockerfile: Dockerfile.development + ports: + - "3000:3000" + networks: + - stagingnetwork + volumes: + - ./pages:/app/pages + - ./public:/app/public + - ./styles:/app/styles + +networks: + stagingnetwork: + driver: bridge + ipam: + config: + - subnet: 172.28.0.0/16 + gateway: 172.28.0.1 diff --git a/app/lib/api.js b/app/lib/api.js index 4504482f..0793cbdb 100644 --- a/app/lib/api.js +++ b/app/lib/api.js @@ -1,6 +1,6 @@ export function getStrapiURL(path = "") { return `${ - process.env.NEXT_PUBLIC_STRAPI_API_URL || "http://127.0.0.1:1337" + process.env.NEXT_PUBLIC_STRAPI_API_URL || " http://172.28.0.1:1337/api" }/api${path}`; } From 369921547ec575f918c3c9e7af6ace2f0cf8c980 Mon Sep 17 00:00:00 2001 From: Sarvesh Limaye Date: Sat, 14 Jan 2023 17:50:51 +0000 Subject: [PATCH 3/8] nextjs container network issue fixed --- app/docker-compose.development.yml | 13 ++++++------- app/lib/api.js | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/docker-compose.development.yml b/app/docker-compose.development.yml index b41d8e06..3994cd4c 100644 --- a/app/docker-compose.development.yml +++ b/app/docker-compose.development.yml @@ -10,16 +10,15 @@ services: ports: - "3000:3000" networks: - - stagingnetwork + - spnet + - oesnet volumes: - ./pages:/app/pages - ./public:/app/public - ./styles:/app/styles networks: - stagingnetwork: - driver: bridge - ipam: - config: - - subnet: 172.28.0.0/16 - gateway: 172.28.0.1 + spnet: + external: true + oesnet: + external: true diff --git a/app/lib/api.js b/app/lib/api.js index 0793cbdb..0935c908 100644 --- a/app/lib/api.js +++ b/app/lib/api.js @@ -1,6 +1,6 @@ export function getStrapiURL(path = "") { return `${ - process.env.NEXT_PUBLIC_STRAPI_API_URL || " http://172.28.0.1:1337/api" + process.env.NEXT_PUBLIC_STRAPI_API_URL || "http://172.28.0.1:1337" }/api${path}`; } From 19aea97159518f1ba17d3f5ffddf9cbb1945d970 Mon Sep 17 00:00:00 2001 From: Sarvesh Limaye Date: Sun, 22 Jan 2023 07:41:42 +0000 Subject: [PATCH 4/8] env file issue solved --- app/docker-compose.development.yml | 2 ++ app/lib/api.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/docker-compose.development.yml b/app/docker-compose.development.yml index 3994cd4c..c82562a1 100644 --- a/app/docker-compose.development.yml +++ b/app/docker-compose.development.yml @@ -5,6 +5,8 @@ version: "3" services: app: image: docker-nextjs-dev + env_file: + - .env build: dockerfile: Dockerfile.development ports: diff --git a/app/lib/api.js b/app/lib/api.js index 0935c908..4504482f 100644 --- a/app/lib/api.js +++ b/app/lib/api.js @@ -1,6 +1,6 @@ export function getStrapiURL(path = "") { return `${ - process.env.NEXT_PUBLIC_STRAPI_API_URL || "http://172.28.0.1:1337" + process.env.NEXT_PUBLIC_STRAPI_API_URL || "http://127.0.0.1:1337" }/api${path}`; } From c742202a9ac1ca15a7fe9ba3a2c48b9cb0722ca4 Mon Sep 17 00:00:00 2001 From: Sarvesh Limaye Date: Thu, 2 Feb 2023 11:41:28 +0000 Subject: [PATCH 5/8] minor changes --- app/{docker-compose.development.yml => docker-compose.dev.yml} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename app/{docker-compose.development.yml => docker-compose.dev.yml} (86%) diff --git a/app/docker-compose.development.yml b/app/docker-compose.dev.yml similarity index 86% rename from app/docker-compose.development.yml rename to app/docker-compose.dev.yml index c82562a1..3905c579 100644 --- a/app/docker-compose.development.yml +++ b/app/docker-compose.dev.yml @@ -10,7 +10,7 @@ services: build: dockerfile: Dockerfile.development ports: - - "3000:3000" + - "$NEXTJS_PORT:3000" networks: - spnet - oesnet @@ -18,6 +18,7 @@ services: - ./pages:/app/pages - ./public:/app/public - ./styles:/app/styles + - ./assets:/app/assets networks: spnet: From 7f4b4e5a96cd85ab3ce3794de13adf83ec0bbac4 Mon Sep 17 00:00:00 2001 From: Sarvesh Limaye Date: Thu, 2 Feb 2023 11:56:50 +0000 Subject: [PATCH 6/8] updated Dockerfile.development --- app/Dockerfile.development | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Dockerfile.development b/app/Dockerfile.development index 62cb4061..a978d556 100644 --- a/app/Dockerfile.development +++ b/app/Dockerfile.development @@ -23,6 +23,7 @@ COPY public ./public COPY styles ./styles COPY components ./components COPY lib ./lib +COPY assets ./assets # Ensure port 3000 is accessible to our system EXPOSE 3000 From 8985059ebd1d17c45b9d40d25064eeda3fd95120 Mon Sep 17 00:00:00 2001 From: Sarvesh Limaye Date: Mon, 6 Feb 2023 18:22:14 +0000 Subject: [PATCH 7/8] updated docs + script --- docs/conferences/README.md | 4 ++++ startNext.sh | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/conferences/README.md b/docs/conferences/README.md index b9d922ec..3dd8420a 100644 --- a/docs/conferences/README.md +++ b/docs/conferences/README.md @@ -53,6 +53,10 @@ The client-side of RC4Conferences is developed using NextJS, to start the develo ``` sh startNext.sh localhost ``` +The client-side of RC4Conferences is developed using NextJS, to start the development environment of NextJS using docker run the following command +``` +sh startNext.sh localhost --docker +``` _Note: Please replace the "localhost" (127.0.0.1) with your static IP if you are doing environment setup on your VM. For e.g. `173.456.1.19`_ On a successful execution of script, the NextJS will start on port `3000` (default) or if it is occupied the next available port shall be used e.g., `3001`. diff --git a/startNext.sh b/startNext.sh index 540104b2..30fd9a2f 100644 --- a/startNext.sh +++ b/startNext.sh @@ -22,11 +22,11 @@ check_and_set_next_port export NEXT_PUBLIC_PORT=$NEXTJS_PORT -if [ "$2" = 'production' ]; then +if [ "$2" = '--docker' ]; then printf '\nNEXT_PUBLIC_API_URL'="https://$1:$NEXTJS_PORT" >> app/.env - echo "--Starting NextJS Production Client--" + echo "--Starting NextJS Client using docker--" cd app - docker-compose up -d + docker-compose -f docker-compose.dev.yml up --build else printf '\nNEXT_PUBLIC_API_URL'="http://$1:$NEXTJS_PORT" >> app/.env echo "--Starting NextJS Development Client--" From c6f37d048bba217219f0fd48f65d805bad02deef Mon Sep 17 00:00:00 2001 From: Sarvesh Limaye Date: Wed, 8 Feb 2023 17:18:10 +0000 Subject: [PATCH 8/8] minor changes done --- startNext.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/startNext.sh b/startNext.sh index 30fd9a2f..5be11d84 100644 --- a/startNext.sh +++ b/startNext.sh @@ -22,11 +22,19 @@ check_and_set_next_port export NEXT_PUBLIC_PORT=$NEXTJS_PORT -if [ "$2" = '--docker' ]; then +if [ "$2" = '--docker' ] +then printf '\nNEXT_PUBLIC_API_URL'="https://$1:$NEXTJS_PORT" >> app/.env echo "--Starting NextJS Client using docker--" cd app docker-compose -f docker-compose.dev.yml up --build +elif [ "$2" = 'production' ] +then + printf '\nNEXT_PUBLIC_API_URL'="https://$1:$NEXTJS_PORT" >> app/.env + echo "--Starting NextJS Production Client--" + cd app + docker-compose up -d + else printf '\nNEXT_PUBLIC_API_URL'="http://$1:$NEXTJS_PORT" >> app/.env echo "--Starting NextJS Development Client--"