forked from gphper/grm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
50 lines (31 loc) · 874 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#构建npm前端打包环境
FROM node:16 as nbuilder
WORKDIR /build
COPY ./web .
RUN npm install
RUN npm run build
#构建golang打包环境
FROM golang:alpine as gbuilder
ENV CGO_ENABLED 0
ENV GOPROXY https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update \
&& apk upgrade
RUN apk update
Run apk add upx
WORKDIR /build
ADD . .
#将打包好的前端文件拷贝到gbuilder中
COPY --from=nbuilder /build/dist /build/web/dist
RUN go mod download
RUN go build -ldflags "-s -w" -o grm-build main.go
RUN upx -9 grm-build -o grmsrv
#构建最终的发布镜像
FROM alpine
ENV TZ Asia/Shanghai
WORKDIR /app
COPY --from=gbuilder /build/grmsrv /app/grmsrv
#添加管理用户 -u指定用户名 -p指定密码
RUN ./grmsrv user add -u=admin -p=123456
#运行服务
CMD ["./grmsrv","srv","run"]