Skip to content

Commit

Permalink
fix: docker dev and prod build
Browse files Browse the repository at this point in the history
  • Loading branch information
Murzbul committed Mar 13, 2023
1 parent 37c1f50 commit e75d27f
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 242 deletions.
31 changes: 22 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:16-alpine as dev
FROM node:18-alpine as dev

RUN apk add bash dumb-init curl
RUN apk add bash dumb-init curl python3
RUN curl -s https://raw.githubusercontent.com/Intervox/node-webp/latest/bin/install_webp | bash
RUN apk add --no-cache --update libwebp-tools
RUN apk add --no-cache --update libpng-dev libjpeg-turbo-dev giflib-dev tiff-dev autoconf automake make gcc g++ wget
Expand All @@ -18,15 +18,24 @@ RUN npm install --location=global pnpm
WORKDIR /usr/app

COPY --chown=node:node src ./src
COPY --chown=node:node tools ./tools
COPY --chown=node:node package.json ./
COPY --chown=node:node pnpm-lock.yaml ./
COPY --chown=node:node tsconfig.json ./
COPY --chown=node:node ecosystem.config.js ./
COPY --chown=node:node .env ./
COPY --chown=node:node config ./config/
COPY --chown=node:node etsc.config.js ./
COPY --chown=node:node nodemon.json ./
COPY --chown=node:node .eslintrc.json ./
COPY --chown=node:node rimraf_cpy.mjs ./
COPY --chown=node:node .husky ./
COPY --chown=node:node .huskyrc ./
COPY --chown=node:node .npmrc ./

RUN pnpm install

RUN mkdir dist
RUN chown node:node dist

# Run development server
ENTRYPOINT [ "dumb-init", "pnpm", "dev" ]
Expand All @@ -41,10 +50,9 @@ FROM dev as build
USER root

RUN npm install --location=global pnpm
RUN pnpm install

RUN mkdir /usr/app/dist
RUN chown -R node:node /usr/app/dist
RUN pnpm install
RUN chown node:node node_modules

USER node

Expand All @@ -58,13 +66,16 @@ USER root

RUN rm -rf node_modules
RUN pnpm install --production --ignore-scripts
RUN chown node:node node_modules

RUN cd node_modules/bcrypt && npm rebuild bcrypt --build-from-source

FROM node:16-alpine as prod
FROM node:18-alpine as prod

ENV NODE_ENV production

RUN apk add bash dumb-init
RUN npm install --location=global pm2
RUN npm install --location=global pm2 pnpm

WORKDIR /usr/app

Expand All @@ -74,7 +85,9 @@ COPY --from=prerelease --chown=node:node /usr/app/node_modules/ ./node_modules/
COPY --from=prerelease --chown=node:node /usr/app/dist/ ./dist/
COPY --from=prerelease --chown=node:node /usr/app/config/ ./config/
COPY --from=prerelease --chown=node:node /usr/app/.env/ ./.env
COPY --from=prerelease --chown=node:node /usr/app/package.json/ ./package.json

USER node

ENTRYPOINT ["dumb-init", "pm2-runtime", "start", "ecosystem.config.js"]
#ENTRYPOINT ["dumb-init", "pm2-runtime", "start", "ecosystem.config.js"]
ENTRYPOINT ["dumb-init", "pnpm", "start"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ init:
@echo '************ ************'
@echo '************ Init NODE ************'
@echo '************ ************'
docker-compose exec node sh dev.init.sh
docker-compose exec node sh tools/dev.init.sh

clean:
docker-compose down -v --remove-orphans
Expand Down
4 changes: 0 additions & 4 deletions dev.build.sh

This file was deleted.

4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ services:
- traefik.http.routers.api.tls.certresolver=lets-encrypt
- traefik.port=80
volumes:
- .:/usr/app:cached
- ./src:/usr/app/src:cached
- ./config:/usr/app/config:cached
- ./.env:/usr/app/.env
networks:
- experiencenet

Expand Down
4 changes: 2 additions & 2 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module.exports = {
script: "./dist/src/index.js",
error_file: "./dist/src/logs/err.log",
watch: false,
instances: 1,
instances: 2,
ignore_watch: './dist/src/logs/*',
instance_var: "0",
env: {
NODE_ENV: "production",
NODE_CONFIG_STRICT_MODE: true
NODE_CONFIG_STRICT_MODE: false
}
}]
}
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"pre-commit": "lint-staged",
"pre-check": "pnpm ts-check && pnpm lint",
"prepare": "husky install",
"start": "node dist/index.js",
"start": "node dist/src/index.js",
"test-ci": "jest --run-in-band --coverage",
"test": "jest --coverage",
"test-watch": "jest --watch --silent --coverage=false",
Expand All @@ -34,23 +34,24 @@
"dependencies": {
"@deepkit/core": "1.0.1-alpha.77",
"@deepkit/event": "1.0.1-alpha.85",
"@deepkit/injector": "1.0.1-alpha.91",
"@deepkit/type": "1.0.1-alpha.85",
"@koa/cors": "^4.0.0",
"@koa/multer": "^3.0.0",
"@mikro-orm/core": "^5.6.2",
"@mikro-orm/postgresql": "^5.6.2",
"@mikro-orm/core": "^5.6.14",
"@mikro-orm/postgresql": "^5.6.14",
"axios": "^1.2.1",
"bcrypt": "^5.1.0",
"commander": "^9.4.1",
"commander": "^9.5.0",
"compression": "^1.7.4",
"config": "^3.3.8",
"config": "^3.3.9",
"cors": "^2.8.5",
"cwebp": "^2.0.5",
"dayjs": "^1.11.7",
"dotenv": "^16.0.3",
"envalid": "^7.3.1",
"express": "^4.18.2",
"express-rate-limit": "^6.5.1",
"express-rate-limit": "^6.7.0",
"faker": "^5.5.3",
"fs-extra": "^11.1.0",
"handlebars": "^4.7.7",
Expand All @@ -77,11 +78,14 @@
"node-cron": "^3.0.1",
"nodemailer": "6.7.7",
"pg-promise": "^10.11.1",
"pg-mem": "^2.6.4",
"pino": "^8.10.0",
"pino-pretty": "^9.2.0",
"qs": "^6.11.0",
"reflect-metadata": "^0.1.13",
"shelljs": "^0.8.5",
"tedis": "^0.1.12",
"tslib": "^2.4.1",
"ts-mixer": "^6.0.2",
"tsyringe": "^4.7.0",
"typeorm": "^0.3.11",
Expand Down Expand Up @@ -140,13 +144,10 @@
"lint-staged": "^13.1.0",
"madge": "^6.0.0",
"nodemon": "^2.0.20",
"pg-mem": "^2.6.4",
"pino-pretty": "^9.2.0",
"prettier": "^2.8.3",
"rimraf": "^3.0.2",
"supertest": "^6.3.0",
"ts-node": "^10.9.1",
"tslib": "^2.4.1",
"typescript": "^4.9.4"
},
"engines": {
Expand Down
Loading

0 comments on commit e75d27f

Please sign in to comment.