diff --git a/build/images/openim-tools/component/Dockerfile b/build/images/openim-tools/component/Dockerfile index 6bdfa6942..c419418ca 100644 --- a/build/images/openim-tools/component/Dockerfile +++ b/build/images/openim-tools/component/Dockerfile @@ -1,48 +1,26 @@ -# Copyright © 2023 OpenIM. All rights reserved. -# -# 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. +# Use Go 1.21 as the base image +FROM golang:1.21 as builder -# OpenIM base image: https://github.com/openim-sigs/openim-base-image - -# 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 +# Set the working directory +WORKDIR /openim-server +# Copy all files from the current directory to the image COPY . . -RUN make clean -RUN make build BINS=component - -# FROM ghcr.io/openim-sigs/openim-bash-image:latest -FROM ghcr.io/openim-sigs/openim-bash-image:latest +# Execute the script and build command +RUN chmod +x ./bootstrap.sh && \ + ./bootstrap.sh && \ + mage build -WORKDIR /openim/openim-server +# Use scratch as the base image for the minimal production image +FROM scratch -COPY --from=builder /openim/openim-server/_output/bin/tools /openim/openim-server/_output/bin/tools/ -COPY --from=builder /openim/openim-server/config /openim/openim-server/config +# Copy the compiled binaries from the builder image to the production image +COPY --from=builder /openim-server/_output /openim-server/_output -ENV OPENIM_SERVER_CONFIG_NAME=/openim/openim-server/config +# Set the working directory +WORKDIR /openim-server -RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/component /usr/bin/component +# Set up volume mounts for the config directory and logs directory +VOLUME ["/openim-server/config", "/openim-server/_output/logs"] -ENTRYPOINT ["bash", "-c", "component -c $OPENIM_SERVER_CONFIG_NAME"]