diff --git a/.dockerignore b/.dockerignore index a118b899f..b52db5740 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,8 +4,8 @@ .dockerignore # Ignore build artifacts -_output/ logs/ +_output/ # Ignore non-essential documentation README.md @@ -17,8 +17,6 @@ CHANGELOG/ # Ignore testing and linting configuration .golangci.yml -# Ignore deployment-related files -docker-compose.yaml # Ignore assets assets/ diff --git a/.gitignore b/.gitignore index ea171e8a3..811715820 100644 --- a/.gitignore +++ b/.gitignore @@ -374,4 +374,3 @@ dist # config files, may contain sensitive informatio config/config.yaml -start-config.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2ecf60a70..52e184104 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,48 +1,49 @@ -# Copyright © 2023 OpenIM open source community. 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. - -ARG GOARCH -ARG GOOS - -# Use golang as the builder stage -FROM golang:1.21 AS builder - -ARG GO111MODULE=on -ARG GOPROXY=https://goproxy.io,direct - -WORKDIR /openim/openim-chat - -ENV GO111MODULE=$GO111MODULE -ENV GOPROXY=$GOPROXY - -COPY go.mod go.sum ./ +# Use Go 1.21 Alpine as the base image for building the application +FROM golang:1.21-alpine as builder + +# Define the base directory for the application as an environment variable +ENV SERVER_DIR=/openim-chat + +# Set the working directory inside the container based on the environment variable +WORKDIR $SERVER_DIR + +# Set the Go proxy to improve dependency resolution speed +ENV GOPROXY=https://goproxy.io,direct + +# Copy all files from the current directory into the container +COPY . . + RUN go mod download -# Copy all files to the container -ADD . . +# Install Mage to use for building the application +RUN go install github.com/magefile/mage@v1.15.0 + +# Optionally build your application if needed +RUN mage build + +# Using Alpine Linux with Go environment for the final image +FROM golang:1.21-alpine + +# Install necessary packages, such as bash +RUN apk add --no-cache bash -RUN make clean -RUN make build +# Set the environment and work directory +ENV SERVER_DIR=/openim-chat +WORKDIR $SERVER_DIR -# Build the runtime stage -FROM ghcr.io/openim-sigs/openim-ubuntu-image:latest -WORKDIR ${CHAT_WORKDIR} +# Copy the compiled binaries and mage from the builder image to the final image +COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output +COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config +COPY --from=builder /go/bin/mage /usr/local/bin/mage +COPY --from=builder $SERVER_DIR/magefile_windows.go $SERVER_DIR/ +COPY --from=builder $SERVER_DIR/magefile_unix.go $SERVER_DIR/ +COPY --from=builder $SERVER_DIR/magefile.go $SERVER_DIR/ +COPY --from=builder $SERVER_DIR/start-config.yml $SERVER_DIR/ +COPY --from=builder $SERVER_DIR/go.mod $SERVER_DIR/ +COPY --from=builder $SERVER_DIR/go.sum $SERVER_DIR/ -COPY --from=builder ${OPENIM_CHAT_BINDIR} /openim/openim-chat/_output/bin -COPY --from=builder ${CHAT_WORKDIR}/config /openim/openim-chat/config -COPY --from=builder ${CHAT_WORKDIR}/scripts /openim/openim-chat/scripts -COPY --from=builder ${CHAT_WORKDIR}/deployments /openim/openim-chat/deployments +RUN go get github.com/openimsdk/gomake@v0.0.9-alpha.3 -CMD ["/openim/openim-chat/scripts/docker-start-all.sh"] +# Set the command to run when the container starts +ENTRYPOINT ["sh", "-c", "mage start && tail -f /dev/null"] diff --git a/go.mod b/go.mod index 1357fd854..840a9d5a7 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( require ( github.com/livekit/protocol v1.10.1 github.com/mitchellh/mapstructure v1.5.0 - github.com/openimsdk/gomake v0.0.6 + github.com/openimsdk/gomake v0.0.9-alpha.3 github.com/openimsdk/protocol v0.0.63 github.com/openimsdk/tools v0.0.48 github.com/redis/go-redis/v9 v9.5.1 diff --git a/go.sum b/go.sum index d4c9121bb..c359fd5d7 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADym github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/openimsdk/gomake v0.0.6 h1:bJmQWDHBj8PQ7oGJ2SL3Gsx0k5CdI/BPfGzlGcV105s= -github.com/openimsdk/gomake v0.0.6/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= +github.com/openimsdk/gomake v0.0.9-alpha.3 h1:KO3stbmiTksnnx2o2Lh8/FkKXc7qiF4rwPnr01WO7aM= +github.com/openimsdk/gomake v0.0.9-alpha.3/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= github.com/openimsdk/protocol v0.0.63 h1:9DnweZe9nEYDFa4fGTbC9Cqi0gLUdtBhRo1NRP2X3WQ= github.com/openimsdk/protocol v0.0.63/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8= github.com/openimsdk/tools v0.0.48 h1:GgRtYtMNlJ0PzCR9XQzMVDv7O+Sp8Hg9Grrlnh8HFGE= diff --git a/start-config.yml b/start-config.yml new file mode 100644 index 000000000..b5b8ddc55 --- /dev/null +++ b/start-config.yml @@ -0,0 +1,8 @@ +serviceBinaries: + chat-api: 1 + chat-rpc: 1 + admin-api: 1 + admin-rpc: 1 +toolBinaries: + - check-component +maxFileDescriptors: 10000