165 lines
4.7 KiB
YAML
165 lines
4.7 KiB
YAML
version: '3.8'
|
||
|
||
services:
|
||
# 1. Docker 私有映像倉庫 - 存儲自訂編譯的容器映像
|
||
registry:
|
||
image: registry:2
|
||
container_name: docker-registry
|
||
restart: always
|
||
ports:
|
||
- "5700:5000"
|
||
environment:
|
||
REGISTRY_HTTP_ADDR: 0.0.0.0:5000
|
||
REGISTRY_HTTP_RELATIVEURLS: 'true'
|
||
REGISTRY_STORAGE_DELETE_ENABLED: 'true'
|
||
volumes:
|
||
- /mnt/data/External/docker_registry/registry_data:/var/lib/registry
|
||
healthcheck:
|
||
test: ["CMD", "curl", "-f", "http://localhost:5000/v2/"]
|
||
interval: 30s
|
||
timeout: 10s
|
||
retries: 3
|
||
start_period: 10s
|
||
|
||
# 2. Registry 管理界面 - Web UI,方便查看和管理存儲的映像
|
||
registry-ui:
|
||
image: joxit/docker-registry-ui:latest
|
||
container_name: docker-registry-ui
|
||
restart: always
|
||
ports:
|
||
- "5600:80"
|
||
environment:
|
||
REGISTRY_TITLE: "Docker Registry"
|
||
REGISTRY_URL: "http://registry:5000"
|
||
REGISTRY_SECURED: 'false'
|
||
REGISTRY_USERNAME: "admin"
|
||
REGISTRY_PASSWORD: "change_me"
|
||
DELETE_IMAGES: 'true'
|
||
SHOW_CATALOG_NB_TAGS: 'true'
|
||
NGINX_PROXY_PASS_URL: 'http://registry:5000'
|
||
depends_on:
|
||
registry:
|
||
condition: service_healthy
|
||
healthcheck:
|
||
test: ["CMD", "curl", "-f", "http://localhost:80/"]
|
||
interval: 30s
|
||
timeout: 10s
|
||
retries: 3
|
||
|
||
# 3. Docker Hub 鏡像加速 - 緩存 Docker Hub 映像,加速拉取速度
|
||
registry-mirror:
|
||
image: registry:2
|
||
container_name: docker-registry-mirror
|
||
restart: always
|
||
ports:
|
||
- "5500:5000"
|
||
environment:
|
||
REGISTRY_HTTP_ADDR: 0.0.0.0:5000
|
||
REGISTRY_PROXY_REMOTEURL: "https://registry-1.docker.io"
|
||
REGISTRY_STORAGE_DELETE_ENABLED: 'true'
|
||
volumes:
|
||
- /mnt/data/External/docker_registry/mirror_data:/var/lib/registry
|
||
healthcheck:
|
||
test: ["CMD", "curl", "-f", "http://localhost:5000/v2/"]
|
||
interval: 30s
|
||
timeout: 10s
|
||
retries: 3
|
||
start_period: 10s
|
||
|
||
# 4. Docker 編譯伺服器 - Docker-in-Docker,隔離編譯環境
|
||
build-server:
|
||
image: docker:dind
|
||
container_name: docker-build-server
|
||
restart: always
|
||
environment:
|
||
DOCKER_HOST: unix:///var/run/docker.sock
|
||
DOCKER_DRIVER: overlay2
|
||
# 自動清理策略
|
||
DOCKER_BUILDKIT: 1
|
||
volumes:
|
||
- build_cache:/var/lib/docker
|
||
privileged: true
|
||
networks:
|
||
- docker-registry-network
|
||
healthcheck:
|
||
test: ["CMD", "docker", "ps"]
|
||
interval: 30s
|
||
timeout: 10s
|
||
retries: 3
|
||
start_period: 10s
|
||
|
||
# 5. Drone CI 伺服器 - 自動化編譯平台,支持 Git Webhook 觸發編譯和推送
|
||
drone-server:
|
||
image: drone/drone:latest
|
||
container_name: drone-server
|
||
restart: always
|
||
ports:
|
||
- "5400:80"
|
||
environment:
|
||
DRONE_SERVER_HOST: localhost:5400
|
||
DRONE_SERVER_PROTO: http
|
||
DRONE_RPC_SECRET: ${DRONE_RANDOM_SECRET}
|
||
# Git 平台配置(根據你使用的平台選擇)
|
||
# GitHub 配置
|
||
# DRONE_GITHUB_CLIENT_ID: "your-github-client-id"
|
||
# DRONE_GITHUB_CLIENT_SECRET: "your-github-secret"
|
||
# GitLab 配置
|
||
# DRONE_GITLAB_SERVER: https://gitlab.example.com
|
||
# DRONE_GITLAB_CLIENT_ID: "your-gitlab-client-id"
|
||
# DRONE_GITLAB_CLIENT_SECRET: "your-gitlab-secret"
|
||
# Gitea 配置
|
||
# DRONE_GITEA_SERVER: http://gitea.example.com
|
||
# DRONE_GITEA_CLIENT_ID: "your-gitea-client-id"
|
||
# DRONE_GITEA_CLIENT_SECRET: "your-gitea-secret"
|
||
# 初始管理員
|
||
DRONE_USER_CREATE: "username:admin,admin:true"
|
||
volumes:
|
||
- drone_data:/data
|
||
networks:
|
||
- docker-registry-network
|
||
depends_on:
|
||
- registry
|
||
healthcheck:
|
||
test: ["CMD", "curl", "-f", "http://localhost:80/api/version"]
|
||
interval: 30s
|
||
timeout: 10s
|
||
retries: 3
|
||
start_period: 10s
|
||
|
||
# 6. Drone Runner - Docker 執行器,使用 DinD 編譯並自動清理
|
||
drone-runner:
|
||
image: drone/drone-runner-docker:latest
|
||
container_name: drone-runner-docker
|
||
restart: always
|
||
environment:
|
||
# 連接到 Drone Server
|
||
DRONE_RPC_HOST: drone-server
|
||
DRONE_RPC_PROTO: http
|
||
DRONE_RPC_SECRET: ${DRONE_RANDOM_SECRET}
|
||
# 執行器配置
|
||
DRONE_RUNNER_CAPACITY: 2
|
||
DRONE_RUNNER_NAME: "docker-runner-01"
|
||
# 使用獨立的 DinD 連接
|
||
DRONE_DOCKER_HOST: tcp://build-server:2375
|
||
# 自動清理配置
|
||
DRONE_CLEANUP: "true"
|
||
# 編譯完後自動刪除容器
|
||
DRONE_DOCKER_PURGE: "true"
|
||
DRONE_UI_USERNAME: admin
|
||
DRONE_UI_PASSWORD: admin
|
||
networks:
|
||
- docker-registry-network
|
||
depends_on:
|
||
- drone-server
|
||
- build-server
|
||
|
||
volumes:
|
||
# 編譯緩存(DinD 層緩存)
|
||
build_cache:
|
||
# Drone CI 配置和數據
|
||
drone_data:
|
||
|
||
networks:
|
||
docker-registry-network:
|
||
driver: bridge
|