66 lines
2.1 KiB
Docker
66 lines
2.1 KiB
Docker
## 第一阶段 ====> Nodejs打包编译输出前端资源
|
|
FROM node:18-alpine AS buildNode
|
|
|
|
ENV FRONTEND_DIR = "/jenkins/.jenkins/workspace/ems_frontend_vue3"
|
|
|
|
## 工作目录存放程序源码
|
|
WORKDIR /frontend
|
|
|
|
## 复制实际需要的文件到工作目录
|
|
COPY ${FRONTEND_DIR} ./
|
|
|
|
RUN npm config set registry https://registry.npmmirror.com
|
|
RUN npm install && npm run build
|
|
|
|
## 第二阶段 ====> GO打包编译输出后端程序
|
|
FROM golang:alpine AS buildGo
|
|
|
|
ARG VERSION
|
|
|
|
ENV BACKEND_DIR = "/jenkins/.jenkins/workspace/ems_backend"
|
|
|
|
ENV CGO_ENABLED 0
|
|
ENV GOOS linux
|
|
ENV GOPROXY https://goproxy.cn,direct
|
|
|
|
WORKDIR /backend
|
|
|
|
## 复制实际需要的文件到工作目录
|
|
COPY ${BACKEND_DIR}/docker ./docker
|
|
COPY ${BACKEND_DIR}/restagent/config ./restagent/config
|
|
COPY ${BACKEND_DIR}/restagent/etc ./restagent/etc
|
|
COPY ${BACKEND_DIR}/restagent/restagent.go ./restagent/restagent.go
|
|
COPY ${BACKEND_DIR}/features ./features
|
|
COPY ${BACKEND_DIR}/lib ./lib
|
|
COPY ${BACKEND_DIR}/src ./src
|
|
COPY ${BACKEND_DIR}/go.sum ./
|
|
COPY ${BACKEND_DIR}/go.mod ./
|
|
|
|
RUN cd /backend && go mod download
|
|
RUN cd /backend/restagent && go build -o omc -v -ldflags "-X 'ems.agt/lib/global.Version=${VERSION}' -X 'ems.agt/lib/global.BuildTime=`date`' -X 'ems.agt/lib/global.GoVer=`go version`'"
|
|
|
|
## 第三阶段 ====> 构建前后端融合镜像
|
|
FROM alpine
|
|
|
|
## 安装时区工具
|
|
RUN apk add --no-cache tzdata nginx openssh \
|
|
&& ssh-keygen -A \
|
|
&& adduser -D sshuser \
|
|
&& echo 'sshuser:password' | chpasswd \
|
|
&& mkdir /home/sshuser/.ssh \
|
|
&& chmod 700 /home/sshuser/.ssh
|
|
|
|
# 设置时区和语言环境
|
|
ENV TZ="Asia/Shanghai"
|
|
ENV LANG="en_US.UTF-8"
|
|
|
|
WORKDIR /usr/local/omc
|
|
COPY --from=buildNode /frontend/dist /usr/local/omc/bin/frontend
|
|
COPY --from=buildGo /backend/restagent/omc /usr/local/omc/bin/backend
|
|
COPY --from=buildGo /backend/docker/config.yaml /usr/local/omc/etc/config.yaml
|
|
COPY --from=buildGo /backend/docker/nginx.conf /etc/nginx/nginx.conf
|
|
|
|
EXPOSE 3030 80 22
|
|
|
|
CMD ["/usr/sbin/sshd", "-D", ";", "nginx", "-g", "daemon off;", ";", "/usr/local/omc/bin/backend", "--env", "prod", "-c", "/usr/local/omc/etc/config.yaml"]
|