Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(dockerfiles): split dockerfile into production and dev #1325

Merged
merged 4 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ FROM node:14-alpine3.12

LABEL maintainer="Open Government Products" email="go@open.gov.sg"

ARG BUILD_MODE

# Inject ASSET_VARIANT via build arguments for production
ARG __ASSET_VARIANT
ENV ASSET_VARIANT=${__ASSET_VARIANT:-gov}
Expand All @@ -29,14 +27,12 @@ RUN npm ci

COPY . ./

RUN if [ "$BUILD_MODE" != "development" ]; \
then { \
RUN { \
echo "Building..."; \
npm run build; \
echo "Removing devDependencies for production..."; \
npm prune --production; \
} \
fi
}

# Builds and starts Node server for production
CMD ["npm", "run", "start"]
24 changes: 24 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:14-alpine3.12

LABEL maintainer="Open Government Products" email="go@open.gov.sg"

WORKDIR /usr/src/gogovsg

# For Express server
EXPOSE 8080

# For dev webpack server only, proxies to localhost:8080
EXPOSE 3000

RUN apk update && apk add ttf-freefont && rm -rf /var/cache/apk/*

# Installs IBMPlexSans-Regular.ttf for QRCodeService.
RUN wget https://github.com/IBM/plex/blob/master/IBM-Plex-Sans/fonts/complete/ttf/IBMPlexSans-Regular.ttf?raw=true -O /usr/share/fonts/TTF/IBMPlexSans-Regular.ttf
RUN fc-cache -f

# Install libraries
COPY package.json package-lock.json ./

RUN npm ci

COPY . ./
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ services:
app:
build:
context: .
args:
- BUILD_MODE=development
dockerfile: Dockerfile.dev
command: npm run docker-dev
depends_on:
- postgres
Expand Down