From e103e33ccb586eeeb278ba6ca139183d6934b386 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 22 Apr 2024 17:33:17 +0800 Subject: [PATCH] refactor --- Dockerfile | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 78e669bff9..1ad0165f9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,37 @@ -# Use Go 1.21 as the base image +# Use Go 1.21 as the base image for building the application FROM golang:1.21 as builder -# Set the working directory +# Set the working directory inside the container WORKDIR /openim-server +# Set the Go proxy to improve dependency resolution speed ENV GOPROXY=https://goproxy.cn,direct -# Copy all files from the current directory to the image +# Copy all files from the current directory into the container COPY . . -# Execute the script and build command +# Execute the script and build command, including downloading mage RUN chmod +x ./bootstrap.sh && \ ./bootstrap.sh && \ mage build -# Use scratch as the base image for the minimal production image -FROM scratch +# Use Alpine Linux as the final base image due to its small size and included utilities +FROM alpine:latest -# Copy the compiled binaries from the builder image to the production image +# Install necessary packages, such as bash, to ensure compatibility and functionality +RUN apk add --no-cache bash + +# Copy the compiled binaries and mage from the builder image to the final image COPY --from=builder /openim-server/_output /openim-server/_output +COPY --from=builder /root/go/bin/mage /usr/local/bin/mage -# Set the working directory +# Set the working directory to /openim-server within the container WORKDIR /openim-server -# Set up volume mounts for the config directory and logs directory +# Set up volume mounts for the configuration directory and logs directory VOLUME ["/openim-server/config", "/openim-server/_output/logs"] +# Set the command to run when the container starts +ENTRYPOINT ["sh", "-c", "mage start && tail -f /dev/null"] + +