96 lines
3.2 KiB
Docker
96 lines
3.2 KiB
Docker
## 第一阶段 ====> Nodejs打包编译输出前端资源
|
|
FROM node:20-alpine AS build-node
|
|
|
|
# 系统文件
|
|
COPY ./linux /linux
|
|
# 后端程序
|
|
COPY ./omc_api /api
|
|
# 前端程序
|
|
COPY ./omc_web /web
|
|
RUN npm config set registry https://registry.npmmirror.com
|
|
RUN cd /web && npm install && npm run build
|
|
|
|
|
|
## 第二阶段 ====> Go打包编译输出后端程序
|
|
FROM ubuntu:22.04 AS build-golang
|
|
ARG TARGETARCH
|
|
ARG VERSION
|
|
|
|
# 从上个阶段复制文件
|
|
COPY --from=build-node /web/dist /web
|
|
COPY --from=build-node /api /api
|
|
COPY --from=build-node /linux /linux
|
|
|
|
# 安装 Go 和其他依赖
|
|
RUN apt-get update && \
|
|
apt-get install -y build-essential libpcap-dev curl \
|
|
&& curl -OL https://dl.google.com/go/go1.24.2.linux-$TARGETARCH.tar.gz \
|
|
&& tar -C /usr/local -xzf go1.24.2.linux-$TARGETARCH.tar.gz \
|
|
&& rm go1.24.2.linux-$TARGETARCH.tar.gz \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 设置变量
|
|
ENV PATH="/usr/local/go/bin:${PATH}"
|
|
ENV OS_ARCH="${TARGETARCH:-amd64}"
|
|
ENV CGO_ENABLED=1
|
|
ENV GOOS=linux
|
|
ENV GOPROXY=https://goproxy.cn,direct
|
|
|
|
RUN cd /api && go mod download
|
|
RUN cd /api && go build -o omc -v -ldflags "-s -w \
|
|
-X 'be.ems/src/framework/config.Version=$VERSION' \
|
|
-X 'be.ems/src/framework/config.BuildTime=$(date)' \
|
|
-X 'be.ems/src/framework/config.GoVer=$(go version)'"
|
|
# RUN cd /api/sshsvc && go build -o sshsvc -v -ldflags "-s -w \
|
|
# -X 'be.ems/lib/global.Version=$VERSION' \
|
|
# -X 'be.ems/lib/global.BuildTime=$(date)' \
|
|
# -X 'be.ems/lib/global.GoVer=$(go version)'"
|
|
|
|
|
|
## 第三阶段 ====> 构建前后端融合镜像
|
|
FROM ubuntu:22.04
|
|
|
|
# 从上个阶段复制文件
|
|
COPY --from=build-golang /linux/usr/local/etc/omc /usr/local/etc/omc
|
|
COPY --from=build-golang /linux/usr/local/omc /usr/local/omc
|
|
COPY --from=build-golang /api/omc /usr/local/bin/omc
|
|
# COPY --from=build-golang /api/sshsvc/sshsvc /usr/local/bin/sshsvc
|
|
COPY --from=build-golang /web /usr/local/etc/omc/web
|
|
|
|
# 更新apt并安装必要工具
|
|
RUN apt-get update && apt-get install -y libpcap-dev nginx
|
|
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
|
|
RUN apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
|
|
# 设置时区和语言环境
|
|
ENV LANG="en_US.UTF-8"
|
|
ENV TZ="Asia/Shanghai"
|
|
WORKDIR /usr/local/etc/omc
|
|
|
|
SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-c"]
|
|
RUN chmod +x /usr/local/etc/omc/script/*.sh
|
|
RUN /usr/local/etc/omc/script/postunpack.sh
|
|
|
|
EXPOSE 80 443 33030 33443 33033 33034 33060
|
|
|
|
CMD [ "/usr/local/etc/omc/script/entrypoint.sh" ]
|
|
|
|
# build 546 MB
|
|
# docker docker build --platform linux/amd64 --build-arg TARGETARCH=amd64 --build-arg VERSION=2.2505.2 -t omc:r2.2505.2-ubuntu22.04-amd64 .
|
|
|
|
# service ssh start && service nginx start && /usr/local/bin/omc --env prod -c /usr/local/etc/omc/omc.yaml
|
|
# docker run -it omc:2.2505.2-ubuntu22.04-amd64 /bin/bash
|
|
|
|
# docker run --privileged=true --restart=always -m 512M -e M_PARAM=lite --name omc_2.2505.2 -d omc:2.2505.2-ubuntu22.04-amd64
|
|
# docker run --privileged=true --restart=always -m 512M \
|
|
# -e TZ=Asia/Shanghai \
|
|
# -e M_PARAM=lite \
|
|
# -p 80:80 \
|
|
# -p 443:443 \
|
|
# --network omcnet \
|
|
# --name omc \
|
|
# -d omc:2.2505.2-ubuntu22.04-amd64
|
|
# docker rm -f omc_2.2505.2
|
|
# docker run -it omc_2.2505.2 bash
|