Skip to content

Commit

Permalink
feat: update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
vanpho93 committed Sep 16, 2022
1 parent 8cafa12 commit 6ad0304
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/reaction/.dockerignore → .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

.build.log
Dockerfile
.reaction/docker/reaction.*
apps/reaction/.reaction/docker/reaction.*
docs
node_modules
**/node_modules
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ yalc-packages
.DS_Store

# Build
dist
dist
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
engine-strict=true
auto-install-peers=true
strict-peer-dependencies=false
57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 0 additions & 14 deletions apps/reaction/Dockerfile

This file was deleted.

25 changes: 0 additions & 25 deletions apps/reaction/docker-compose.dev.yml

This file was deleted.

24 changes: 0 additions & 24 deletions apps/reaction/docker-compose.yml → docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 6ad0304

Please sign in to comment.