|
| 1 | +# inspired by https://vuejs.org/v2/cookbook/dockerize-vuejs-app.html#Real-World-Example |
| 2 | +# use multi-stage builds: https://docs.docker.com/develop/develop-images/multistage-build/ |
| 3 | + |
| 4 | +# METHOND 1 (simple) |
| 5 | + |
| 6 | +## 1 build stage |
| 7 | +## 1.1 prepare for building front-end project |
| 8 | +#FROM node:10 as build-stage |
| 9 | +# |
| 10 | +## 1.2 make the 'app' folder the current working directory |
| 11 | +#WORKDIR /app |
| 12 | +# |
| 13 | +## 1.3 copy both 'package.json' and 'package-lock.json' (if available) |
| 14 | +#COPY package*.json ./ |
| 15 | +# |
| 16 | +## 1.4 install project dependencies |
| 17 | +#RUN npm install |
| 18 | +# |
| 19 | +## 1.5 copy project files and folders to the current working directory (i.e. 'app' folder) |
| 20 | +#COPY . . |
| 21 | +# |
| 22 | +## 1.6 get ENV Alias arguement |
| 23 | +#ARG ENV_ALIAS |
| 24 | +#RUN echo ${ENV_ALIAS} |
| 25 | +# |
| 26 | +## 1.7 build static resources |
| 27 | +#RUN npm run build:${ENV_ALIAS} --scripts-prepend-node-path=auto |
| 28 | +# |
| 29 | +## 2 publishing stage |
| 30 | +## 2.1 publish static resouces |
| 31 | +#FROM nginx as publishing-stage |
| 32 | +# |
| 33 | +## 2.2 copy compiled static resources to the directory that NGINX proxies |
| 34 | +#COPY --from=build-stage /app/dist/ /usr/share/nginx/html/ |
| 35 | +# |
| 36 | +## 2.3 get ENV arguement |
| 37 | +#ARG ENV |
| 38 | +#RUN echo ${ENV} |
| 39 | +# |
| 40 | +## 2.4 copy custom NGINX configuration to cover its default one |
| 41 | +#COPY nginx/default-${ENV}.conf /etc/nginx/conf.d/default.conf |
| 42 | +# |
| 43 | +## 2.5 expose port |
| 44 | +#EXPOSE 80 |
| 45 | +# |
| 46 | +## 2.6 start NGINX |
| 47 | +#CMD ["nginx", "-g", "daemon off;"] |
| 48 | + |
| 49 | +# METHOND 2 (faster) |
| 50 | + |
| 51 | +# 1 publishing stage |
| 52 | +# 1.1 publish static resouces |
| 53 | +FROM nginx as publishing-stage |
| 54 | + |
| 55 | +# 1.2 copy compiled static resources to the directory that NGINX proxies |
| 56 | +COPY dist/ /usr/share/nginx/html/ |
| 57 | + |
| 58 | +# 2.3 get ENV arguement |
| 59 | +ARG ENV |
| 60 | +RUN echo ${ENV} |
| 61 | + |
| 62 | +# 1.4 copy custom NGINX configuration |
| 63 | +COPY nginx/nginx-${ENV}.conf /etc/nginx/nginx.conf |
| 64 | +COPY nginx/mime.types /etc/nginx/mime.types |
| 65 | + |
| 66 | +# 1.5 expose port |
| 67 | +EXPOSE 80 |
| 68 | + |
| 69 | +# 1.6 start NGINX |
| 70 | +CMD ["nginx", "-g", "daemon off;"] |
0 commit comments