file_system/.gitlab-ci.yml
root 2f88022782 Add complete deployment configuration with Docker-in-Docker
- Added docker-in-docker service for container deployment
- Created dynamic docker-compose.yml with full configuration
- Added container auto-restart policy (unless-stopped)
- Configured health check for service monitoring
- Added environment variables for RustFS backend
- Set up port mapping (8080:8080) and network configuration
- Added logging configuration with rotation
- Included deployment validation and status reporting
- Service will auto-pull from private registry and deploy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-19 10:22:19 +08:00

104 lines
3.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

stages:
- build
- deploy
variables:
DOCKER_IMAGE_NAME: file-system-server
DOCKER_TAG: latest
CI_REGISTRY: "192.168.1.154:31010"
CI_REGISTRY_USER: "docker"
CI_REGISTRY_PASSWORD: "dockerxn001624."
# 构建镜像
build_image:
stage: build
image: 192.168.1.154:31010/docker/alpine:latest
script:
- apk add --no-cache docker-cli
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $DOCKER_IMAGE_NAME:$DOCKER_TAG .
- docker tag $DOCKER_IMAGE_NAME:$DOCKER_TAG $CI_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG
- docker push $CI_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG
only:
- main
# 部署服务
deploy_service:
stage: deploy
image: 192.168.1.154:31010/docker/compose:latest
services:
- docker:24.0.6-dind # Docker-in-Docker服务
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
script:
# 创建docker-compose.yml文件如果没有的话
- |
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
file-system-server:
image: ${CI_REGISTRY}/${DOCKER_IMAGE_NAME}:${DOCKER_TAG}
container_name: file-system-server
restart: unless-stopped # 容器退出时自动重启,除非手动停止
ports:
- "8080:8080" # 映射端口
environment:
- SERVER_PORT=8080
- RUSTFS_ENDPOINT=http://192.168.1.154:9000
- RUSTFS_ACCESS_KEY=minioadmin
- RUSTFS_SECRET_KEY=minioadmin123
- RUSTFS_USE_SSL=false
- RUSTFS_REGION=us-east-1
volumes:
# 挂载日志目录
- ./logs:/app/logs
networks:
- file-system-network
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/swagger/index.html"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
networks:
file-system-network:
driver: bridge
EOF
# 登录到私有仓库
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# 拉取最新镜像
- docker pull $CI_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG
# 停止并删除旧容器
- docker-compose down --remove-orphans || true
# 删除旧镜像(释放空间)
- docker rmi $CI_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG 2>/dev/null || true
# 启动服务(后台运行)
- docker-compose up -d
# 等待容器启动
- sleep 10
# 显示运行状态
- docker-compose ps
# 显示容器健康状态
- docker inspect --format='{{.State.Health.Status}}' file-system-server || echo "Health check not configured"
# 显示容器日志最近20行
- docker-compose logs --tail=20
# 验证服务是否正常响应
- wget --no-verbose --tries=1 --spider http://localhost:8080/swagger/index.html || echo "Service health check failed"
# 清理未使用的镜像
- docker image prune -f
# 显示最终状态
- echo "🚀 部署完成!服务地址: http://localhost:8080"
- echo "📊 容器状态:"
- docker ps --filter "name=file-system-server" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
only:
- main