Drone

CI/CDDroneコンテナネイティブDockerKubernetes継続的統合エージェントレスプラグイン

CI/CDツール

Drone

概要

DroneはContainer-Native(コンテナネイティブ)な継続的デリバリープラットフォームです。すべてのビルドを独立したDockerコンテナ内で実行し、Kubernetesとの深い統合により、現代的なクラウドネイティブアーキテクチャを活用したCI/CDを実現します。

詳細

Drone(ドローン)は、コンテナテクノロジーを基盤とした継続的デリバリーシステムとして、GitHub上で25,700を超えるスターと300名以上の貢献者を持つ成熟したクラウドネイティブCI/CDプラットフォームです。2024-2025年には、Kubernetesネイティブ機能の強化により、エージェントレスアーキテクチャを実現し、従来のCI/CDシステムと比較して大幅な運用簡素化を達成しています。シンプルなYAML設定ファイル(docker-composeのスーパーセット)を使用してDockerコンテナ内でパイプラインを定義・実行し、コンテナファーストアーキテクチャによりKubernetesとDockerランタイム間で同一のパイプライン設定が利用可能です。すべてのビルドが独立したDockerコンテナで実行されるため、完全に分離された環境を提供し、数千のDockerイメージから選択して環境を自動プロビジョニングできます。エフェメラル(一時的)ビルドにより各パイプライン実行でクリーンな環境が保証され、再現性が向上します。Kubernetesアドミニストレーターの視点では、エージェントのインストール・アップグレード・管理が不要となり、デプロイメントが大幅に簡素化されます。ホストマシンのDockerソケットマウントやDocker-in-Dockerの実行も不要で、Kubernetesネイティブなクラスター内ビルドを実現します。プラグインアーキテクチャでは、他のCIツールがサーバーサイドでプラグインをインストールするのと異なり、DroneのプラグインはDockerコンテナとしてパイプラインステップに含まれる革新的な設計を採用しています。シングルバイナリからのインストールと自動スケーリング、オンプレミス・プライベートクラウド・Kubernetesクラウドネイティブインフラでの柔軟なデプロイメントにより、チームがビルドインフラを完全制御できます。

メリット・デメリット

メリット

  • コンテナネイティブ: 全ビルドをDockerコンテナで分離実行
  • Kubernetesネイティブ: エージェントレスなK8s統合アーキテクチャ
  • シンプルな設定: YAML設定ファイルによる直感的なパイプライン定義
  • プラグインアーキテクチャ: Dockerコンテナベースの革新的プラグインシステム
  • 高い再現性: エフェメラルビルドによるクリーンな実行環境
  • 自動スケーリング: シングルバイナリからの簡単インストールと拡張
  • ポータビリティ: 複数の実行環境での統一設定利用
  • 豊富なイメージ: 数千のDockerイメージからの環境選択
  • ローカル実行: Docker ExtensionによるローカルCI実行

デメリット

  • Docker依存: Dockerコンテナ技術への強い依存
  • 学習コスト: コンテナ技術とKubernetes知識が必要
  • リソース消費: コンテナオーバーヘッドによるリソース使用量
  • デバッグ複雑性: コンテナ環境でのトラブルシューティング
  • プラグイン制限: コンテナベースプラグインの制約
  • ネットワーク設定: 複雑なネットワーク要件での設定困難
  • エコシステム: 他のCI/CDツールと比較したコミュニティ規模
  • ストレージ管理: 一時的コンテナでの永続化データ管理

主要リンク

書き方の例

基本的なパイプライン設定

# .drone.yml
kind: pipeline
type: docker
name: default

steps:
- name: build
  image: golang:1.21
  commands:
  - go mod download
  - go build -o app .

- name: test
  image: golang:1.21
  commands:
  - go test -v ./...
  - go test -race -coverprofile=coverage.out ./...

- name: lint
  image: golangci/golangci-lint:latest
  commands:
  - golangci-lint run

trigger:
  branch:
  - main
  - develop
  event:
  - push
  - pull_request

Kubernetesネイティブパイプライン

# .drone.yml
kind: pipeline
type: kubernetes
name: default

# リソース要求の定義
resources:
  requests:
    cpu: 1000
    memory: 1000MiB

steps:
- name: build
  image: node:18
  commands:
  - npm ci
  - npm run build
  resources:
    limits:
      cpu: 2000
      memory: 2000MiB

- name: test
  image: node:18
  commands:
  - npm test
  - npm run test:coverage

- name: security-scan
  image: node:18
  commands:
  - npm audit
  - npm run security:check

# サービスコンテナ
services:
- name: redis
  image: redis:7-alpine
- name: postgres
  image: postgres:15
  environment:
    POSTGRES_DB: testdb
    POSTGRES_USER: testuser
    POSTGRES_PASSWORD: testpass

# ボリュームマウント
volumes:
- name: cache
  temp: {}

Docker統合とマルチステージビルド

# .drone.yml
kind: pipeline
type: docker
name: default

steps:
- name: build-frontend
  image: node:18-alpine
  volumes:
  - name: cache
    path: /cache
  commands:
  - npm ci --cache /cache/.npm
  - npm run build
  - npm run test:unit

- name: build-backend
  image: golang:1.21-alpine
  volumes:
  - name: cache
    path: /go/pkg/mod
  commands:
  - go mod download
  - go build -o app .
  - go test ./...

- name: docker-build
  image: plugins/docker
  settings:
    repo: myregistry.com/myapp
    tags:
      - ${DRONE_COMMIT_SHA:0:8}
      - latest
    dockerfile: Dockerfile
    context: .
    registry: myregistry.com
    username:
      from_secret: docker_username
    password:
      from_secret: docker_password

- name: docker-scan
  image: aquasec/trivy
  commands:
  - trivy image myregistry.com/myapp:${DRONE_COMMIT_SHA:0:8}

volumes:
- name: cache
  temp: {}

trigger:
  branch:
  - main
  event:
  - push

マルチプラットフォーム・マルチアーキテクチャ

# .drone.yml - AMD64
---
kind: pipeline
type: docker
name: test-amd64

platform:
  os: linux
  arch: amd64

steps:
- name: test
  image: golang:1.21
  commands:
  - go build
  - go test -v ./...

---
# ARM64パイプライン
kind: pipeline
type: docker
name: test-arm64

platform:
  os: linux
  arch: arm64

steps:
- name: test
  image: golang:1.21
  commands:
  - go build
  - go test -v ./...

---
# Windowsパイプライン
kind: pipeline
type: docker
name: test-windows

platform:
  os: windows
  arch: amd64
  version: 1909

steps:
- name: test
  image: golang:1.21-windowsservercore-1909
  commands:
  - go build
  - go test -v ./...

---
# 依存関係の定義
kind: pipeline
type: docker
name: deploy

depends_on:
- test-amd64
- test-arm64
- test-windows

steps:
- name: deploy
  image: alpine
  commands:
  - echo "All tests passed, deploying..."

プラグインとサービス統合

# .drone.yml
kind: pipeline
type: docker
name: default

steps:
- name: build
  image: node:18
  commands:
  - npm ci
  - npm run build

- name: test
  image: node:18
  environment:
    DATABASE_URL: postgres://testuser:testpass@postgres:5432/testdb
    REDIS_URL: redis://redis:6379
  commands:
  - npm run test:integration
  depends_on:
  - postgres
  - redis

- name: sonarqube
  image: sonarqube/sonar-scanner-cli
  environment:
    SONAR_HOST_URL: https://sonarqube.company.com
    SONAR_LOGIN:
      from_secret: sonar_token
  commands:
  - sonar-scanner

- name: slack-notify
  image: plugins/slack
  settings:
    webhook:
      from_secret: slack_webhook
    channel: "#ci-cd"
    username: drone
    template: >
      {{#success build.status}}
        ✅ Build {{build.number}} succeeded. Branch: {{build.branch}}
      {{else}}
        ❌ Build {{build.number}} failed. Branch: {{build.branch}}
      {{/success}}
  when:
    status:
    - success
    - failure

- name: deploy-staging
  image: plugins/ansible
  settings:
    playbook: deploy.yml
    inventory: staging
    private_key:
      from_secret: ansible_key
  when:
    branch:
    - develop

- name: deploy-production
  image: plugins/ansible
  settings:
    playbook: deploy.yml
    inventory: production
    private_key:
      from_secret: ansible_key
  when:
    branch:
    - main
    event:
    - tag

services:
- name: postgres
  image: postgres:15
  environment:
    POSTGRES_DB: testdb
    POSTGRES_USER: testuser
    POSTGRES_PASSWORD: testpass

- name: redis
  image: redis:7-alpine

volumes:
- name: docker-sock
  host:
    path: /var/run/docker.sock

条件付き実行とマトリックスビルド

# .drone.yml
kind: pipeline
type: docker
name: test-matrix

strategy:
  matrix:
    NODE_VERSION:
    - "16"
    - "18"
    - "20"
    ENVIRONMENT:
    - "test"
    - "staging"

steps:
- name: test
  image: node:${NODE_VERSION}
  environment:
    NODE_ENV: ${ENVIRONMENT}
  commands:
  - npm ci
  - npm run test:${ENVIRONMENT}

---
kind: pipeline
type: docker
name: security-scan

steps:
- name: vulnerability-scan
  image: aquasec/trivy
  commands:
  - trivy fs .

- name: secret-scan
  image: trufflesecurity/trufflehog
  commands:
  - trufflehog filesystem .

- name: license-check
  image: licensefinder/license_finder
  commands:
  - license_finder

trigger:
  event:
  - pull_request

---
kind: pipeline
type: docker
name: production-deploy

steps:
- name: deploy
  image: kubectl
  environment:
    KUBECONFIG:
      from_secret: kubeconfig
  commands:
  - kubectl apply -f k8s/
  - kubectl rollout status deployment/myapp

trigger:
  branch:
  - main
  event:
  - push

depends_on:
- test-matrix
- security-scan

---
# Signature(設定ファイル検証用)
kind: signature
hmac: F10E2821BBBEA527EA02200352313BC059445190

ConfigMapとSecretの活用(Kubernetes)

# .drone.yml
kind: pipeline
type: kubernetes
name: default

steps:
- name: build
  image: node:18
  volumes:
  - name: build-config
    path: /config
  - name: secrets
    path: /secrets
  environment:
    DATABASE_URL:
      from_secret: database_url
    API_KEY:
      from_secret: api_key
  commands:
  - echo "Building with config from $(cat /config/environment)"
  - npm ci
  - npm run build

- name: test
  image: node:18
  volumes:
  - name: test-data
    path: /test-data
  commands:
  - npm test
  - npm run test:integration

- name: publish
  image: plugins/docker
  settings:
    repo: myregistry.com/myapp
    registry: myregistry.com
    username:
      from_secret: registry_username
    password:
      from_secret: registry_password
    tags:
    - ${DRONE_COMMIT_SHA}
    - latest

volumes:
- name: build-config
  config_map:
    name: build-config
    default_mode: 420

- name: secrets
  secret:
    secret_name: app-secrets

- name: test-data
  empty_dir: {}

image_pull_secrets:
- regcred