mcpField
D
docker-ci-cd

docker-ci-cd

github.com/pluginagentmarketplace云与 DevOps257 次安装42 周前更新
代码仓库

关于 docker-ci-cd

用于在 CI/CD 系统中构建、扫描和部署 Docker 镜像的技能,提供工作流指导与模板,适合自动化容器交付的团队。

主要功能

  1. 01GitHub Actions 工作流指导
  2. 02GitLab CI 工作流指导
  3. 03多架构镜像构建
  4. 04安全扫描与镜像签名
  5. 05构建缓存与故障处理

适用场景

  1. 01代码变更时自动构建镜像
  2. 02发布前扫描镜像
  3. 03通过 CI 流水线部署容器

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/pluginagentmarketplace/custom-plugin-docker --skill docker-ci-cd

安装后在 Claude Code 中输入/docker-ci-cd确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/
github-actions-docker.yaml
references/
CI-CD-GUIDE.md
scripts/
build-and-push.sh

详细介绍

Docker CI/CD 技能

将 Docker 集成到 CI/CD 流水线中,实现自动构建镜像、安全扫描和部署。

用途

使用 GitHub Actions、GitLab CI 和其他 CI/CD 平台设置自动化 Docker 工作流。

参数

参数类型必填默认值描述
platformenum否githubgithub/gitlab/jenkins
registrystring否ghcr.io容器镜像仓库
scanboolean否true包含安全扫描

GitHub Actions

完整工作流
name: Docker Build and Deploy

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to 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 metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
          tags: |
            type=sha
            type=ref,event=branch
            type=semver,pattern={{version}}

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          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

      - name: Scan for vulnerabilities
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${{ github.sha }}
          exit-code: '1'
          severity: 'CRITICAL,HIGH'
多架构构建
- name: Set up QEMU
  uses: docker/setup-qemu-action@v3

- name: Build multi-arch
  uses: docker/build-push-action@v5
  with:
    platforms: linux/amd64,linux/arm64
    push: true
    tags: ${{ steps.meta.outputs.tags }}

GitLab CI

# .gitlab-ci.yml
stages:
  - build
  - scan
  - deploy

variables:
  DOCKER_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

build:
  stage: build
  image: docker:24
  services:
    - docker:24-dind
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build -t $DOCKER_IMAGE .
    - docker push $DOCKER_IMAGE

scan:
  stage: scan
  image:
    name: aquasec/trivy
    entrypoint: [""]
  script:
    - trivy image --exit-code 1 --severity CRITICAL $DOCKER_IMAGE

deploy:
  stage: deploy
  script:
    - ssh deploy@server "docker pull $DOCKER_IMAGE && docker compose up -d"
  only:
    - main

最佳实践

缓存
# GitHub Actions BuildKit cache
cache-from: type=gha
cache-to: type=gha,mode=max

# GitLab cache
cache:
  key: docker-$CI_COMMIT_REF_SLUG
  paths:
    - .docker-cache
安全
# Scan before push
- name: Scan
  run: trivy image --exit-code 1 --severity CRITICAL $IMAGE

# Sign images (cosign)
- name: Sign
  run: cosign sign $IMAGE

错误处理

常见错误
错误原因解决方案
unauthorized凭据无效检查镜像仓库登录信息
rate limitDocker Hub 限制使用经过身份验证的拉取
cache miss首次构建缓存将会填充
回退策略
  1. 缓存损坏时,不使用缓存进行构建
  2. 主镜像仓库不可用时,使用备用镜像仓库
  3. 部署失败时,部署之前的版本

故障排除

调试检查清单
  • 镜像仓库凭据是否有效?
  • Docker 守护进程是否正在运行?
  • 构建上下文是否正确?
  • 是否存在 Dockerfile?

用法

Skill("docker-ci-cd")

资源

  • assets/github-actions-docker.yaml - GitHub Actions 模板
  • scripts/build-and-push.sh - 构建脚本

相关技能

  • docker-production
  • docker-security

评论

支持 Markdown