File tree 5 files changed +73
-1
lines changed
5 files changed +73
-1
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,6 @@ COMPOSE_PROJECT_NAME=
7
7
8
8
# docker-compose development overrides; uncomment to enable
9
9
# COMPOSE_FILE=docker-compose.yaml:docker-compose.dev.yaml
10
+
11
+ # docker-compose production overrides; uncomment to enable
12
+ # COMPOSE_FILE=docker-compose.yaml:docker-compose.prod.yaml
Original file line number Diff line number Diff line change 1
1
# TODO update to newer version: Active LTS or Current
2
- FROM node:14
2
+ FROM node:14 as dev
3
3
4
4
# cache hack (very fragile): initially only copy list of project dependencies
5
5
COPY --chown=node:node package.json package-lock.json /opt/node/
@@ -18,3 +18,17 @@ WORKDIR /opt/node/app
18
18
19
19
EXPOSE 3000
20
20
CMD ["npm" , "start" ]
21
+
22
+
23
+ FROM dev as node-prod
24
+ ENV NODE_ENV=production
25
+ RUN npm run build
26
+
27
+
28
+ FROM nginx as prod
29
+ COPY docker-entrypoint-override.sh /usr/bin/docker-entrypoint-override.sh
30
+ # write environment variables to config file and start
31
+ ENTRYPOINT ["/usr/bin/docker-entrypoint-override.sh" , "/docker-entrypoint.sh" ]
32
+ CMD ["nginx" ,"-g" ,"daemon off;" ]
33
+
34
+ COPY --from=node-prod /opt/node/app/build /usr/share/nginx/html
Original file line number Diff line number Diff line change 3
3
version : " 3.4"
4
4
services :
5
5
frontend :
6
+ build :
7
+ # stop building Dockerfile after dev stage
8
+ target : dev
6
9
volumes :
7
10
# mount code directory into container to allow hot-reloading
8
11
- ./:/opt/node/app
Original file line number Diff line number Diff line change
1
+ # docker-compose production overrides
2
+ ---
3
+ version : " 3.4"
4
+ services :
5
+ frontend :
6
+ build :
7
+ target : prod
8
+ environment :
9
+ NODE_ENV : production
10
+ ports :
11
+ # map container port 80 to $FRONTEND_EXTERNAL_PORT (port 3000 by default) on localhost (127.0.0.1)
12
+ - 127.0.0.1:${FRONTEND_EXTERNAL_PORT:-3000}:80
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ set -eu
3
+
4
+ repo_path=" $( cd " $( dirname " $0 " ) " && pwd) "
5
+ cmdname=" $( basename " $0 " ) "
6
+
7
+ usage () {
8
+ cat << USAGE >&2
9
+ Usage:
10
+ $cmdname command
11
+
12
+ Docker entrypoint script
13
+ Wrapper script that executes docker-related tasks before running given command
14
+
15
+ USAGE
16
+ exit 1
17
+ }
18
+
19
+ if [ " $1 " = " -h" ] || [ " $1 " = " --help" ]; then
20
+ usage
21
+ exit 0
22
+ fi
23
+
24
+
25
+ write_env_to_json () {
26
+ # write project-specific environment variables to app config file
27
+ local json_file=" $1 "
28
+
29
+ # only write environment variables frontend will read (beginning with "REACT_" or "VUE_")
30
+ local json_contents=" {$( printenv | grep -e REACT_ -e VUE_ | sed ' s/^\|$/"/g' | sed ' s|=|":"|' | paste -sd, -) }"
31
+ echo " $json_contents " > " $json_file "
32
+ }
33
+
34
+
35
+ write_env_to_json /usr/share/nginx/html/env.json
36
+
37
+
38
+ echo $cmdname complete
39
+ echo executing given command $@
40
+ exec " $@ "
You can’t perform that action at this time.
0 commit comments