✨ add Dockerfile
This commit is contained in:
120
Dockerfile
Normal file
120
Dockerfile
Normal file
@@ -0,0 +1,120 @@
|
||||
# to build this docker image:
|
||||
# docker build -f Dockerfile -t schisandra-cloud-album-server .
|
||||
# docker build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile -t schisandra-cloud-album-server .
|
||||
|
||||
FROM ubuntu:20.04 AS opencv-builder
|
||||
|
||||
LABEL maintainer="landaiqing <<landaiqing@126.com>>"
|
||||
|
||||
RUN sed -i 's|http://archive.ubuntu.com/ubuntu/|http://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list
|
||||
|
||||
ENV TZ=Europe/Madrid
|
||||
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
|
||||
tzdata git build-essential cmake pkg-config wget unzip libgtk2.0-dev \
|
||||
curl ca-certificates libcurl4-openssl-dev libssl-dev \
|
||||
libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \
|
||||
libharfbuzz-dev libfreetype6-dev \
|
||||
libjpeg-turbo8-dev libpng-dev libtiff-dev libdc1394-22-dev nasm && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG OPENCV_VERSION="4.10.0"
|
||||
|
||||
ENV OPENCV_VERSION=$OPENCV_VERSION
|
||||
|
||||
ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip"
|
||||
|
||||
ENV OPENCV_FILE=$OPENCV_FILE
|
||||
|
||||
ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip"
|
||||
|
||||
ENV OPENCV_CONTRIB_FILE=$OPENCV_CONTRIB_FILE
|
||||
|
||||
RUN curl -Lo opencv.zip ${OPENCV_FILE} && \
|
||||
unzip -q opencv.zip && \
|
||||
curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \
|
||||
unzip -q opencv_contrib.zip && \
|
||||
rm opencv.zip opencv_contrib.zip && \
|
||||
cd opencv-${OPENCV_VERSION} && \
|
||||
mkdir build && cd build && \
|
||||
cmake -D CMAKE_BUILD_TYPE=RELEASE \
|
||||
-D WITH_IPP=OFF \
|
||||
-D WITH_OPENGL=OFF \
|
||||
-D WITH_QT=OFF \
|
||||
-D WITH_FREETYPE=ON \
|
||||
-D CMAKE_INSTALL_PREFIX=/usr/local \
|
||||
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \
|
||||
-D OPENCV_ENABLE_NONFREE=ON \
|
||||
-D WITH_JASPER=OFF \
|
||||
-D WITH_TBB=ON \
|
||||
-D BUILD_JPEG=ON \
|
||||
-D WITH_SIMD=ON \
|
||||
-D ENABLE_LIBJPEG_TURBO_SIMD=ON \
|
||||
-D BUILD_DOCS=OFF \
|
||||
-D BUILD_EXAMPLES=OFF \
|
||||
-D BUILD_TESTS=OFF \
|
||||
-D BUILD_PERF_TESTS=ON \
|
||||
-D BUILD_opencv_java=NO \
|
||||
-D BUILD_opencv_python=NO \
|
||||
-D BUILD_opencv_python2=NO \
|
||||
-D BUILD_opencv_python3=NO \
|
||||
-D OPENCV_GENERATE_PKGCONFIG=ON .. && \
|
||||
make -j $(nproc --all) && \
|
||||
make preinstall && make install && ldconfig && \
|
||||
cd / && rm -rf opencv*
|
||||
|
||||
|
||||
FROM golang:1.23.1-alpine AS go-builder
|
||||
|
||||
RUN apk add --no-cache gcc musl-dev libgcc libstdc++ cmake
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
ENV CGO_ENABLED=1
|
||||
|
||||
ENV CGO_CFLAGS="-I/usr/local/include/opencv4"
|
||||
|
||||
ENV CGO_LDFLAGS="-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui"
|
||||
|
||||
ENV GOOS=linux
|
||||
|
||||
ENV GOARCH=amd64
|
||||
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
COPY --from=opencv-builder /usr/local/lib /usr/local/lib
|
||||
COPY --from=opencv-builder /usr/local/include/opencv4 /usr/local/include/opencv4
|
||||
|
||||
RUN go mod download
|
||||
|
||||
RUN go build -o schisandra-cloud-album-server
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
|
||||
RUN apk add --no-cache tzdata
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=go-builder /app/schisandra-cloud-album-server .
|
||||
|
||||
COPY --from=go-builder /app/config.yaml .
|
||||
|
||||
COPY --from=go-builder /app/resource ./resource
|
||||
|
||||
COPY --from=go-builder /app/config/rbac_model.conf ./config/rbac_model.conf
|
||||
|
||||
COPY --from=opencv-builder /usr/local/lib /usr/local/lib
|
||||
|
||||
COPY --from=opencv-builder /usr/local/include/opencv4 /usr/local/include/opencv4
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["./schisandra-cloud-album-server"]
|
@@ -3,14 +3,16 @@ package message_ws_controller
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/lxzan/gws"
|
||||
"net/http"
|
||||
|
||||
"schisandra-cloud-album/common/constant"
|
||||
"schisandra-cloud-album/common/redis"
|
||||
"schisandra-cloud-album/global"
|
||||
"schisandra-cloud-album/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MessageWebsocketController struct {
|
||||
@@ -28,9 +30,9 @@ type WebSocket struct {
|
||||
|
||||
var MessageHandler = MessageWebSocket()
|
||||
|
||||
// MessageWSController 创建websocket服务
|
||||
// @Summary 创建websocket服务
|
||||
// @Description 创建websocket服务
|
||||
// MessageWSController 消息通知websocket服务
|
||||
// @Summary 消息通知websocket服务
|
||||
// @Description 消息通知websocket服务
|
||||
// @Tags websocket
|
||||
// @Router /controller/ws/gws [get]
|
||||
func (MessageWebsocketController) MessageWSController(c *gin.Context) {
|
||||
@@ -94,7 +96,7 @@ func (c *WebSocket) OnOpen(socket *gws.Conn) {
|
||||
c.sessions.Store(clientId, socket)
|
||||
// 订阅该用户的频道
|
||||
go c.subscribeUserChannel(clientId)
|
||||
//fmt.Printf("websocket client %s connected\n", clientId)
|
||||
// fmt.Printf("websocket client %s connected\n", clientId)
|
||||
}
|
||||
|
||||
// OnClose 关闭连接
|
||||
@@ -105,7 +107,7 @@ func (c *WebSocket) OnClose(socket *gws.Conn, err error) {
|
||||
sharding.Lock()
|
||||
defer sharding.Unlock()
|
||||
|
||||
//global.LOG.Printf("onerror, name=%s, msg=%s\n", name, err.Error())
|
||||
// global.LOG.Printf("onerror, name=%s, msg=%s\n", name, err.Error())
|
||||
}
|
||||
|
||||
// OnPing 处理客户端的Ping消息
|
||||
|
@@ -27,9 +27,9 @@ type WebSocket struct {
|
||||
|
||||
var Handler = NewWebSocket()
|
||||
|
||||
// QrWebsocket 创建websocket服务
|
||||
// @Summary 创建websocket服务
|
||||
// @Description 创建websocket服务
|
||||
// QrWebsocket 登录websocket服务
|
||||
// @Summary 登录websocket服务
|
||||
// @Description 登录websocket服务
|
||||
// @Tags websocket
|
||||
// @Router /controller/ws/gws [get]
|
||||
func (QrWebsocketController) QrWebsocket(c *gin.Context) {
|
||||
|
@@ -73,6 +73,7 @@ func JWTAuthMiddleware() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
c.Set("userId", parseToken.UserID)
|
||||
global.DB.Set("user_id", parseToken.UserID) // 全局变量中设置用户ID
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -42,3 +43,16 @@ func (user *ScaAuthUser) MarshalBinary() ([]byte, error) {
|
||||
func (user *ScaAuthUser) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, user)
|
||||
}
|
||||
func (user *ScaAuthUser) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
user.CreatedBy = "system"
|
||||
return
|
||||
}
|
||||
|
||||
func (user *ScaAuthUser) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
currentUserID, b := tx.Get("user_id")
|
||||
if !b {
|
||||
return
|
||||
}
|
||||
user.UpdateBy = currentUserID.(string)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user