Dockerfile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #前端预构建
  2. FROM cmfont-cache:latest as builderFont
  3. COPY /client .
  4. RUN yarn
  5. RUN npm run build
  6. # 后端预构建
  7. FROM golang:1.15-alpine AS builder
  8. RUN go env -w GO111MODULE=on
  9. RUN go env -w GOPROXY=https://goproxy.cn,direct
  10. COPY . /go/src/construction_management
  11. # 编译
  12. WORKDIR /go/src/construction_management/server/web
  13. #install 执行文件会生成在 gopath/bin 中
  14. RUN go install ./
  15. # 正式镜像
  16. FROM alpine:3.13
  17. # 安装nginx
  18. RUN echo http://mirrors.aliyun.com/alpine/v3.10/main>/etc/apk/repositories && \
  19. echo http://mirrors.aliyun.com/alpine/v3.10/community>>/etc/apk/repositories
  20. RUN apk update && apk upgrade \
  21. && apk add nginx \
  22. && mkdir /run/nginx \
  23. touch /run/nginx.pid && \
  24. chmod 755 /run.sh
  25. RUN find / -name ngnix.pid
  26. # 复制配置文件和前端文件
  27. COPY --from=builder /go/src/construction_management/deployment/default.conf /etc/nginx/conf.d
  28. COPY --from=builderFont /dist /var/www/html/client
  29. # 后端相关
  30. # 把编译环境中编译好的 chat 复制到生产镜像中的 bin/chat 文件名称 不是目录
  31. #COPY --from=builder /go/bin/chat /bin/chat
  32. # /chat 放到根目录
  33. COPY --from=builder /go/bin/web /server
  34. COPY --from=builder /go/src/construction_management/server/web/config-debug.yaml /config-debug.yaml
  35. COPY --from=builder /go/src/construction_management/server/web/config-uat.yaml /config-uat.yaml
  36. COPY --from=builder /go/src/construction_management/server/web/config-pro.yaml /config-pro.yaml
  37. RUN mkdir -p /lib
  38. COPY --from=builder /go/src/construction_management/server/lib/*.json /lib/
  39. RUN chmod 777 /lib/*.json
  40. RUN chmod 777 /server
  41. RUN chmod 777 /config-debug.yaml
  42. RUN chmod 777 /config-uat.yaml
  43. RUN chmod 777 /config-pro.yaml
  44. ENV ADDR=:6060
  45. # 申明暴露的端口
  46. EXPOSE 80
  47. EXPOSE 6060
  48. # 设置服务入口
  49. ENTRYPOINT ["/run.sh"]
  50. # ENTRYPOINT ["sh","-c", "/server" ]
  51. # FROM centos:7
  52. # ADD /bin/ /
  53. # RUN chmod 777 /construction_management
  54. # ENV PARAMS=""
  55. # EXPOSE 6060
  56. # ENTRYPOINT ["sh","-c","/construction_management $PARAMS"]