file_system/.gitlab-ci.yml
root 8bfae1588b Simplify deployment using Docker run instead of docker-compose
- Removed docker-compose dependency, using direct Docker run commands
- Kept all deployment features: auto-restart, health check, logging
- Direct Docker container deployment from private registry image
- Added comprehensive environment variables for RustFS backend
- Maintained port mapping (8080:8080) and volume mounting
- Added detailed status reporting and health check validation
- Works with local Dockerfile only, no docker-compose.yml needed

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

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

91 lines
3.2 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/alpine:latest
services:
- docker:24.0.6-dind # Docker-in-Docker服务
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
script:
# 安装必要的工具
- apk add --no-cache docker-cli wget
# 登录到私有仓库
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# 拉取最新构建的镜像
- docker pull $CI_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG
# 停止并删除旧容器
- docker stop file-system-server 2>/dev/null || true
- docker rm file-system-server 2>/dev/null || true
# 删除旧镜像(释放空间)
- docker rmi $CI_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG 2>/dev/null || true
# 创建日志目录
- mkdir -p /builds/root/file_service/logs
# 运行新的容器
- |
docker run -d \
--name file-system-server \
--restart unless-stopped \
-p 8080:8080 \
-e SERVER_PORT=8080 \
-e RUSTFS_ENDPOINT=http://192.168.1.154:9000 \
-e RUSTFS_ACCESS_KEY=minioadmin \
-e RUSTFS_SECRET_KEY=minioadmin123 \
-e RUSTFS_USE_SSL=false \
-e RUSTFS_REGION=us-east-1 \
-v /builds/root/file_service/logs:/app/logs \
--health-cmd="wget --no-verbose --tries=1 --spider http://localhost:8080/swagger/index.html || exit 1" \
--health-interval=30s \
--health-timeout=10s \
--health-retries=3 \
--health-start-period=40s \
--log-driver json-file \
--log-opt max-size=10m \
--log-opt max-file=3 \
$CI_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG
# 等待容器启动
- sleep 15
# 显示容器状态
- docker ps --filter "name=file-system-server"
# 显示容器健康状态
- docker inspect --format='{{.State.Health.Status}}' file-system-server || echo "Health check not available yet"
# 显示容器日志最近20行
- docker logs --tail=20 file-system-server
# 验证服务是否正常响应
- 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}}"
- echo "📋 健康检查状态:"
- docker inspect --format='{{.State.Health.Status}}' file-system-server || echo "Pending..."
only:
- main