Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the Dockerfile. #502

Merged
merged 41 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
69e3701
refactor dockerFile
skiffer-git Apr 22, 2024
0ed15f9
refactor dockerFile
skiffer-git Apr 22, 2024
d3f501a
refactor dockerFile
skiffer-git Apr 22, 2024
6e7297f
refactor dockerFile
skiffer-git Apr 23, 2024
f61d4e8
refactor dockerFile
skiffer-git Apr 23, 2024
b191311
refactor dockerFile
skiffer-git Apr 23, 2024
92c39e2
refactor dockerFile
skiffer-git Apr 23, 2024
6fa845d
refactor dockerFile
skiffer-git Apr 23, 2024
03abb30
refactor dockerFile
skiffer-git Apr 23, 2024
9e5fba8
refactor dockerFile
skiffer-git Apr 23, 2024
ac12c23
refactor dockerFile
skiffer-git Apr 23, 2024
2f560dc
refactor dockerFile
skiffer-git Apr 23, 2024
7d20082
refactor dockerFile
skiffer-git Apr 23, 2024
08cc727
refactor dockerFile
skiffer-git Apr 23, 2024
005617e
refactor dockerFile
skiffer-git Apr 23, 2024
762de2d
refactor dockerFile
skiffer-git Apr 23, 2024
1c517e4
refactor dockerFile
skiffer-git Apr 23, 2024
8e28492
refactor dockerFile
skiffer-git Apr 23, 2024
e6efeed
refactor dockerFile
skiffer-git Apr 23, 2024
66a2ba9
refactor dockerFile
skiffer-git Apr 23, 2024
76ca440
refactor dockerFile
skiffer-git Apr 23, 2024
a0ddd4e
refactor dockerFile
skiffer-git Apr 23, 2024
0fb98fe
refactor dockerFile
skiffer-git Apr 23, 2024
1544cd8
refactor dockerFile
skiffer-git Apr 23, 2024
803aca4
refactor dockerFile
skiffer-git Apr 23, 2024
560fd75
refactor dockerFile
skiffer-git Apr 23, 2024
48f245a
refactor dockerFile
skiffer-git Apr 23, 2024
8df6381
refactor dockerFile
skiffer-git Apr 23, 2024
7642345
refactor dockerFile
skiffer-git Apr 23, 2024
6b5106b
refactor dockerFile
skiffer-git Apr 23, 2024
b34632d
refactor dockerFile
skiffer-git Apr 23, 2024
4841b03
refactor dockerFile
skiffer-git Apr 23, 2024
855010a
refactor dockerFile
skiffer-git Apr 23, 2024
91b2f7a
refactor dockerFile
skiffer-git Apr 23, 2024
87e74cb
refactor dockerFile
skiffer-git Apr 23, 2024
154f9c9
refactor dockerFile
skiffer-git Apr 23, 2024
40f4ebf
refactor dockerFile
skiffer-git Apr 23, 2024
9364aaa
refactor dockerFile
skiffer-git Apr 23, 2024
657201b
refactor dockerFile
skiffer-git Apr 23, 2024
ebca825
refactor dockerFile
skiffer-git Apr 23, 2024
7f9222d
refactor dockerFile
skiffer-git Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
.dockerignore

# Ignore build artifacts
_output/
logs/
_output/

# Ignore non-essential documentation
README.md
Expand All @@ -17,8 +17,6 @@ CHANGELOG/
# Ignore testing and linting configuration
.golangci.yml

# Ignore deployment-related files
docker-compose.yaml

# Ignore assets
assets/
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,3 @@ dist
# config files, may contain sensitive informatio
config/config.yaml

start-config.yml
83 changes: 42 additions & 41 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/[email protected]

# 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/[email protected]

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"]
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 8 additions & 0 deletions start-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
serviceBinaries:
chat-api: 1
chat-rpc: 1
admin-api: 1
admin-rpc: 1
toolBinaries:
- check-component
maxFileDescriptors: 10000
Loading