Skip to content

Commit

Permalink
Build container image as user node
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkingit committed Aug 3, 2020
1 parent ba1badd commit c1c5030
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ build-tools/
.nyc_output/
coverage/
test/
compose/
compose/
.*
build/
kubernetes/
samples/
50 changes: 30 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
#Build an intermediate image, have to use 12.x.x node since 13.x is not working for bcrypt yet
################################################################################
# Copyright 2019 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
#######################################
# Build the preliminary image
#######################################
FROM node:lts-alpine as buildImg

RUN apk update
RUN apk --no-cache add gnupg python make
RUN apk add --upgrade --no-cache libssl1.1
RUN apk add --no-cache g++
RUN apk --no-cache add python make g++

RUN mkdir -p /usr/src/
ENV PATH="$PATH:/usr/src/"

WORKDIR /usr/src/
COPY package.json /usr/src/
COPY package-lock.json /usr/src/
USER node
WORKDIR /home/node

COPY --chown=node . /home/node
RUN npm install --production --loglevel=warn
COPY . /usr/src/


#######################################
# Build the production image
#######################################
FROM node:lts-alpine
RUN apk add --upgrade --no-cache libssl1.1

RUN mkdir -p /usr/src/
ENV PATH="$PATH:/usr/src/"
USER node
WORKDIR /home/node

RUN export BUILD_TIME=`date '+%Y-%m-%d %H:%M:%S'`

WORKDIR /usr/src/
COPY --from=buildImg /usr/src /usr/src

ARG BUILD_TIME
ENV BUILD_TIME=${BUILD_TIME}
ARG BUILD_ID
ENV BUILD_ID=${BUILD_ID}

ARG BUILD_TIME
ENV BUILD_TIME=${BUILD_TIME}
COPY --chown=node --from=buildImg /home/node /home/node

EXPOSE 3333
CMD ["npm", "start"]

0 comments on commit c1c5030

Please sign in to comment.