From f703b14b5ef73d0b205530724a79bddba91d89d9 Mon Sep 17 00:00:00 2001 From: xiabin Date: Tue, 21 Jan 2025 18:03:59 +0800 Subject: [PATCH] add DockerFile --- README.md | 2 ++ docker-compose.yaml | 27 ++++++++++++++-------- game_open_api/Dockerfile | 33 +++++++++++++++++++++++++++ game_open_api/etc/compose_config.yaml | 22 ++++++++++++++++++ 4 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 game_open_api/Dockerfile create mode 100644 game_open_api/etc/compose_config.yaml diff --git a/README.md b/README.md index 697d734..2146600 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,6 @@ goctl api go -api .\game_open_api\app_user.api -dir .\game_open_api\ --style=go_ goctl rpc protoc .\dw_server\dw_server.proto --go-grpc_out .\dw_server\ --go_out .\dw_server\ --zrpc_out .\dw_server\ -c -style go_zero + +docker exec -i mysql mysqldump -uroot -p'youtu!0113' ecpm > ecpm_backup.sql ``` \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 3cffdb4..f60641c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,13 +16,11 @@ services: MYSQL_DATABASE: ecpm volumes: #数据目录,要确保先创建好 - - ./data/mysql/data:/var/lib/mysql - - ./data/mysql/logs:/var/log/mysql + - ./mysql/data:/var/lib/mysql + - ./mysql/logs:/var/log/mysql + - ./mysql/conf:/etc/mysql/conf.d ##初始化的脚本,初始化我们存放的init.sql文件 - - ./data/sql:/docker-entrypoint-initdb.d/ - - ./data/mysql/conf:/etc/mysql/conf.d - ports: - - "3306:3306" + - ./sql:/docker-entrypoint-initdb.d/ healthcheck: test: [ "CMD", "mysqladmin", "ping", "-h", "localhost", "-uyoutu", "-pyoutu!0113" ] interval: 6s @@ -35,8 +33,6 @@ services: hostname: redis container_name: redis privileged: true - ports: - - "6379:6379" environment: TZ: Asia/Shanghai volumes: @@ -44,4 +40,17 @@ services: # - ./conf/redis.conf:/etc/redis/redis.conf - ./data/redis/logs:/logs # command: [ "redis-server","/etc/redis/redis.conf" ] - + youtu_server: + image: youtu_server:v1 + container_name: youtu_server + ports: + - "8888:8888" + environment: + TZ: Asia/Shanghai + restart: always + depends_on: + - mysql + - redis + volumes: + - ./server/config.yaml:/app/etc/game_open_api-api.yaml + - ./server/logs:/logs \ No newline at end of file diff --git a/game_open_api/Dockerfile b/game_open_api/Dockerfile new file mode 100644 index 0000000..41f18ad --- /dev/null +++ b/game_open_api/Dockerfile @@ -0,0 +1,33 @@ +FROM golang:alpine AS builder + +LABEL stage=gobuilder + +ENV CGO_ENABLED=0 +ENV GOPROXY=https://goproxy.cn,direct + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories +RUN apk update --no-cache && apk add --no-cache tzdata + +WORKDIR /build + +ADD go.mod . +ADD go.sum . +RUN go mod download +COPY . . + +RUN go build -ldflags="-s -w" -o /app/game_open_api ./game_open_api/game_open_api.go + + +FROM scratch + +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai +ENV TZ=Asia/Shanghai + +WORKDIR /app +COPY --from=builder /app/game_open_api /app/game_open_api +COPY ./game_open_api/etc /app/etc + +EXPOSE 8888 + +CMD ["./game_open_api", "-f", "etc/game_open_api-api.yaml"] diff --git a/game_open_api/etc/compose_config.yaml b/game_open_api/etc/compose_config.yaml new file mode 100644 index 0000000..8c4ba22 --- /dev/null +++ b/game_open_api/etc/compose_config.yaml @@ -0,0 +1,22 @@ +Name: game_open_api-api +Host: 0.0.0.0 +Port: 8888 +DB: + DataSource: root:youtu!0113@tcp(mysql:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local +Cache: + - Host: redis:6379 + type: node + +Auth: + AccessSecret: youtu123! + AccessExpire: 86400 + +Log: + Level: info + Mode: file + Path: /logs + MaxSize: 100 + +DWCache: + Host: redis:6379 + IdleTimeout: 60 \ No newline at end of file