feat: add docker deployment support
This commit is contained in:
20
.dockerignore
Normal file
20
.dockerignore
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
.git
|
||||||
|
.agents
|
||||||
|
.codex
|
||||||
|
.omc
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
logs
|
||||||
|
data
|
||||||
|
gateway
|
||||||
|
gateway-*
|
||||||
|
kcp
|
||||||
|
kcp-*
|
||||||
|
quic
|
||||||
|
quic-*
|
||||||
|
|
||||||
|
*.so
|
||||||
|
*.sqlite3
|
||||||
|
*.sqlite3-*
|
||||||
|
|
||||||
|
config.toml
|
||||||
63
.github/workflows/docker-image.yml
vendored
Normal file
63
.github/workflows/docker-image.yml
vendored
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
name: Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["master"]
|
||||||
|
tags: ["v*"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["master"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to GitHub Container Registry
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract Docker metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=pr
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
type=sha,prefix=sha-
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,5 +5,6 @@ config.toml
|
|||||||
/kcp*
|
/kcp*
|
||||||
/quic*
|
/quic*
|
||||||
/logs/
|
/logs/
|
||||||
|
/data/
|
||||||
|
|
||||||
.omc
|
.omc
|
||||||
|
|||||||
34
Dockerfile
Normal file
34
Dockerfile
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
FROM golang:1.24.4-alpine AS build
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN --mount=type=cache,id=mc-gateway-go-mod,target=/go/pkg/mod,sharing=locked \
|
||||||
|
go mod download
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN --mount=type=cache,id=mc-gateway-go-mod,target=/go/pkg/mod,sharing=locked \
|
||||||
|
--mount=type=cache,id=mc-gateway-go-build,target=/root/.cache/go-build,sharing=locked \
|
||||||
|
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/mc-gateway ./cmd/gateway
|
||||||
|
|
||||||
|
FROM alpine:3.22
|
||||||
|
|
||||||
|
RUN apk add --no-cache su-exec \
|
||||||
|
&& addgroup -S mc-gateway \
|
||||||
|
&& adduser -S -G mc-gateway mc-gateway
|
||||||
|
|
||||||
|
WORKDIR /data
|
||||||
|
RUN chown mc-gateway:mc-gateway /data
|
||||||
|
|
||||||
|
COPY --from=build /out/mc-gateway /usr/local/bin/mc-gateway
|
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
|
||||||
|
ENV MC_GATEWAY_DB=/data/mc-gateway.sqlite3
|
||||||
|
|
||||||
|
EXPOSE 25565/tcp
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||||
|
CMD ["/usr/local/bin/mc-gateway"]
|
||||||
35
README.md
35
README.md
@@ -24,6 +24,41 @@ mc-gateway 默认不依赖配置文件。直接启动后会在 `25565` 端口同
|
|||||||
|
|
||||||
服务启停、KCP/QUIC/WebSocket 参数、用户、权限和路由都通过后台管理写入 SQLite,不再使用 `config.toml` 作为启动配置或路由来源。
|
服务启停、KCP/QUIC/WebSocket 参数、用户、权限和路由都通过后台管理写入 SQLite,不再使用 `config.toml` 作为启动配置或路由来源。
|
||||||
|
|
||||||
|
### Docker Compose
|
||||||
|
|
||||||
|
可以直接用 Docker Compose 本地构建并启动:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
默认使用 host network,在宿主机 `25565/tcp` 提供 Minecraft TCP 转发入口和后台管理入口,后台地址为:
|
||||||
|
|
||||||
|
```text
|
||||||
|
http://<host>:25565/admin/
|
||||||
|
```
|
||||||
|
|
||||||
|
Compose 使用本地 `./data` 目录持久化 SQLite 数据库和 WAL 文件,不挂载旧 `config.toml`。首次启动可以在后台页面初始化管理员,也可以通过 `.env` 预置默认管理员 `admin` 的密码:
|
||||||
|
|
||||||
|
```env
|
||||||
|
MC_GATEWAY_ADMIN_PASSWORD=change-me
|
||||||
|
```
|
||||||
|
|
||||||
|
常用可选项:
|
||||||
|
|
||||||
|
```env
|
||||||
|
MC_GATEWAY_TCP_ADMIN_PORT=25565
|
||||||
|
MC_GATEWAY_ADMIN_PATH=/admin/
|
||||||
|
MC_GATEWAY_ADMIN_API_PREFIX=/admin/api
|
||||||
|
MC_GATEWAY_DB=/data/mc-gateway.sqlite3
|
||||||
|
```
|
||||||
|
|
||||||
|
`master` 分支和 `v*` tag 会通过 GitHub Actions 构建并推送 Docker 镜像到 GitHub Container Registry:
|
||||||
|
|
||||||
|
```text
|
||||||
|
ghcr.io/tursom/mc-gateway:latest
|
||||||
|
```
|
||||||
|
|
||||||
## 权限
|
## 权限
|
||||||
|
|
||||||
后台管理内置三类角色:
|
后台管理内置三类角色:
|
||||||
|
|||||||
24
compose.yaml
Normal file
24
compose.yaml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
services:
|
||||||
|
mc-gateway:
|
||||||
|
image: ${MC_GATEWAY_IMAGE:-ghcr.io/tursom/mc-gateway:latest}
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
network_mode: host
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MC_GATEWAY_TCP_ADMIN_PORT: "${MC_GATEWAY_TCP_ADMIN_PORT:-25565}"
|
||||||
|
MC_GATEWAY_ADMIN_PATH: "${MC_GATEWAY_ADMIN_PATH:-/admin/}"
|
||||||
|
MC_GATEWAY_ADMIN_API_PREFIX: "${MC_GATEWAY_ADMIN_API_PREFIX:-/admin/api}"
|
||||||
|
MC_GATEWAY_DB: "${MC_GATEWAY_DB:-/data/mc-gateway.sqlite3}"
|
||||||
|
MC_GATEWAY_ADMIN_PASSWORD: "${MC_GATEWAY_ADMIN_PASSWORD:-}"
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
healthcheck:
|
||||||
|
test:
|
||||||
|
- CMD-SHELL
|
||||||
|
- wget -Y off -qO- "http://127.0.0.1:$${MC_GATEWAY_TCP_ADMIN_PORT:-25565}$${MC_GATEWAY_ADMIN_API_PREFIX:-/admin/api}/setup" >/dev/null
|
||||||
|
interval: 30s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
start_period: 10s
|
||||||
10
docker-entrypoint.sh
Normal file
10
docker-entrypoint.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ "$(id -u)" = "0" ]; then
|
||||||
|
mkdir -p /data
|
||||||
|
chown -R mc-gateway:mc-gateway /data
|
||||||
|
exec su-exec mc-gateway "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$@"
|
||||||
Reference in New Issue
Block a user