Skip to content

Commit 2b12153

Browse files
authored
feat: use docker multi-stage build (juliomrqz#193)
thanks to @dmlemos
1 parent 2eb3a70 commit 2b12153

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

Dockerfile

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
FROM node:8-alpine
2-
3-
RUN apk add --no-cache git
1+
FROM node:8-alpine AS builder
42

5-
# Set environment variables
6-
ENV USER_DIR=/usr/src/app
3+
ENV STATUSFY_VERSION 0.3.1
74
ENV NODE_ENV production
8-
ENV STATUSFY_VERSION=0.3.1
5+
6+
WORKDIR /usr/src/app
7+
8+
RUN \
9+
set -x \
10+
&& yarn install \
11+
&& yarn add "statusfy@$STATUSFY_VERSION" \
12+
&& npx statusfy build
13+
14+
15+
FROM node:8-alpine
16+
917
ENV NODE_ENV production
1018
ENV HOST 0.0.0.0
1119
ENV PORT 3000
20+
ENV WORKDIR /usr/src/app
1221

13-
RUN mkdir -p $USER_DIR
14-
RUN chown node:node "$USER_DIR"
15-
WORKDIR $USER_DIR
16-
17-
# RUN yarn cache clean
18-
# RUN yarn global add "statusfy@$STATUSFY_VERSION"
22+
COPY --from=builder --chown=node:node /usr/src/app/ $WORKDIR
1923

2024
COPY ./scripts/docker-start.sh /start.sh
21-
RUN chmod +x /start.sh
2225

23-
VOLUME $USER_DIR
26+
WORKDIR $WORKDIR
27+
VOLUME $WORKDIR
2428
EXPOSE $PORT
2529

26-
CMD ["sh", "/start.sh"]
30+
CMD ["/start.sh"]

scripts/docker-start.sh

100644100755
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
#!/bin/bash
1+
#!/bin/sh
2+
set -e
23

3-
cd $USER_DIR
4-
5-
yarn cache clean
6-
NODE_ENV=development yarn install
7-
yarn add "statusfy@$STATUSFY_VERSION"
8-
9-
npx statusfy build
4+
echo "Starting server..."
105
npx statusfy start

0 commit comments

Comments
 (0)