FROM golang:1.22-alpine AS buildGo

ARG VERSION

ENV CGO_ENABLED 1
ENV GOOS linux
ENV GOPROXY https://goproxy.cn,direct

## 安装时区工具
RUN apk add --no-cache gcc musl-dev libpcap-dev tzdata openssh \
    && ssh-keygen -A \
    && adduser -D omcuser \
    && echo 'omcuser:password' | chpasswd \
    && mkdir /home/omcuser/.ssh \
    && chmod 700 /home/omcuser/.ssh

# 设置时区和语言环境
ENV TZ="Asia/Shanghai"
ENV LANG="en_US.UTF-8"

WORKDIR /backend

## 复制实际需要的文件到工作目录
COPY ./restagent/config ./restagent/config
COPY ./restagent/etc ./restagent/etc
COPY ./restagent/restagent.go ./restagent/restagent.go
COPY ./features ./features
COPY ./lib ./lib
COPY ./src ./src
COPY ./go.sum ./
COPY ./go.mod ./ 

RUN cd /backend && go mod download
RUN cd /backend/restagent && go build -o omc_api -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`'"

EXPOSE 33030 33033 33040 80 22

CMD [ "/backend/restagent/omc_api", "--env", "prod", "-c", "/backend/restagent/etc/restconf.yaml"]

# 构建
# docker build --build-arg VERSION=241031 -t omc:2.241031 .
# docker run -it omc:2.241031 sh
# /backend/restagent/omc_api --env prod -c /backend/restagent/etc/restconf.yaml