feat: update openim-web

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
Xinwei Xiong(cubxxw-openim) 2 years ago
parent 4281600e0d
commit 63861e29ff
No known key found for this signature in database
GPG Key ID: 1BAD6F395338EFDE

@ -0,0 +1,59 @@
# 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.
# 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
ARG GOPROXY=https://goproxy.cn,direct
WORKDIR /openim/openim-server
ENV GO111MODULE=$GO111MODULE
ENV GOPROXY=$GOPROXY
RUN apt-get update && apt-get install -y curl unzip
RUN curl -LO https://app-1302656840.cos.ap-nanjing.myqcloud.com/dist.zip \
&& unzip dist.zip -d ./ \
&& rm dist.zip
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make clean
RUN make build BINS=openim-web
FROM ghcr.io/openim-sigs/openim-ubuntu-image:latest
WORKDIR /openim/openim-server
COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/
COPY --from=builder /app/dist /app/dist
ENV PORT 11001
ENV DISTPATH /app/dist
EXPOSE $PORT
RUN cp -r ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-web /usr/bin/openim-web
ENTRYPOINT ["bash", "-c", "openim-web -port $PORT"]
CMD ["-distPath","/app/dist"]

@ -54,6 +54,7 @@ require (
cloud.google.com/go/iam v1.1.1 // indirect cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/longrunning v0.5.1 // indirect cloud.google.com/go/longrunning v0.5.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect cloud.google.com/go/storage v1.30.1 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect github.com/bytedance/sonic v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect

@ -17,6 +17,8 @@ cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7Biccwk
firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4=
firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/OpenIMSDK/protocol v0.0.15 h1:KrrvdHH9kFF/tFYL2FXRPAr2e5F5DctSHfHq6MQjUI4= github.com/OpenIMSDK/protocol v0.0.15 h1:KrrvdHH9kFF/tFYL2FXRPAr2e5F5DctSHfHq6MQjUI4=
github.com/OpenIMSDK/protocol v0.0.15/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= github.com/OpenIMSDK/protocol v0.0.15/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ= github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ=

@ -8,6 +8,6 @@ use (
./tools/infra ./tools/infra
./tools/ncpu ./tools/ncpu
./tools/versionchecker ./tools/versionchecker
./tools/web ./tools/openim-web
./tools/yamlfmt ./tools/yamlfmt
) )

@ -0,0 +1,33 @@
# 使用官方Go镜像作为基础镜像
FROM golang:1.21 AS build-env
ENV CGO_ENABLED=0
# 设置工作目录
WORKDIR /app
# 安装curl和unzip工具
#RUN apt-get update && apt-get install -y curl unzip
# 从GitHub下载并解压dist.zip
#RUN curl -LO https://github.com/OpenIMSDK/dist.zip \
# && unzip dist.zip -d ./ \
# && rm dist.zip
# 复制Go代码到容器
COPY . .
# 编译Go代码
RUN go build -o openim-web
# 使用轻量级的基础镜像
FROM debian:buster-slim
# 将编译好的二进制文件和dist资源复制到新的容器
WORKDIR /app
COPY --from=build-env /app/openim-web /app/openim-web
COPY --from=build-env /app/dist /app/dist
# 开放容器的20001端口
EXPOSE 20001
# 指定容器启动命令
ENTRYPOINT ["/app/openim-web"]

@ -24,14 +24,29 @@ OpenIM Web Service is a lightweight containerized service built with Go. The ser
example example
```bash ```bash
# ./web -h $ ./openim-web -h
Usage of ./web: Usage of ./openim-web:
-distPath string -distPath string
Path to the distribution (default "/app/dist") Path to the distribution (default "/app/dist")
-port string -port string
Port to run the server on (default "20001") Port to run the server on (default "20001")
``` ```
Variables can be set as above, Environment variables can also be set
example:
```bash
$ export OPENIM_WEB_DIST_PATH="/app/dist"
$ export OPENIM_WEB_PPRT="11001"
```
Initialize the env configuration file:
```bash
$ make init
```
## Docker Deployment ## Docker Deployment
### Build the Docker Image ### Build the Docker Image
@ -40,16 +55,16 @@ Even though we've implemented automation, it's to make the developer experience
To build the Docker image for OpenIM Web Service: To build the Docker image for OpenIM Web Service:
``` ```bash
docker build -t openim-web . $ docker build -t openim-web .
``` ```
### Run the Docker Container ### Run the Docker Container
To run the service: To run the service:
``` ```bash
docker run -e DIST_PATH=/app/dist -e PORT=20001 -p 20001:20001 openim-web $ docker run -e DIST_PATH=/app/dist -e PORT=20001 -p 20001:20001 openim-web
``` ```
## Configuration ## Configuration

@ -0,0 +1,7 @@
module github.com/OpenIMSDK/Open-IM-Server/tools/openim-web
go 1.18
require gopkg.in/yaml.v2 v2.4.0
require github.com/NYTimes/gziphandler v1.1.1 // indirect

@ -0,0 +1,10 @@
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

@ -5,6 +5,8 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"github.com/NYTimes/gziphandler"
) )
var ( var (
@ -22,7 +24,10 @@ func main() {
distPath := getConfigValue("DIST_PATH", distPathFlag, "/app/dist") distPath := getConfigValue("DIST_PATH", distPathFlag, "/app/dist")
fs := http.FileServer(http.Dir(distPath)) fs := http.FileServer(http.Dir(distPath))
http.Handle("/", fs)
withGzip := gziphandler.GzipHandler(fs)
http.Handle("/", withGzip)
port := getConfigValue("PORT", portFlag, "11001") port := getConfigValue("PORT", portFlag, "11001")
log.Printf("Server listening on port %s in %s...", port, distPath) log.Printf("Server listening on port %s in %s...", port, distPath)

@ -1,5 +0,0 @@
module github.com/OpenIMSDK/Open-IM-Server/tools/web
go 1.18
require gopkg.in/yaml.v2 v2.4.0

@ -1,4 +0,0 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Loading…
Cancel
Save