From f1989abedb077f519b658abaa00f4f4ab0d1f680 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Fri, 28 Jul 2023 10:17:58 +0800 Subject: [PATCH] feat: add multi-architecture mirroring Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- Dockerfile | 50 +++++++++++++++++++++++++------------------------ Dockerfile_test | 26 ------------------------- 2 files changed, 26 insertions(+), 50 deletions(-) delete mode 100644 Dockerfile_test diff --git a/Dockerfile b/Dockerfile index 36557c05a..3decabdc6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,7 @@ -# Use the official Golang image as a build environment -# docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/openimsdk/openim-chat:v1.0.1 . --push +# Use golang as the builder stage +FROM golang:1.20 as builder -FROM golang:1.20 AS builder - -WORKDIR /app - -ARG GOARCH -ARG GOOS +WORKDIR /workspace ENV GOPROXY=https://goproxy.cn @@ -14,33 +9,40 @@ ENV GOPROXY=https://goproxy.cn COPY go.mod go.sum ./ RUN go mod download +ARG GOARCH +ARG GOOS + # Copy source code files into the image COPY . . # Compile the source code -RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o open_im_admin ./cmd/rpc/admin -RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o open_im_admin_api ./cmd/api/admin_api -RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o open_im_chat ./cmd/rpc/chat -RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o open_im_chat_api ./cmd/api/chat_api +RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_admin ./cmd/rpc/admin +RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_admin_api ./cmd/api/admin_api +RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_chat ./cmd/rpc/chat +RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_chat_api ./cmd/api/chat_api -# Create a new image layer using scratch, copy the built binary files into it -FROM alpine:latest -# Create some directories for mounting, add execution permissions -RUN mkdir -p $WORKDIR/logs \ - && chmod +x $WORKDIR/bin/open_im_admin $WORKDIR/bin/open_im_chat $WORKDIR/bin/open_im_admin_api $WORKDIR/bin/open_im_chat_api \ - && apk --no-cache add ca-certificates curl +# Build the runtime stage +FROM debian +# Set fixed project path ENV WORKDIR /chat ENV CMDDIR $WORKDIR/scripts ENV CONFIG_NAME $WORKDIR/config/config.yaml -COPY ./scripts $WORKDIR/scripts -COPY ./config/config.yaml $WORKDIR/config/config.yaml -COPY --from=builder /app/open_im_admin $WORKDIR/bin/open_im_admin -COPY --from=builder /app/open_im_admin_api $WORKDIR/bin/open_im_admin_api -COPY --from=builder /app/open_im_chat $WORKDIR/bin/open_im_chat -COPY --from=builder /app/open_im_chat_api $WORKDIR/bin/open_im_chat_api +# Copy the executable files to the target directory +COPY --from=builder /workspace/bin/open_im_admin $WORKDIR/bin/open_im_admin +COPY --from=builder /workspace/bin/open_im_admin_api $WORKDIR/bin/open_im_admin_api +COPY --from=builder /workspace/bin/open_im_chat $WORKDIR/bin/open_im_chat +COPY --from=builder /workspace/bin/open_im_chat_api $WORKDIR/bin/open_im_chat_api +COPY --from=builder /workspace/scripts $WORKDIR/scripts +COPY --from=builder /workspace/config/config.yaml $WORKDIR/config/config.yaml + +# Create several directories for mounting and add executable permissions +RUN mkdir $WORKDIR/logs && \ + chmod +x $WORKDIR/bin/open_im_admin $WORKDIR/bin/open_im_chat $WORKDIR/bin/open_im_admin_api $WORKDIR/bin/open_im_chat_api +RUN apt-get -qq update \ + && apt-get -qq install -y --no-install-recommends ca-certificates curl VOLUME ["/chat/logs","/chat/config","/chat/scripts"] diff --git a/Dockerfile_test b/Dockerfile_test deleted file mode 100644 index c5b7692fb..000000000 --- a/Dockerfile_test +++ /dev/null @@ -1,26 +0,0 @@ -FROM ubuntu - -# 设置固定的项目路径 -ENV WORKDIR /chat -ENV CMDDIR $WORKDIR/scripts - -ENV CONFIG_NAME $WORKDIR/config/config.yaml - -# 将可执行文件复制到目标目录 -ADD ./bin/open_im_admin $WORKDIR/bin/open_im_admin -ADD ./bin/open_im_admin_api $WORKDIR/bin/open_im_admin_api -ADD ./bin/open_im_chat $WORKDIR/bin/open_im_chat -ADD ./bin/open_im_chat_api $WORKDIR/bin/open_im_chat_api -ADD ./scripts $WORKDIR/scripts -ADD ./config/config.yaml $WORKDIR/config/config.yaml - -# 创建用于挂载的几个目录,添加可执行权限 -RUN mkdir $WORKDIR/logs && \ - chmod +x $WORKDIR/bin/open_im_admin $WORKDIR/bin/open_im_chat $WORKDIR/bin/open_im_admin_api $WORKDIR/bin/open_im_chat_api -RUN apt-get -qq update \ - && apt-get -qq install -y --no-install-recommends ca-certificates curl - -VOLUME ["/chat/logs","/chat/config","/chat/scripts"] - -WORKDIR $CMDDIR -CMD ["./docker_start_all.sh"] \ No newline at end of file