From b33a53a20fa16668c6037d50d46480770b0719a6 Mon Sep 17 00:00:00 2001 From: LeoQiu981112 Date: Tue, 26 Dec 2023 13:33:40 -0800 Subject: [PATCH 1/9] Add local docker setup with hot-reload --- .dockerignore | 7 +++++++ Dockerfile | 8 ++++++++ docker-compose.yml | 15 +++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c550055 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d9d016b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# Dockerfile (For Development) +FROM node:18-alpine +WORKDIR /app +COPY package*.json ./ +RUN npm install +RUN npm run build +EXPOSE 3000 +CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8559f1f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +# docker-compose.yml + +version: '3' + +services: + web: + build: + context: . + dockerfile: Dockerfile + container_name: local-site + restart: always + volumes: + - ./:/app + ports: + - 3000:3000 From 858996554bd1f5dd2bb4bff193cbf6cad36f2155 Mon Sep 17 00:00:00 2001 From: LeoQiu981112 Date: Tue, 26 Dec 2023 14:05:27 -0800 Subject: [PATCH 2/9] Add anon volumes --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 8559f1f..dcedfae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,5 +11,7 @@ services: restart: always volumes: - ./:/app + - /app/node_modules + - /app/.next ports: - 3000:3000 From e254e82bd0916f7f3f36e049486ad5077383d979 Mon Sep 17 00:00:00 2001 From: Leo Qiu Date: Thu, 28 Dec 2023 14:31:25 -0800 Subject: [PATCH 3/9] change os end of line config and dockerfile settings --- .prettierrc | 2 +- Dockerfile | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.prettierrc b/.prettierrc index 80af0ee..26a9ca5 100644 --- a/.prettierrc +++ b/.prettierrc @@ -6,5 +6,5 @@ "tabWidth": 2, "trailingComma": "es5", "bracketSpacing": true, - "endOfLine": "lf" + "endOfLine": "auto" } diff --git a/Dockerfile b/Dockerfile index d9d016b..5d607cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,8 @@ FROM node:18-alpine WORKDIR /app COPY package*.json ./ -RUN npm install +RUN npm ci +COPY . . RUN npm run build EXPOSE 3000 CMD ["npm", "start"] From 6300000a73087c6176a3bf77aa60b24e25103ff9 Mon Sep 17 00:00:00 2001 From: Leo Qiu Date: Fri, 29 Dec 2023 10:56:20 -0800 Subject: [PATCH 4/9] Update Dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alja Čekada <112892699+alchuu00@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5d607cf..8f93ffc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM node:18-alpine WORKDIR /app COPY package*.json ./ -RUN npm ci +RUN npm install COPY . . RUN npm run build EXPOSE 3000 From cfa8f18a0978a0e9898e12433b1f185cb462cb6a Mon Sep 17 00:00:00 2001 From: Leo Qiu Date: Sun, 31 Dec 2023 01:26:11 -0800 Subject: [PATCH 5/9] updated docker settings, and add hot-reload for dev --- Dockerfile | 31 +++++++++++++++++++++++++------ docker-compose.yml | 4 +--- next.config.js | 7 +++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8f93ffc..9816b76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,28 @@ -# Dockerfile (For Development) -FROM node:18-alpine +FROM node:18-alpine as base +RUN apk add --no-cache g++ make py3-pip libc6-compat WORKDIR /app COPY package*.json ./ -RUN npm install -COPY . . -RUN npm run build EXPOSE 3000 -CMD ["npm", "start"] + +FROM base as builder +WORKDIR /app +COPY . . +RUN npm run build + +FROM base as dev +WORKDIR /app +ENV NODE_ENV=development +RUN npm install +CMD ["npm", "run", "start"] + +FROM base as production +WORKDIR /app +ENV NODE_ENV=production +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nextjs -u 1001 +USER nextjs +COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json +CMD ["npm", "run", "startProduction"] + diff --git a/docker-compose.yml b/docker-compose.yml index dcedfae..446a546 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,9 @@ -# docker-compose.yml - version: '3' - services: web: build: context: . + target: dev dockerfile: Dockerfile container_name: local-site restart: always diff --git a/next.config.js b/next.config.js index e71f070..003a782 100644 --- a/next.config.js +++ b/next.config.js @@ -11,6 +11,13 @@ const nextConfig = { typescript: { tsconfigPath: './tsconfig.json', }, + webpackDevMiddleware: (config) => { + config.watchOptions = { + poll: 1000, + aggregateTimeout: 300, + }; + return config; + }, }; module.exports = nextConfig; From fd42ddfbd82803b449bcab787b284fc4f638042f Mon Sep 17 00:00:00 2001 From: Leo Qiu Date: Sun, 31 Dec 2023 01:46:15 -0800 Subject: [PATCH 6/9] undo eol change in .prettierrc --- .prettierrc | 2 +- src/app/about/page.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.prettierrc b/.prettierrc index 26a9ca5..80af0ee 100644 --- a/.prettierrc +++ b/.prettierrc @@ -6,5 +6,5 @@ "tabWidth": 2, "trailingComma": "es5", "bracketSpacing": true, - "endOfLine": "auto" + "endOfLine": "lf" } diff --git a/src/app/about/page.tsx b/src/app/about/page.tsx index 73fdff4..b738844 100644 --- a/src/app/about/page.tsx +++ b/src/app/about/page.tsx @@ -1,6 +1,6 @@ -import React from 'react'; import { Typography } from '@mui/material'; import Container from '@mui/material/Container'; +import React from 'react'; import './about.scss'; export default function About() { From 672563d1083ae4c7ca32ae6e7ec18f7be5b32df9 Mon Sep 17 00:00:00 2001 From: LeoQiu981112 Date: Fri, 5 Jan 2024 11:01:48 -0800 Subject: [PATCH 7/9] next config file changes --- next.config.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/next.config.js b/next.config.js index 003a782..e47021a 100644 --- a/next.config.js +++ b/next.config.js @@ -1,9 +1,11 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - basePath: process.env.NODE_ENV === 'production' ? '/openbc-web' : '', - output: 'export', - distDir: 'dist', + basePath: process.env.NODE_ENV === 'production' ? '' : '', + // basePath: process.env.NODE_ENV === 'production' ? '/openbc-web' : '', + output: 'standalone', + // output: 'export', + // distDir: 'dist', githubApiToken: process.env.GITHUB_API_KEY, images: { unoptimized: true, From 0ebd8a8bdd0a55a389383eb43fcf8e05a886ca5b Mon Sep 17 00:00:00 2001 From: LeoQiu981112 Date: Fri, 5 Jan 2024 12:08:24 -0800 Subject: [PATCH 8/9] local container config tweaks --- Dockerfile | 8 ++------ docker-compose.yml | 6 +----- next.config.js | 3 --- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9816b76..eb78faf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,14 +6,10 @@ EXPOSE 3000 FROM base as builder WORKDIR /app +RUN npm install COPY . . RUN npm run build -FROM base as dev -WORKDIR /app -ENV NODE_ENV=development -RUN npm install -CMD ["npm", "run", "start"] FROM base as production WORKDIR /app @@ -24,5 +20,5 @@ USER nextjs COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./package.json -CMD ["npm", "run", "startProduction"] +CMD ["node", ".next/standalone/server.js"] diff --git a/docker-compose.yml b/docker-compose.yml index 446a546..6c28572 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,13 +3,9 @@ services: web: build: context: . - target: dev + target: production dockerfile: Dockerfile container_name: local-site restart: always - volumes: - - ./:/app - - /app/node_modules - - /app/.next ports: - 3000:3000 diff --git a/next.config.js b/next.config.js index e47021a..9d7fbf4 100644 --- a/next.config.js +++ b/next.config.js @@ -2,10 +2,7 @@ const nextConfig = { basePath: process.env.NODE_ENV === 'production' ? '' : '', - // basePath: process.env.NODE_ENV === 'production' ? '/openbc-web' : '', output: 'standalone', - // output: 'export', - // distDir: 'dist', githubApiToken: process.env.GITHUB_API_KEY, images: { unoptimized: true, From b01cc87788533fcd883b9154901c4e397e53551a Mon Sep 17 00:00:00 2001 From: Leo Qiu Date: Tue, 9 Jan 2024 16:27:23 -0800 Subject: [PATCH 9/9] simplified configs, remove unused import in about page --- Dockerfile | 21 ++++----------------- docker-compose.yml | 3 +-- next.config.js | 12 +----------- src/app/about/page.tsx | 1 - 4 files changed, 6 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index eb78faf..15816ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,11 @@ FROM node:18-alpine as base -RUN apk add --no-cache g++ make py3-pip libc6-compat -WORKDIR /app -COPY package*.json ./ + EXPOSE 3000 -FROM base as builder WORKDIR /app -RUN npm install + COPY . . +RUN npm install RUN npm run build - -FROM base as production -WORKDIR /app -ENV NODE_ENV=production -RUN addgroup -g 1001 -S nodejs && \ - adduser -S nextjs -u 1001 -USER nextjs -COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./package.json -CMD ["node", ".next/standalone/server.js"] - +CMD ["npm", "run", "startProduction"] diff --git a/docker-compose.yml b/docker-compose.yml index 6c28572..fdfe2fe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,10 @@ version: '3' + services: web: build: context: . - target: production dockerfile: Dockerfile container_name: local-site - restart: always ports: - 3000:3000 diff --git a/next.config.js b/next.config.js index 9d7fbf4..b7cb4eb 100644 --- a/next.config.js +++ b/next.config.js @@ -1,22 +1,12 @@ /** @type {import('next').NextConfig} */ - const nextConfig = { - basePath: process.env.NODE_ENV === 'production' ? '' : '', - output: 'standalone', - githubApiToken: process.env.GITHUB_API_KEY, + basePath: '', images: { unoptimized: true, }, typescript: { tsconfigPath: './tsconfig.json', }, - webpackDevMiddleware: (config) => { - config.watchOptions = { - poll: 1000, - aggregateTimeout: 300, - }; - return config; - }, }; module.exports = nextConfig; diff --git a/src/app/about/page.tsx b/src/app/about/page.tsx index b738844..615bd0d 100644 --- a/src/app/about/page.tsx +++ b/src/app/about/page.tsx @@ -1,6 +1,5 @@ import { Typography } from '@mui/material'; import Container from '@mui/material/Container'; -import React from 'react'; import './about.scss'; export default function About() {