feat: 🎸 docker compose构建脚本
This commit is contained in:
parent
9f1052b501
commit
3dced742e6
64
Dockerfile
Normal file
64
Dockerfile
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# 使用官方 Go 镜像作为基础镜像
|
||||||
|
FROM golang:1.24.4-alpine AS builder
|
||||||
|
|
||||||
|
# 安装必要的工具
|
||||||
|
RUN apk update && apk add tzdata
|
||||||
|
RUN apk add --no-cache nodejs npm git
|
||||||
|
|
||||||
|
# 安装 pnpm
|
||||||
|
RUN npm install -g pnpm
|
||||||
|
|
||||||
|
# 设置工作目录
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制后端
|
||||||
|
COPY ./server ./server
|
||||||
|
# 复制前端
|
||||||
|
COPY ./web ./web
|
||||||
|
|
||||||
|
# 构建前端项目
|
||||||
|
WORKDIR /app/web
|
||||||
|
RUN echo "y" |pnpm install
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
# 构建后端项目
|
||||||
|
WORKDIR /app/server
|
||||||
|
|
||||||
|
# 删除之前的web资源并重新创建目录
|
||||||
|
RUN rm -rf ./resource/public/admin/
|
||||||
|
RUN mkdir -p ./resource/public/admin/
|
||||||
|
|
||||||
|
# 复制编译好的web资源到server目录
|
||||||
|
RUN cp -rf ../web/dist/* ./resource/public/admin/
|
||||||
|
|
||||||
|
# 编译hotgo服务端
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# 安装gf
|
||||||
|
RUN wget -O gf "https://github.com/gogf/gf/releases/latest/download/gf_$(go env GOOS)_$(go env GOARCH)" && chmod +x gf && ./gf install -y && rm ./gf
|
||||||
|
|
||||||
|
RUN gf build
|
||||||
|
|
||||||
|
# 使用轻量级的 alpine 镜像作为运行环境
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
# 安装 ca-certificates 用于 HTTPS 请求
|
||||||
|
RUN apk --no-cache add ca-certificates tzdata
|
||||||
|
|
||||||
|
# 设置时区
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
|
# 设置工作目录
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 从构建阶段复制编译好的二进制文件
|
||||||
|
COPY --from=builder /app/server/temp/hotgo .
|
||||||
|
|
||||||
|
# 复制配置文件(如果存在)
|
||||||
|
COPY --from=builder /app/server/manifest/config/ ./manifest/config/
|
||||||
|
|
||||||
|
# 暴露端口
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
CMD ./hotgo
|
47
deploy/hack/config.yaml
Normal file
47
deploy/hack/config.yaml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# CLI tool, only in development environment.
|
||||||
|
# https://goframe.org/pages/viewpage.action?pageId=3673173
|
||||||
|
gfcli:
|
||||||
|
build:
|
||||||
|
name: "hotgo" # 编译后的可执行文件名称
|
||||||
|
# arch: "amd64" # 不填默认当前系统架构,可选:386,amd64,arm,all
|
||||||
|
# system: "linux" # 不填默认当前系统平台,可选:linux,darwin,windows,all
|
||||||
|
mod: "none"
|
||||||
|
cgo: 0
|
||||||
|
packSrc: "resource" # 将resource目录打包进可执行文件,静态资源无需单独部署
|
||||||
|
packDst: "internal/packed/packed.go" # 打包后生成的Go文件路径,一般使用相对路径指定到本项目目录中
|
||||||
|
version: ""
|
||||||
|
output: "./temp/hotgo" # 可执行文件生成路径
|
||||||
|
extra: ""
|
||||||
|
|
||||||
|
|
||||||
|
docker:
|
||||||
|
build: "-a amd64 -s linux -p temp -ew" # 构建参数
|
||||||
|
tagPrefixes: # 该docker的标记前缀,用于docker推送,请替换成你自己的
|
||||||
|
- ccr.ccs.tencentyun.com/bufanyun
|
||||||
|
|
||||||
|
|
||||||
|
gen:
|
||||||
|
dao:
|
||||||
|
- link: "mysql:root:gmanager123!@tcp(mysql)/hotgo?loc=Local&parseTime=true&charset=utf8mb4"
|
||||||
|
group: "default" # 分组 使用hotgo代码生成功能时必须填
|
||||||
|
# tables: "" # 指定当前数据库中需要执行代码生成的数据表。如果为空,表示数据库的所有表都会生成。
|
||||||
|
tablesEx: "hg_sys_addons_install" # 指定当前数据库中需要排除代码生成的数据表。
|
||||||
|
removePrefix: "hg_"
|
||||||
|
descriptionTag: true
|
||||||
|
noModelComment: true
|
||||||
|
jsonCase: "CamelLower"
|
||||||
|
gJsonSupport: true
|
||||||
|
clear: false
|
||||||
|
|
||||||
|
|
||||||
|
# service: # 生成业务配置
|
||||||
|
# srcFolder: "internal/logic"
|
||||||
|
# dstFolder: "internal/service"
|
||||||
|
# dstFileNameCase: "CamelLower"
|
||||||
|
# clear: true
|
||||||
|
ctrl:
|
||||||
|
# api/api下的接口可以使用gf gen ctrl自动生成控制器相关代码
|
||||||
|
srcFolder: "api/api"
|
||||||
|
dstFolder: "internal/controller/api"
|
||||||
|
clear: true
|
||||||
|
merge: false
|
@ -75,14 +75,14 @@ tcp:
|
|||||||
cron:
|
cron:
|
||||||
group: "cron" # 分组名称
|
group: "cron" # 分组名称
|
||||||
name: "cron1" # 客户端名称
|
name: "cron1" # 客户端名称
|
||||||
address: gmanager-server:8099 # 服务器地址
|
address: "127.0.0.1:8099" # 服务器地址
|
||||||
appId: "1002" # 应用名称
|
appId: "1002" # 应用名称
|
||||||
secretKey: "hotgo" # 密钥
|
secretKey: "hotgo" # 密钥
|
||||||
# 系统授权
|
# 系统授权
|
||||||
auth:
|
auth:
|
||||||
group: "auth" # 分组名称
|
group: "auth" # 分组名称
|
||||||
name: "auth1" # 客户端名称
|
name: "auth1" # 客户端名称
|
||||||
address: gmanager-server:8099 # 服务器地址
|
address: "127.0.0.1:8099" # 服务器地址
|
||||||
appId: "mengshuai" # 应用名称
|
appId: "mengshuai" # 应用名称
|
||||||
secretKey: "123456" # 密钥
|
secretKey: "123456" # 密钥
|
||||||
|
|
@ -1,26 +1,26 @@
|
|||||||
services:
|
services:
|
||||||
nginx:
|
# nginx:
|
||||||
build:
|
# build:
|
||||||
dockerfile: ./resources/docker/Dockerfile
|
# dockerfile: ./resources/docker/Dockerfile
|
||||||
target: gmanager-nginx
|
# target: gmanager-nginx
|
||||||
ports:
|
# ports:
|
||||||
- 80:80
|
# - 80:80
|
||||||
environment:
|
# environment:
|
||||||
- NGINX_HOST=gmanager
|
# - NGINX_HOST=gmanager
|
||||||
- NGINX_PORT=80
|
# - NGINX_PORT=80
|
||||||
volumes:
|
# volumes:
|
||||||
- ./resources/docker/nginx/gmanager.conf:/etc/nginx/conf.d/gmanager.conf
|
# - ./resources/docker/nginx/gmanager.conf:/etc/nginx/conf.d/gmanager.conf
|
||||||
- ./resources/docker/nginx/nginx.conf:/etc/nginx/nginx.conf
|
# - ./resources/docker/nginx/nginx.conf:/etc/nginx/nginx.conf
|
||||||
depends_on:
|
# depends_on:
|
||||||
mysql:
|
# mysql:
|
||||||
condition: service_healthy
|
# condition: service_healthy
|
||||||
gmanager-server:
|
# gmanager-server:
|
||||||
condition: service_started
|
# condition: service_started
|
||||||
networks:
|
# networks:
|
||||||
- gmanager
|
# - gmanager
|
||||||
restart: on-failure
|
# restart: on-failure
|
||||||
extra_hosts:
|
# extra_hosts:
|
||||||
- "host.docker.internal:host-gateway"
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
# mysql:5.7 linux/arm64 image is unavailable.
|
# mysql:5.7 linux/arm64 image is unavailable.
|
||||||
@ -42,7 +42,7 @@ services:
|
|||||||
- 3306:3306
|
- 3306:3306
|
||||||
volumes:
|
volumes:
|
||||||
- mysql_data:/var/lib/mysql
|
- mysql_data:/var/lib/mysql
|
||||||
- ./resources/docker/init.sql:/data/application/init.sql
|
- ./deploy/init.sql:/data/application/init.sql
|
||||||
networks:
|
networks:
|
||||||
- gmanager
|
- gmanager
|
||||||
healthcheck:
|
healthcheck:
|
||||||
@ -66,8 +66,7 @@ services:
|
|||||||
|
|
||||||
gmanager-server:
|
gmanager-server:
|
||||||
build:
|
build:
|
||||||
dockerfile: ./resources/docker/Dockerfile
|
dockerfile: ./Dockerfile
|
||||||
target: gmanager-server
|
|
||||||
container_name: gmanager-server
|
container_name: gmanager-server
|
||||||
depends_on:
|
depends_on:
|
||||||
mysql:
|
mysql:
|
||||||
@ -75,7 +74,9 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 8000:8000
|
- 8000:8000
|
||||||
volumes:
|
volumes:
|
||||||
- ./resources/docker/config/config.example.yaml:/app/config.yaml
|
- ./deploy/manifest/config/config.yaml:/app/manifest/config/config.yaml
|
||||||
|
- ./deploy/manifest/config/casbin.conf:/app/manifest/config/casbin.conf
|
||||||
|
- ./deploy/hack/config.yaml:/app/hack/config.yaml
|
||||||
networks:
|
networks:
|
||||||
- gmanager
|
- gmanager
|
||||||
restart: on-failure
|
restart: on-failure
|
@ -1,61 +0,0 @@
|
|||||||
|
|
||||||
###############################################################################
|
|
||||||
# SERVER
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# 第一阶段:编译go项目
|
|
||||||
FROM golang:1.24.4-alpine as server-builder
|
|
||||||
ENV WORKDIR /app
|
|
||||||
WORKDIR $WORKDIR
|
|
||||||
|
|
||||||
COPY ./server .
|
|
||||||
|
|
||||||
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
|
||||||
RUN go mod download
|
|
||||||
RUN go mod tidy
|
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main main.go
|
|
||||||
|
|
||||||
# 第二阶段:部署server项目
|
|
||||||
FROM alpine:3.21.3 as gmanager-server
|
|
||||||
|
|
||||||
RUN apk update && apk add tzdata
|
|
||||||
|
|
||||||
ENV WORKDIR /app
|
|
||||||
# 复制编译后的静态文件和启动文件
|
|
||||||
COPY --from=server-builder /app/resource $WORKDIR/resource
|
|
||||||
COPY --from=server-builder /app/main $WORKDIR/main
|
|
||||||
RUN chmod +x $WORKDIR/main
|
|
||||||
|
|
||||||
# 暴露端口
|
|
||||||
EXPOSE 8000
|
|
||||||
|
|
||||||
WORKDIR $WORKDIR
|
|
||||||
CMD ./main
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# NGINX
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# 第一阶段:编译pnpm项目
|
|
||||||
FROM node:22.16.0-alpine as nginx-builder
|
|
||||||
# 安装pnpm
|
|
||||||
RUN npm install -g pnpm
|
|
||||||
# 设置镜像
|
|
||||||
RUN pnpm config set registry https://registry.npmmirror.com/
|
|
||||||
# 复制项目文件
|
|
||||||
WORKDIR /app
|
|
||||||
COPY ./web .
|
|
||||||
# 安装依赖并编译
|
|
||||||
RUN rm -rf node_modules
|
|
||||||
RUN pnpm install
|
|
||||||
RUN pnpm build
|
|
||||||
|
|
||||||
# 第二阶段:使用Nginx部署
|
|
||||||
FROM nginx:latest as gmanager-nginx
|
|
||||||
# 复制编译后的静态文件
|
|
||||||
COPY --from=nginx-builder /app/dist /app/dist
|
|
||||||
# 暴露端口
|
|
||||||
EXPOSE 80
|
|
||||||
# 启动Nginx
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
|
@ -1,89 +0,0 @@
|
|||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name _;
|
|
||||||
|
|
||||||
location /admin {
|
|
||||||
proxy_pass http://gmanager-server:8000/;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Connection "";
|
|
||||||
proxy_buffering off;
|
|
||||||
proxy_read_timeout 3600s;
|
|
||||||
proxy_send_timeout 3600s;
|
|
||||||
}
|
|
||||||
|
|
||||||
# swagger api.json
|
|
||||||
location ~/(api.json|swagger) {
|
|
||||||
proxy_pass http://gmanager-server:8000;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Connection "";
|
|
||||||
proxy_buffering off;
|
|
||||||
proxy_read_timeout 3600s;
|
|
||||||
proxy_send_timeout 3600s;
|
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
|
||||||
root /app/dist;
|
|
||||||
index index.html;
|
|
||||||
try_files $uri $uri/ /index.html;
|
|
||||||
}
|
|
||||||
|
|
||||||
# websocket
|
|
||||||
location = /socket {
|
|
||||||
proxy_pass http://gmanager-server:8000/socket;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-NginX-Proxy true;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "Upgrade";
|
|
||||||
proxy_connect_timeout 600s;
|
|
||||||
proxy_read_timeout 600;
|
|
||||||
proxy_send_timeout 600s;
|
|
||||||
}
|
|
||||||
|
|
||||||
# # http
|
|
||||||
# location ^~ / {
|
|
||||||
# proxy_set_header Host $http_host;
|
|
||||||
# proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
# proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
# proxy_pass http://gmanager-server:8000/;
|
|
||||||
# proxy_redirect off;
|
|
||||||
# proxy_buffering off;
|
|
||||||
# proxy_http_version 1.1;
|
|
||||||
# proxy_set_header Upgrade $http_upgrade;
|
|
||||||
# proxy_set_header Connection upgrade;
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # swagger api.json
|
|
||||||
# location ~/(api.json|swagger) {
|
|
||||||
# proxy_pass http://gmanager-server:8000;
|
|
||||||
# proxy_set_header Host $host;
|
|
||||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
# proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
# proxy_http_version 1.1;
|
|
||||||
# proxy_set_header Connection "";
|
|
||||||
# proxy_buffering off;
|
|
||||||
# proxy_read_timeout 3600s;
|
|
||||||
# proxy_send_timeout 3600s;
|
|
||||||
# }
|
|
||||||
|
|
||||||
# location / {
|
|
||||||
# root /app/dist;
|
|
||||||
# index index.html;
|
|
||||||
# try_files $uri $uri/ /index.html;
|
|
||||||
# }
|
|
||||||
|
|
||||||
# Cache-Control: max-age~@~AExpires
|
|
||||||
location ~ ^/static/(css|js|media)/ {
|
|
||||||
expires 10y;
|
|
||||||
access_log off;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
user root;
|
|
||||||
worker_processes auto;
|
|
||||||
|
|
||||||
error_log /var/log/nginx/error.log notice;
|
|
||||||
pid /var/run/nginx.pid;
|
|
||||||
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
http {
|
|
||||||
include /etc/nginx/mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
|
|
||||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
||||||
'$status $body_bytes_sent "$http_referer" '
|
|
||||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
||||||
|
|
||||||
access_log /var/log/nginx/access.log main;
|
|
||||||
|
|
||||||
sendfile on;
|
|
||||||
#tcp_nopush on;
|
|
||||||
|
|
||||||
keepalive_timeout 65;
|
|
||||||
|
|
||||||
#gzip on;
|
|
||||||
client_max_body_size 1024M;
|
|
||||||
|
|
||||||
include /etc/nginx/conf.d/gmanager.conf;
|
|
||||||
}
|
|
@ -3,8 +3,8 @@
|
|||||||
gfcli:
|
gfcli:
|
||||||
build:
|
build:
|
||||||
name: "hotgo" # 编译后的可执行文件名称
|
name: "hotgo" # 编译后的可执行文件名称
|
||||||
arch: "amd64" # 不填默认当前系统架构,可选:386,amd64,arm,all
|
# arch: "amd64" # 不填默认当前系统架构,可选:386,amd64,arm,all
|
||||||
system: "linux" # 不填默认当前系统平台,可选:linux,darwin,windows,all
|
# system: "linux" # 不填默认当前系统平台,可选:linux,darwin,windows,all
|
||||||
mod: "none"
|
mod: "none"
|
||||||
cgo: 0
|
cgo: 0
|
||||||
packSrc: "resource" # 将resource目录打包进可执行文件,静态资源无需单独部署
|
packSrc: "resource" # 将resource目录打包进可执行文件,静态资源无需单独部署
|
||||||
|
Loading…
x
Reference in New Issue
Block a user