caipin 3 anos atrás
pai
commit
067220a9f7
3 arquivos alterados com 51 adições e 3 exclusões
  1. 26 3
      deployment/Dockerfile
  2. 18 0
      deployment/default.conf
  3. 7 0
      deployment/run.sh

+ 26 - 3
deployment/Dockerfile

@@ -1,15 +1,36 @@
-FROM golang:1.15-alpine AS builder
+#前端预构建
+FROM cmfont-cache:latest as builderFont
+COPY /client .
+RUN yarn
+RUN npm run build
 
+# 后端预构建
+FROM golang:1.15-alpine AS builder
 RUN go env -w GO111MODULE=on
 RUN go env -w GOPROXY=https://goproxy.cn,direct
-
 COPY . /go/src/construction_management
 # 编译
 WORKDIR /go/src/construction_management/server/web
 #install 执行文件会生成在 gopath/bin 中
 RUN go install ./
 
+
+# 正式镜像
 FROM alpine:3.13
+
+# 安装nginx
+RUN echo http://mirrors.aliyun.com/alpine/v3.10/main>/etc/apk/repositories && \
+    echo  http://mirrors.aliyun.com/alpine/v3.10/community>>/etc/apk/repositories
+RUN apk update && apk upgrade \
+    && apk add nginx \
+    && mkdir /run/nginx  \
+    touch /run/nginx.pid && \
+    chmod 755 /run.sh
+RUN find / -name ngnix.pid
+
+# 复制配置文件和前端文件
+COPY /investServer/deployment/default.conf /etc/nginx/conf.d
+COPY --from=builder /dist /var/www/html/client
 # 把编译环境中编译好的 chat 复制到生产镜像中的  bin/chat 文件名称 不是目录
 #COPY --from=builder /go/bin/chat /bin/chat
 # /chat 放到根目录
@@ -29,10 +50,12 @@ RUN chmod 777 /config-pro.yaml
 ENV ADDR=:6060
 
 # 申明暴露的端口
+EXPOSE 80
 EXPOSE 6060
 
 # 设置服务入口
-ENTRYPOINT ["sh","-c", "/server" ]
+ENTRYPOINT ["/run.sh"]
+# ENTRYPOINT ["sh","-c", "/server" ]
 
 
 

+ 18 - 0
deployment/default.conf

@@ -0,0 +1,18 @@
+server {
+        listen      80;
+        server_name localhost,127.0.0.1;
+
+        location / {
+            try_files $uri  /index.html;
+            root "/var/www/html/client/";
+        }
+        
+        location /api{ 
+            proxy_pass http://localhost:6060;
+            proxy_set_header Host $proxy_host;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+            proxy_set_header Cookie $http_cookie;
+            proxy_set_header X-Forwarded-Proto $scheme;
+        }	
+ }

+ 7 - 0
deployment/run.sh

@@ -0,0 +1,7 @@
+#!/bin/sh
+
+
+# 后端启动
+./server
+# 关闭后台启动,hold住进程
+nginx -g 'daemon off;'