Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Git
.git
.gitignore
.gitattributes

# Dependencies (rebuilt in Docker)
backend/vendor
frontend/node_modules

# Runtime artifacts
backend/data
backend/.env.local
backend/.server.pid
frontend/.vite.pid
frontend/.node_platform
logs
*.log
*.db
*.db-shm
*.db-wal

# Build artifacts
*.tar.gz
*.zip

# IDE
.vscode
.claude
.idea

# Docker files
Dockerfile
docker-compose.yml
.env.example
.env
.dockerignore
docker-init.sh

# Deployment scripts (not needed in image)
一键初始化.bat
一键初始化.sh
一键运行.bat
一键运行.sh
scripts
deploy

# README
README.md
LICENSE
37 changes: 37 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ========================================
# BitAPI Docker 环境变量
# 复制为 .env 并修改后使用
# cp .env.example .env
# ========================================

# 站点名称(会显示在页面标题、导航栏等位置)
BITAPI_APP_NAME=BitAPI

# 环境:production / development
BITAPI_ENV=production

# 对外端口(docker-compose 端口映射使用)
BITAPI_HTTP_PORT=8091

# JWT 签名密钥(必须修改!建议 48 字节随机串)
# 生成方式:openssl rand -base64 48
BITAPI_JWT_SECRET=change-me-in-production

# 数据加密密钥(必须修改!建议 32 字节随机串)
# 生成方式:openssl rand -base64 32
BITAPI_ENCRYPTION_KEY=change-me-encryption-key-32-bytes

# Token 有效期
BITAPI_ACCESS_TOKEN_TTL=30m
BITAPI_REFRESH_TOKEN_TTL=336h

# CORS 允许的域名(逗号分隔,支持 https://*.domain.com 通配)
BITAPI_CORS_ORIGINS=http://localhost:8091,http://127.0.0.1:8091

# 初始管理员账号(首次启动时自动创建)
BITAPI_BOOTSTRAP_EMAIL=admin@bitapi.local
BITAPI_BOOTSTRAP_PASSWORD=bitapi-admin
BITAPI_BOOTSTRAP_NAME=BitAPI 管理员

# 新用户默认余额(单位:微单位,0 表示 0)
BITAPI_DEFAULT_USER_BALANCE_MICROS=0
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --- OS junk ---
.DS_Store
Thumbs.db

# --- IDE / Editor ---
.idea/
.vscode/
*.swp
*.swo
*~

# --- Environment & Secrets ---
.env
*.env
!.env.example
!backend/config.example.env

# --- Go (backend) ---
backend/cmd/*/main
backend/cmd/*/*.exe
*.test
*.out
*.prof
vendor/

# --- Node (frontend) ---
frontend/node_modules/
frontend/dist/
*.tsbuildinfo

# --- Logs ---
*.log
logs/

# --- Docker ---
docker-compose.override.yml

# --- OS / Misc ---
__pycache__/
*.pyc
tmp/
temp/
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# BitAPI - Multi-stage Docker build
# Stage 1: Build Vue 3 frontend
FROM node:20-alpine AS frontend-build
WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build

# Stage 2: Build Go backend (CGO_ENABLED=0, glebarez/sqlite is pure Go)
FROM golang:1.23-alpine AS backend-build
ENV GOTOOLCHAIN=auto
ENV GOPROXY=https://goproxy.cn,direct
WORKDIR /app
COPY backend/go.mod backend/go.sum ./
RUN go mod download
COPY backend/ ./
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o server ./cmd/server

# Stage 3: Minimal runtime
FROM alpine:3.21
RUN apk add --no-cache ca-certificates curl
WORKDIR /app
COPY --from=frontend-build /app/frontend/dist /app/frontend/dist
COPY --from=backend-build /app/server /app/server

RUN mkdir -p /app/data/uploads/avatars

EXPOSE 8091

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -fsS http://localhost:8091/health || exit 1

ENV BITAPI_DATABASE_DSN="file:/app/data/bitapi.db?_foreign_keys=on&_busy_timeout=5000"

ENTRYPOINT ["/app/server"]
Loading