diff --git a/compose.yml b/compose.yml index 7a1c4ad..b3c840c 100644 --- a/compose.yml +++ b/compose.yml @@ -328,6 +328,10 @@ services: - type: bind source: ./logs/miiverse-api/ target: /app/logs/ + - type: bind + source: ./config/mongoose-connect-options.json + target: /home/node/app/mongoose-connect-options.json + read_only: true networks: internal: dns: 172.20.0.200 @@ -374,6 +378,10 @@ services: - type: bind source: ./logs/boss/ target: /app/logs/ + - type: bind + source: ./config/mongoose-connect-options.json + target: /home/node/app/mongoose-connect-options.json + read_only: true networks: internal: dns: 172.20.0.200 diff --git a/config/mongoose-connect-options.json b/config/mongoose-connect-options.json new file mode 100644 index 0000000..0fda81f --- /dev/null +++ b/config/mongoose-connect-options.json @@ -0,0 +1,4 @@ +{ + "useNewUrlParser": true, + "useUnifiedTopology": true +} diff --git a/environment/boss.env b/environment/boss.env index d7837c3..e8f254a 100644 --- a/environment/boss.env +++ b/environment/boss.env @@ -1,5 +1,5 @@ PN_BOSS_CONFIG_HTTP_PORT=8080 -PN_BOSS_CONFIG_MONGOOSE_CONNECT_OPTIONS_PATH=/app/mongoose-connect-options.json +PN_BOSS_CONFIG_MONGOOSE_CONNECT_OPTIONS_PATH=/home/node/app/mongoose-connect-options.json PN_BOSS_CONFIG_GRPC_BOSS_SERVER_ADDRESS=0.0.0.0 PN_BOSS_CONFIG_GRPC_BOSS_SERVER_PORT=5002 PN_BOSS_CONFIG_GRPC_ACCOUNT_SERVER_ADDRESS=account diff --git a/environment/miiverse-api.env b/environment/miiverse-api.env index 5399876..14343d9 100644 --- a/environment/miiverse-api.env +++ b/environment/miiverse-api.env @@ -1,7 +1,7 @@ PN_MIIVERSE_API_CONFIG_HTTP_PORT=8080 PN_MIIVERSE_API_CONFIG_ACCOUNT_SERVER_ADDRESS=account PN_MIIVERSE_API_CONFIG_MONGO_CONNECTION_STRING=mongodb://mongodb:27017/pretendo_miiverse?replicaSet=rs -PN_MIIVERSE_API_CONFIG_MONGOOSE_CONNECT_OPTIONS_PATH=/app/mongoose-connect-options.json +PN_MIIVERSE_API_CONFIG_MONGOOSE_CONNECT_OPTIONS_PATH=/home/node/app/mongoose-connect-options.json PN_MIIVERSE_API_CONFIG_S3_ENDPOINT=http://minio.pretendo.cc PN_MIIVERSE_API_CONFIG_S3_ACCESS_KEY=minio_pretendo PN_MIIVERSE_API_CONFIG_GRPC_FRIENDS_IP=friends diff --git a/patches/BOSS/create-mongoose-connect-options-json.patch b/patches/BOSS/create-mongoose-connect-options-json.patch deleted file mode 100644 index fad0161..0000000 --- a/patches/BOSS/create-mongoose-connect-options-json.patch +++ /dev/null @@ -1,10 +0,0 @@ -diff --git c/mongoose-connect-options.json i/mongoose-connect-options.json -new file mode 100644 -index 0000000..0fda81f ---- /dev/null -+++ i/mongoose-connect-options.json -@@ -0,0 +1,4 @@ -+{ -+ "useNewUrlParser": true, -+ "useUnifiedTopology": true -+} diff --git a/patches/BOSS/dockerize.patch b/patches/BOSS/dockerize.patch index df235f7..827ed62 100644 --- a/patches/BOSS/dockerize.patch +++ b/patches/BOSS/dockerize.patch @@ -1,26 +1,64 @@ +diff --git c/.dockerignore i/.dockerignore +new file mode 100644 +index 0000000..19cdd91 +--- /dev/null ++++ i/.dockerignore +@@ -0,0 +1,4 @@ ++.git ++node_modules ++dist ++logs diff --git c/Dockerfile i/Dockerfile new file mode 100644 -index 0000000..6a9687a +index 0000000..25e1b0a --- /dev/null +++ i/Dockerfile -@@ -0,0 +1,11 @@ -+FROM node:18-alpine +@@ -0,0 +1,48 @@ ++# syntax=docker/dockerfile:1 + -+WORKDIR /app ++ARG app_dir="/home/node/app" + -+COPY package*.json . -+RUN npm install ++ ++# * Base Node.js image ++FROM node:20-alpine AS base ++ARG app_dir ++WORKDIR ${app_dir} ++ ++ ++# * Installing production dependencies ++FROM base AS dependencies ++ ++RUN --mount=type=bind,source=package.json,target=package.json \ ++ --mount=type=bind,source=package-lock.json,target=package-lock.json \ ++ --mount=type=cache,target=/root/.npm \ ++ npm ci --omit=dev ++ ++ ++# * Installing development dependencies and building the application ++FROM base AS build ++ ++RUN --mount=type=bind,source=package.json,target=package.json \ ++ --mount=type=bind,source=package-lock.json,target=package-lock.json \ ++ --mount=type=cache,target=/root/.npm \ ++ npm ci + +COPY . . +RUN npm run build + -+CMD ["node", "--inspect=0.0.0.0:9233", "./dist/server.js"] -diff --git c/.dockerignore i/.dockerignore -new file mode 100644 -index 0000000..dd2040f ---- /dev/null -+++ i/.dockerignore -@@ -0,0 +1,3 @@ -+.git -+node_modules -+logs ++ ++# * Running the final application ++FROM base AS final ++ARG app_dir ++ ++RUN mkdir -p ${app_dir}/logs ++RUN chown node:node ${app_dir}/logs ++ ++ENV NODE_ENV production ++USER node ++ ++COPY package.json . ++ ++COPY --from=dependencies ${app_dir}/node_modules ${app_dir}/node_modules ++COPY --from=build ${app_dir}/dist ${app_dir}/dist ++ ++CMD ["node", "."] diff --git a/patches/BOSS/make-fs-extra-dependency.patch b/patches/BOSS/make-fs-extra-dependency.patch new file mode 100644 index 0000000..7127f30 --- /dev/null +++ b/patches/BOSS/make-fs-extra-dependency.patch @@ -0,0 +1,130 @@ +diff --git i/package-lock.json w/package-lock.json +index f72209d..00d6594 100644 +--- i/package-lock.json ++++ w/package-lock.json +@@ -20,6 +20,7 @@ + "dotenv": "^10.0.0", + "express": "^4.17.1", + "express-subdomain": "^1.0.5", ++ "fs-extra": "^11.2.0", + "moment": "^2.29.4", + "mongoose": "^7.4.3", + "morgan": "^1.10.0", +@@ -36,7 +37,6 @@ + "@typescript-eslint/parser": "^6.4.0", + "axios": "^1.6.2", + "eslint": "^8.47.0", +- "fs-extra": "^10.1.0", + "tsc-alias": "^1.8.7", + "typescript": "^5.1.6", + "xmlbuilder2": "^3.0.2" +@@ -3458,17 +3458,16 @@ + } + }, + "node_modules/fs-extra": { +- "version": "10.1.0", +- "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", +- "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", +- "dev": true, ++ "version": "11.2.0", ++ "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", ++ "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { +- "node": ">=12" ++ "node": ">=14.14" + } + }, + "node_modules/fs-minipass": { +@@ -3599,8 +3598,7 @@ + "node_modules/graceful-fs": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz", +- "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", +- "dev": true ++ "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==" + }, + "node_modules/graphemer": { + "version": "1.4.0", +@@ -3855,7 +3853,6 @@ + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", +- "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, +@@ -5211,7 +5208,6 @@ + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", +- "dev": true, + "engines": { + "node": ">= 10.0.0" + } +@@ -8071,10 +8067,9 @@ + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==" + }, + "fs-extra": { +- "version": "10.1.0", +- "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", +- "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", +- "dev": true, ++ "version": "11.2.0", ++ "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", ++ "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", +@@ -8172,8 +8167,7 @@ + "graceful-fs": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz", +- "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", +- "dev": true ++ "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==" + }, + "graphemer": { + "version": "1.4.0", +@@ -8357,7 +8351,6 @@ + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", +- "dev": true, + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" +@@ -9317,8 +9310,7 @@ + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", +- "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", +- "dev": true ++ "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + }, + "unpipe": { + "version": "1.0.0", +diff --git i/package.json w/package.json +index 0e95ff9..24a694b 100644 +--- i/package.json ++++ w/package.json +@@ -24,6 +24,7 @@ + "dotenv": "^10.0.0", + "express": "^4.17.1", + "express-subdomain": "^1.0.5", ++ "fs-extra": "^11.2.0", + "moment": "^2.29.4", + "mongoose": "^7.4.3", + "morgan": "^1.10.0", +@@ -40,7 +41,6 @@ + "@typescript-eslint/parser": "^6.4.0", + "axios": "^1.6.2", + "eslint": "^8.47.0", +- "fs-extra": "^10.1.0", + "tsc-alias": "^1.8.7", + "typescript": "^5.1.6", + "xmlbuilder2": "^3.0.2" diff --git a/patches/account/dockerfile-update.patch b/patches/account/dockerfile-update.patch index 7d45291..4408561 100644 --- a/patches/account/dockerfile-update.patch +++ b/patches/account/dockerfile-update.patch @@ -1,25 +1,73 @@ +diff --git i/.dockerignore w/.dockerignore +index 7a2fc0a..19cdd91 100644 +--- i/.dockerignore ++++ w/.dockerignore +@@ -1,6 +1,4 @@ + .git +-config.json +-logs +-certs +-cdn + node_modules ++dist ++logs diff --git i/Dockerfile w/Dockerfile -index a810a90..39fa5ad 100644 +index a810a90..4f2eb80 100644 --- i/Dockerfile +++ w/Dockerfile -@@ -1,16 +1,13 @@ +@@ -1,16 +1,45 @@ -FROM node:18-alpine -+FROM node:20-alpine ++# syntax=docker/dockerfile:1 -RUN apk add --no-cache python3 make gcc g++ - WORKDIR /app +-WORKDIR /app ++ARG app_dir="/home/node/app" -COPY "docker/entrypoint.sh" ./ -- - COPY package*.json ./ --RUN npm install bcrypt && npm rebuild bcrypt --build-from-source - RUN npm install - COPY . ./ -+RUN npm run build +-COPY package*.json ./ +-RUN npm install bcrypt && npm rebuild bcrypt --build-from-source +-RUN npm install ++# * Base Node.js image ++FROM node:20-alpine AS base ++ARG app_dir ++WORKDIR ${app_dir} + +-COPY . ./ -VOLUME [ "/app/config.json", "/app/certs" ] -+VOLUME [ "/app/certs" ] ++# * Installing production dependencies ++FROM base AS dependencies -CMD ["sh", "entrypoint.sh"] -+CMD ["node", "--inspect=0.0.0.0:9229", "./dist/server.js"] ++RUN --mount=type=bind,source=package.json,target=package.json \ ++ --mount=type=bind,source=package-lock.json,target=package-lock.json \ ++ --mount=type=cache,target=/root/.npm \ ++ npm ci --omit=dev ++ ++ ++# * Installing development dependencies and building the application ++FROM base AS build ++ ++RUN --mount=type=bind,source=package.json,target=package.json \ ++ --mount=type=bind,source=package-lock.json,target=package-lock.json \ ++ --mount=type=cache,target=/root/.npm \ ++ npm ci ++ ++COPY . . ++RUN npm run build ++ ++ ++# * Running the final application ++FROM base AS final ++ARG app_dir ++ ++ENV NODE_ENV production ++USER node ++ ++COPY package.json . ++ ++COPY --from=dependencies ${app_dir}/node_modules ${app_dir}/node_modules ++COPY --from=build ${app_dir}/dist ${app_dir}/dist ++ ++CMD ["node", "."] diff --git a/patches/miiverse-api/create-mongoose-connect-options-json.patch b/patches/miiverse-api/create-mongoose-connect-options-json.patch deleted file mode 100644 index fad0161..0000000 --- a/patches/miiverse-api/create-mongoose-connect-options-json.patch +++ /dev/null @@ -1,10 +0,0 @@ -diff --git c/mongoose-connect-options.json i/mongoose-connect-options.json -new file mode 100644 -index 0000000..0fda81f ---- /dev/null -+++ i/mongoose-connect-options.json -@@ -0,0 +1,4 @@ -+{ -+ "useNewUrlParser": true, -+ "useUnifiedTopology": true -+} diff --git a/patches/miiverse-api/dockerfile-update.patch b/patches/miiverse-api/dockerfile-update.patch index b2309d5..c9a1315 100644 --- a/patches/miiverse-api/dockerfile-update.patch +++ b/patches/miiverse-api/dockerfile-update.patch @@ -1,21 +1,75 @@ +diff --git i/.dockerignore w/.dockerignore +index b4bb16e..19cdd91 100644 +--- i/.dockerignore ++++ w/.dockerignore +@@ -1,5 +1,4 @@ +-node_modules + .git +-config.json +-certs +-src/logs ++node_modules ++dist ++logs diff --git i/Dockerfile w/Dockerfile -index be1b7af..3293f6c 100644 +index be1b7af..25e1b0a 100644 --- i/Dockerfile +++ w/Dockerfile -@@ -1,6 +1,5 @@ - FROM node:18-alpine +@@ -1,15 +1,48 @@ +-FROM node:18-alpine ++# syntax=docker/dockerfile:1 -RUN apk add --no-cache python3 make gcc g++ - WORKDIR /app +-WORKDIR /app ++ARG app_dir="/home/node/app" - COPY "docker/entrypoint.sh" ./ -@@ -9,7 +8,6 @@ COPY package*.json ./ - RUN npm install +-COPY "docker/entrypoint.sh" ./ - COPY . ./ -+RUN npm run build +-COPY package*.json ./ +-RUN npm install ++# * Base Node.js image ++FROM node:20-alpine AS base ++ARG app_dir ++WORKDIR ${app_dir} + +-COPY . ./ -VOLUME [ "/app/config.json", "/app/certs" ] -- ++# * Installing production dependencies ++FROM base AS dependencies + -CMD ["sh", "entrypoint.sh"] -+CMD ["node", "--inspect=0.0.0.0:9231", "./dist/server.js"] ++RUN --mount=type=bind,source=package.json,target=package.json \ ++ --mount=type=bind,source=package-lock.json,target=package-lock.json \ ++ --mount=type=cache,target=/root/.npm \ ++ npm ci --omit=dev ++ ++ ++# * Installing development dependencies and building the application ++FROM base AS build ++ ++RUN --mount=type=bind,source=package.json,target=package.json \ ++ --mount=type=bind,source=package-lock.json,target=package-lock.json \ ++ --mount=type=cache,target=/root/.npm \ ++ npm ci ++ ++COPY . . ++RUN npm run build ++ ++ ++# * Running the final application ++FROM base AS final ++ARG app_dir ++ ++RUN mkdir -p ${app_dir}/logs ++RUN chown node:node ${app_dir}/logs ++ ++ENV NODE_ENV production ++USER node ++ ++COPY package.json . ++ ++COPY --from=dependencies ${app_dir}/node_modules ${app_dir}/node_modules ++COPY --from=build ${app_dir}/dist ${app_dir}/dist ++ ++CMD ["node", "."]