This commit is contained in:
skiffer-git 2024-04-22 17:14:57 +08:00
parent c239307f77
commit 6a29662786
2 changed files with 57 additions and 39 deletions

View File

@ -1,30 +1,26 @@
# Build Stage # Use Go 1.21 as the base image
FROM golang:1.20 AS builder FROM golang:1.21 as builder
# Set go mod installation source and proxy # Set the working directory
ARG GO111MODULE=on WORKDIR /openim-server
ENV GO111MODULE=$GO111MODULE # Copy all files from the current directory to the image
ENV GOPROXY=$GOPROXY COPY . .
# Set up the working directory # Execute the script and build command
WORKDIR /openim/openim-server RUN chmod +x ./bootstrap.sh && \
./bootstrap.sh && \
mage build
# Use scratch as the base image for the minimal production image
FROM scratch
# Copy all files to the container # Copy the compiled binaries from the builder image to the production image
ADD . . COPY --from=builder /openim-server/_output /openim-server/_output
RUN Bash bootstrap.sh # Set the working directory
RUN mage WORKDIR /openim-server
FROM ghcr.io/openim-sigs/openim-ubuntu-image:latest # Set up volume mounts for the config directory and logs directory
VOLUME ["/openim-server/config", "/openim-server/_output/logs"]
WORKDIR ${`SERVER_WORKDIR`}
# Copy scripts and binary files to the production image
COPY --from=builder ${OPENIM_SERVER_BINDIR} /openim/openim-server/_output/bin
COPY --from=builder ${OPENIM_SERVER_CMDDIR} /openim/openim-server/scripts
COPY --from=builder ${SERVER_WORKDIR}/config /openim/openim-server/config
COPY --from=builder ${SERVER_WORKDIR}/deployments /openim/openim-server/deployments
CMD ["cd /openim/openim-server/scripts/docker-start-all.sh"]

View File

@ -1,26 +1,48 @@
# Use Go 1.21 as the base image # Copyright © 2023 OpenIM. All rights reserved.
FROM golang:1.21 as builder #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Set the working directory # OpenIM base image: https://github.com/openim-sigs/openim-base-image
WORKDIR /openim-server
# Set go mod installation source and proxy
FROM golang:1.20 AS builder
ARG GO111MODULE=on
WORKDIR /openim/openim-server
ENV GO111MODULE=$GO111MODULE
ENV GOPROXY=$GOPROXY
COPY go.mod go.sum ./
RUN go mod download
# Copy all files from the current directory to the image
COPY . . COPY . .
# Execute the script and build command RUN make clean
RUN chmod +x ./bootstrap.sh && \ RUN make build BINS=component
./bootstrap.sh && \
mage build
# Use scratch as the base image for the minimal production image # FROM ghcr.io/openim-sigs/openim-bash-image:latest
FROM scratch FROM ghcr.io/openim-sigs/openim-bash-image:latest
# Copy the compiled binaries from the builder image to the production image WORKDIR /openim/openim-server
COPY --from=builder /openim-server/_output /openim-server/_output
# Set the working directory COPY --from=builder /openim/openim-server/_output/bin/tools /openim/openim-server/_output/bin/tools/
WORKDIR /openim-server COPY --from=builder /openim/openim-server/config /openim/openim-server/config
# Set up volume mounts for the config directory and logs directory ENV OPENIM_SERVER_CONFIG_NAME=/openim/openim-server/config
VOLUME ["/openim-server/config", "/openim-server/_output/logs"]
RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/component /usr/bin/component
ENTRYPOINT ["bash", "-c", "component -c $OPENIM_SERVER_CONFIG_NAME"]