-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile-API
executable file
·85 lines (54 loc) · 1.86 KB
/
Dockerfile-API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
##
# prepare build environment
FROM node:dubnium-alpine as builder-base
ENV YARN_VERSION 1.16.0
ENV YARN_DIR /opt/yarn
RUN apk --no-cache add git python make g++
ADD https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v${YARN_VERSION}.tar.gz /opt/yarn.tar.gz
RUN rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg && \
rm -rf $YARN_DIR && \
mkdir -p $YARN_DIR && \
tar -xzf /opt/yarn.tar.gz -C $YARN_DIR && \
ln -s $YARN_DIR/yarn-v$YARN_VERSION/bin/yarn $YARN_DIR/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/ && \
rm /opt/yarn.tar.gz
##
# development environment
FROM builder-base as development
ARG APPLICATION_PATH=applications/api
ENV APPLICATION_PATH=$APPLICATION_PATH
WORKDIR /srv
EXPOSE 3000
CMD ["sh", "-c", "sh ./infrastructure/docker-yarn-install.sh && cd ./$APPLICATION_PATH && yarn start"]
##
# build production environment
FROM builder-base as builder-source-code-and-deps
ARG APPLICATION_PATH=applications/api
WORKDIR /srv
COPY ./package.json /srv/package.json
COPY ./yarn.lock /srv/yarn.lock
COPY ./packages /srv/packages
COPY ./$APPLICATION_PATH/package.json /srv/$APPLICATION_PATH/package.json
RUN yarn install
COPY $APPLICATION_PATH /srv/$APPLICATION_PATH
##
# test environment
FROM builder-source-code-and-deps as stage-test
ARG APPLICATION_PATH=applications/api
WORKDIR /srv
CMD ["yarn", "run", "test"]
##
# build production environment
FROM builder-source-code-and-deps as stage-build
ARG APPLICATION_PATH=applications/api
WORKDIR /srv
RUN cd ./$APPLICATION_PATH; yarn build
##
# production environment
FROM node:dubnium-alpine
ARG APPLICATION_PATH=applications/api
WORKDIR /srv
COPY --from=stage-build /srv/$APPLICATION_PATH/dist /srv
COPY --from=stage-build /srv/$APPLICATION_PATH/node_modules /srv/node_modules
COPY --from=stage-build /srv/$APPLICATION_PATH/package.json /srv/package.json
EXPOSE 3000
CMD ["node", "./server.js"]