From 6ad030453461293e5e9ba3629a3937bb2a5d05db Mon Sep 17 00:00:00 2001 From: vanpho93 Date: Fri, 16 Sep 2022 16:03:51 +0700 Subject: [PATCH] feat: update Dockerfile --- .circleci/config.yml | 2 +- apps/reaction/.dockerignore => .dockerignore | 4 +- .gitignore | 2 +- .npmrc | 1 + Dockerfile | 57 +++++++++++++++++++ apps/reaction/Dockerfile | 14 ----- apps/reaction/docker-compose.dev.yml | 25 -------- ...cker-compose.yml => docker-compose.dev.yml | 24 -------- docker-compose.yml | 24 ++++++++ 9 files changed, 86 insertions(+), 67 deletions(-) rename apps/reaction/.dockerignore => .dockerignore (83%) create mode 100644 Dockerfile delete mode 100644 apps/reaction/Dockerfile delete mode 100644 apps/reaction/docker-compose.dev.yml rename apps/reaction/docker-compose.yml => docker-compose.dev.yml (50%) diff --git a/.circleci/config.yml b/.circleci/config.yml index af6846c9170..93816420c59 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -175,7 +175,7 @@ jobs: name: Build and push production Docker image command: | VERSION=$(git describe --tags `git rev-list --tags --max-count=1` | cut -c2-100) - docker build -t ${DOCKER_REPOSITORY}:${VERSION} -t ${DOCKER_REPOSITORY}:latest ./apps/reaction + docker build -t ${DOCKER_REPOSITORY}:${VERSION} -t ${DOCKER_REPOSITORY}:latest . docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} docker push ${DOCKER_REPOSITORY}:${VERSION} docker push ${DOCKER_REPOSITORY}:latest diff --git a/apps/reaction/.dockerignore b/.dockerignore similarity index 83% rename from apps/reaction/.dockerignore rename to .dockerignore index fcb26648113..1d0f06e3781 100644 --- a/apps/reaction/.dockerignore +++ b/.dockerignore @@ -11,6 +11,6 @@ .build.log Dockerfile -.reaction/docker/reaction.* +apps/reaction/.reaction/docker/reaction.* docs -node_modules +**/node_modules diff --git a/.gitignore b/.gitignore index dc0c22f522e..ebd1179ac14 100644 --- a/.gitignore +++ b/.gitignore @@ -78,4 +78,4 @@ yalc-packages .DS_Store # Build -dist \ No newline at end of file +dist diff --git a/.npmrc b/.npmrc index fbf7f9a7e1e..8a3e95d92e2 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,3 @@ engine-strict=true auto-install-peers=true +strict-peer-dependencies=false diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..0cfbd9520a5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +# Dockerfile for production builds +# syntax=docker/dockerfile:1.4 + +FROM node:14.18.1-alpine as deps + +# hadolint ignore=DL3018 +RUN apk --no-cache add bash curl less tini vim make python2 git g++ glib +SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-u", "-c"] +WORKDIR /app + +COPY ./apps/reaction ./apps/reaction +COPY .npmrc .nvmrc package.json pnpm-lock.yaml pnpm-workspace.yaml ./ + +RUN npm i -g pnpm@7 +RUN pnpm --filter=@reactioncommerce/reaction-api --prod deploy deps --ignore-scripts + + +FROM node:14.18.1-alpine + +# hadolint ignore=DL3018 +RUN apk --no-cache add bash curl less tini vim make python2 git g++ glib +SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-u", "-c"] + +WORKDIR /usr/local/src/app +ENV PATH=$PATH:/app/node_modules/.bin + +# Allow yarn/npm to create ./node_modules +RUN chown node:node . + +ENV NODE_ENV=production + +ARG NPM_TOKEN +COPY --from=deps /app/deps /usr/local/src/app + +ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/usr/local/src/app/node_modules/.bin + +# The `node-prod` base image installs NPM deps with --no-scripts. +# This prevents the `sharp` lib from working because it installs the binaries +# in a post-install script. We copy their install script here and run it. +# hadolint ignore=DL3003,SC2015 +RUN cd node_modules/sharp && (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy) + +USER node + +# delete npm token +RUN rm -f .npmrc || : + +# If any Node flags are needed, they can be set in +# the NODE_OPTIONS env variable. +# +# NOTE: We would prefer to use `node .` but relying on +# Node to look up the `main` path is currently broken +# when ECMAScript module support is enabled. When this +# is fixed, change command to: +# +# CMD ["tini", "--", "node", "."] +CMD ["tini", "--", "npm", "start"] diff --git a/apps/reaction/Dockerfile b/apps/reaction/Dockerfile deleted file mode 100644 index 6dce33985f2..00000000000 --- a/apps/reaction/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -# Dockerfile for production builds -FROM reactioncommerce/node-prod:14.18.1-v1 - -ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/usr/local/src/app/node_modules/.bin - -# The `node-prod` base image installs NPM deps with --no-scripts. -# This prevents the `sharp` lib from working because it installs the binaries -# in a post-install script. We copy their install script here and run it. -# hadolint ignore=DL3003,SC2015 -RUN cd node_modules/sharp && (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy) - -# The base image copies /src but we need to copy additional folders in this project -COPY --chown=node:node ./public ./public -COPY --chown=node:node ./plugins.json ./plugins.json diff --git a/apps/reaction/docker-compose.dev.yml b/apps/reaction/docker-compose.dev.yml deleted file mode 100644 index d0fc227b0b3..00000000000 --- a/apps/reaction/docker-compose.dev.yml +++ /dev/null @@ -1,25 +0,0 @@ -# This docker-compose file is used to run the project in Docker for development. -# The local files are mounted into the created container. -# -# Usage: -# ln -s docker-compose.dev.yml docker-compose.override.yml -# docker-compose up [-d] -# -# To go back to running the published image: -# rm docker-compose.override.yml - -version: '3.4' - -services: - api: - image: reactioncommerce/node-dev:14.18.1-v1 - ports: - - "3000:3000" - - "9229:9229" - volumes: - - .:/usr/local/src/app:cached - - api_node_modules:/usr/local/src/app/node_modules # do not link node_modules in, and persist it between dc up runs - -volumes: - mongo-db4: - api_node_modules: diff --git a/apps/reaction/docker-compose.yml b/docker-compose.dev.yml similarity index 50% rename from apps/reaction/docker-compose.yml rename to docker-compose.dev.yml index 8815826cb10..3144014eb73 100644 --- a/apps/reaction/docker-compose.yml +++ b/docker-compose.dev.yml @@ -1,35 +1,11 @@ -# This docker-compose file is used to run the project's published image -# -# Usage: docker-compose up [-d] -# -# See comment in docker-compose.dev.yml if you want to run for development. - version: "3.4" -networks: - reaction: - external: - name: reaction.localhost - services: - api: - image: reactioncommerce/reaction:4.2.0 - depends_on: - - mongo - env_file: - - ./.env - networks: - default: - reaction: - ports: - - "3000:3000" - mongo: image: mongo:4.2.0 command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger networks: default: - reaction: ports: - "27017:27017" volumes: diff --git a/docker-compose.yml b/docker-compose.yml index 3144014eb73..8815826cb10 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,35 @@ +# This docker-compose file is used to run the project's published image +# +# Usage: docker-compose up [-d] +# +# See comment in docker-compose.dev.yml if you want to run for development. + version: "3.4" +networks: + reaction: + external: + name: reaction.localhost + services: + api: + image: reactioncommerce/reaction:4.2.0 + depends_on: + - mongo + env_file: + - ./.env + networks: + default: + reaction: + ports: + - "3000:3000" + mongo: image: mongo:4.2.0 command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger networks: default: + reaction: ports: - "27017:27017" volumes: