🚁

Drone

CI/CD & DevOps

Sehatra fampidirana mitohy avy amin'ny container-native miaraka amin'ny fikirakirana YAML tsotra

Lazan'ny fampidirana

fanapariahana: 2-5 minitra
sokajy: CI/CD & DevOps
RAM ambany indrindra: 1024MB
MANAMPY: Tickets sy mailaka

Zarao ity toro-làlana ity

Topy maso

Drone dia platform CI/CD (integration continue sy delivery continue) natao ho an'ny container ary natsangana eo ambonin'ny Docker. Mahasolo azy ny fomba fiasany tsotra, ny maivana ary ny maritrano natao ho an'ny cloud, izay mahatonga azy ho mora hametrahana, hanitatra ary hitazonana. Tsy toy ny rafitra CI/CD nentim-paharetana izay mitaky infrastructure sy configuration be, Drone dia mihazakazaka ho binary tokana maivana misy fiankinana vitsy, izay tena mety ho an'ny ekipa rehetra habe.

Ny zava-manavaka an'i Drone dia ny fomba fanaovana pipeline ao anaty container: samy build mihazakazaka ao anaty container Docker mitokana, mampanantena build madio sy azo averina tsy misy fifandonana. Ny configuration pipeline-nao dia YAML tsotra voatahiry ao amin'ny repository-nao, izay mamela azy ho mora hotanana version sy hanakambanana amin'ny tetikasa maro. Drone dia mandrenesa ho azy rehefa mipetraka ny kaodinao, mamoaka pull request, na mamaritra release, ka mampihetsika ny pipeline mety avy hatrany.

Ny ecosystem plugin an'i Drone dia lehibe, misy plugin an-jatony natao amin'ny vondrom-piarahamonina ho an'ny fametrahana any amin'ny AWS, Kubernetes, registry Docker, fampandrenesana Slack, ary maro hafa. Satria Docker-native izy, azonao atao ny mampihazakazaka image Docker rehetra ho dingana pipeline, ka mahazo fahafaha-mampiasa tsy voafetra. Mila mametraka test amin'ny Python 3.11? Mametraka any amin'ny AWS? Mandefa fampandrenesana Slack? Ampiasao fotsiny ny image Docker mety ao amin'ny pipeline-nao.

Ny platform dia manohana ny rafitra version control lehibe rehetra, anisan'izany GitHub, GitLab, Bitbucket ary Gitea, miaraka amin'ny fampidirana OAuth natiora ho an'ny fanamarinana tsy misy olana. Drone dia afaka mitombo horizontal amin'ny fampidirana node runner maro, mikarakara build an-jatony mitovy amin'ny server maro. Ny maritrano tsy misy fanjakana dia mamela anao hitombo na hihena arakaraka ny filana, tsy misy fandaharana cluster sarotra.

Drone dia manome endri-javatra matanjaka toy ny build matrix ho an'ny fitsapana amin'ny version maro, fanatanterahana misy fepetra arakaraka ny lakile na tag, fitantanana secret ho an'ny fitahirizana taratasy azo antoka, ary cache build mba hanafohezana ny build atao indray. Ny interface web dia madio sy mora ampiasaina, mampiseho log mivaovao, tantaran'ny build ary fahitana antsipiriany ny dingana pipeline tsirairay.

Ho an'ny ekipa entreprise, Drone dia manome endri-javatra mandroso toy ny RBAC (role-based access control), log audit, ary ny fahafahana manakana ny repository izay afaka mampiasa plugin inona. Ny fahaiza-manao autoscaling dia mahatonga azy ho mora vidy: mampiditra runner raha misy build miandry, ary mampiala azy rehefa tsy miasa, tena mety ho an'ny tontolo cloud izay mandoa isaky ny minitra.

Drone dia open source miaraka amin'ny version community sy entreprise. Ny version community dia feno endri-javatra ary tsara ho an'ny ekipa kely na antonony, fa ny version entreprise dia manampy fifanarahana fanohanana, fiarovana mandroso ary fanohanana laharam-pahamehana. Na startup ianao na entreprise, Drone dia mitombo mifanaraka amin'ny filanao.

Famaritana fototra

Pipeline natiora container

Samy dingana build mihazakazaka ao anaty container Docker mitokana ho an'ny build madio sy azo averina tsy misy fiankinana

Configuration YAML tsotra

Pipeline ho kaody miaraka amin'ny syntaxe YAML mora azo hazavaina, voatahiry ao amin'ny repository-nao

Ecosystem plugin lehibe

Plugin an-jatony ho an'ny fametrahana, fampandrenesana, fitsapana ary fampifandraisana amin'ny serivisy rehetra

Runner mihetsika ho azy

Fitomboana horizontal miaraka amin'ny node runner maro, mampiditra/manala ho azy arakaraka ny halalin'ny foloka

Fampifandraisana VCS natiora

Fanohanana voalohany ho an'ny GitHub, GitLab, Bitbucket, Gitea miaraka amin'ny OAuth sy automation webhook ho azy

Fitantanana secret

Fitahirizana secret voaisy miaraka amin'ny fifehezana access mazava ho an'ny repository na organisation tsirairay

Fomba fampiasana

• CI/CD mikraoserivisy: Mamorona sy mametraka mikraoserivisy maro miaraka amin'ny pipeline misaraka sy ao anaty container ho an'ny serivisy tsirairay
• Tetikasa fiteny maro: Manandrana tetikasa amin'ny fiteny/version samihafa amin'ny alalan'ny build matrix (Python 3.8-3.11, Node 14-18 sy hafa)
• Fanamboarana image Docker: Mamorona, manome tag ary mandefa image Docker any amin'ny registry toy ny Docker Hub, AWS ECR, na registry manokana
• Fametrahana Kubernetes: Mampiasa fametrahana Kubernetes ho azy amin'ny alalan'ny chart Helm na plugin kubectl aorian'ny build vita soa aman-tsara
• Fitsapana pull request: Mihazakazaka ho azy ny test amin'ny PR tsirairay alohan'ny fampidirana, miaraka amin'ny status check mifandray amin'ny GitHub/GitLab
• Fametrahana amin'ny tontolo maro: Mametraka any amin'ny tontolo dev/staging/production arakaraka ny lamaina sy ny fankatoavana manual
• Infrastructure ho kaody: Mitsapa sy mametraka configuration Terraform, CloudFormation na Ansible amin'ny pipeline ho azy

Toro-làlana fametrahana

Fametrahana amin'ny Ubuntu VPS:

1. Apetraho Docker (raha tsy efa voaomana):
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Add current user to docker group
sudo usermod -aG docker $USER
newgrp docker

# Verify installation
docker --version
2. Mamorona configuration server Drone:
# Create directory for Drone
sudo mkdir -p /var/lib/drone
sudo chown -R $USER:$USER /var/lib/drone

# Create environment file
cat > /var/lib/drone/.env <<'EOF'
# Drone Server Settings
DRONE_SERVER_HOST=drone.yourdomain.com
DRONE_SERVER_PROTO=https
DRONE_RPC_SECRET=$(openssl rand -hex 16)
DRONE_DATABASE_DRIVER=sqlite3
DRONE_DATABASE_DATASOURCE=/data/database.sqlite

# GitHub Integration (or use GitLab/Bitbucket)
DRONE_GITHUB_CLIENT_ID=your_github_oauth_app_id
DRONE_GITHUB_CLIENT_SECRET=your_github_oauth_secret

# Admin user (your GitHub username)
DRONE_USER_CREATE=username:yourgithubusername,admin:true

# Optional: Enable registration
DRONE_REGISTRATION_CLOSED=false
EOF
3. Mamorona secret RPC:
# Generate a secure RPC secret
openssl rand -hex 16
# Update DRONE_RPC_SECRET in .env file
4. Apetraho application OAuth GitHub:
- Mandehana any amin'ny: https://github.com/settings/applications/new
- Anaran'ny application: Drone CI
- URL pejy fanombohana: https://drone.yourdomain.com
- URL callback fankatoavana: https://drone.yourdomain.com/login
- Dakozy ny Client ID sy Client Secret ao amin'ny rakitra .env

5. Manomboka ny server Drone:
docker run   --volume=/var/lib/drone:/data   --env-file=/var/lib/drone/.env   --publish=8080:80   --publish=443:443   --restart=always   --detach=true   --name=drone   drone/drone:2
6. Jereo ny server Drone:
# Check container status
docker ps | grep drone

# Check logs
docker logs drone

# Test web interface
curl http://localhost:8080
7. Apetraho runner Drone (runner Docker):
docker run --detach   --volume=/var/run/docker.sock:/var/run/docker.sock   --env=DRONE_RPC_PROTO=http   --env=DRONE_RPC_HOST=localhost:8080   --env=DRONE_RPC_SECRET=your_rpc_secret_from_env   --env=DRONE_RUNNER_CAPACITY=2   --env=DRONE_RUNNER_NAME=my-first-runner   --publish=3000:3000   --restart=always   --name=runner   drone/drone-runner-docker:1
8. Ampifanaraho proxy famerenana Nginx (famokarana):
sudo nano /etc/nginx/sites-available/drone

# Add this configuration:
server {
    listen 80;
    server_name drone.yourdomain.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

# Enable site
sudo ln -s /etc/nginx/sites-available/drone /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
9. Apetraho SSL amin'ny Let's Encrypt:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d drone.yourdomain.com
10. Mamorona pipeline ohatra (.drone.yml):
kind: pipeline
type: docker
name: default

steps:
  - name: test
    image: node:18
    commands:
      - npm install
      - npm test

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

  - name: docker
    image: plugins/docker
    settings:
      repo: yourusername/yourapp
      tags: latest
      username:
        from_secret: docker_username
      password:
        from_secret: docker_password
    when:
      branch:
        - main
11. Mampiditra repository:
- Hiditra amin'ny interface web Drone: https://drone.yourdomain.com
- Hamarino ny fidirana amin'ny GitHub
- Asaivo ny repository-nao
- Mandefasa ny .drone.yml any amin'ny repo-nao
- Jereo ny build mihetsika ho azy!

12. Ampidiro secret (amin'ny alalan'ny CLI na UI):
# Install Drone CLI
curl -L https://github.com/harness/drone-cli/releases/latest/download/drone_linux_amd64.tar.gz | tar zx
sudo install -t /usr/local/bin drone

# Configure CLI
export DRONE_SERVER=https://drone.yourdomain.com
export DRONE_TOKEN=your_user_token_from_ui

# Add secrets
drone secret add --repository yourusername/yourrepo --name docker_username --data yourvalue
drone secret add --repository yourusername/yourrepo --name docker_password --data yourvalue

Torohevitra momba ny kirakira

Configuration ilaina:

1. Configuration server (rakitra .env):
# Core Settings
DRONE_SERVER_HOST=drone.example.com
DRONE_SERVER_PROTO=https
DRONE_RPC_SECRET=supersecretkey

# Database
DRONE_DATABASE_DRIVER=postgres
DRONE_DATABASE_DATASOURCE=postgres://user:pass@localhost:5432/drone?sslmode=disable

# VCS Integration (GitHub example)
DRONE_GITHUB_CLIENT_ID=github_oauth_app_id
DRONE_GITHUB_CLIENT_SECRET=github_oauth_secret

# User Management
DRONE_USER_CREATE=username:admin,admin:true
DRONE_USER_FILTER=organization_name  # Only allow specific org
2. Configuration pipeline (.drone.yml) - Fototra:
kind: pipeline
type: docker
name: build-test-deploy

steps:
  - name: install
    image: node:18
    commands:
      - npm ci

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

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

  - name: deploy
    image: plugins/ssh
    settings:
      host: production.example.com
      username: deploy
      key:
        from_secret: ssh_private_key
      script:
        - cd /var/www/app
        - git pull
        - npm install
        - pm2 restart app
    when:
      branch:
        - main
3. Build matrix (version maro):
kind: pipeline
type: docker
name: matrix-test

steps:
  - name: test
    image: python:${PYTHON_VERSION}
    commands:
      - pip install -r requirements.txt
      - pytest

matrix:
  PYTHON_VERSION:
    - "3.8"
    - "3.9"
    - "3.10"
    - "3.11"
4. Build sy push Docker:
kind: pipeline
type: docker
name: docker-build

steps:
  - name: build-and-push
    image: plugins/docker
    settings:
      repo: username/myapp
      tags:
        - latest
        - ${DRONE_COMMIT_SHA:0:8}
      username:
        from_secret: docker_username
      password:
        from_secret: docker_password
      dockerfile: Dockerfile
      context: .
5. Fametrahana Kubernetes:
kind: pipeline
type: docker
name: k8s-deploy

steps:
  - name: deploy-to-k8s
    image: sinlead/drone-kubectl
    settings:
      kubernetes_server: https://k8s.example.com
      kubernetes_token:
        from_secret: k8s_token
      kubernetes_cert:
        from_secret: k8s_cert
    commands:
      - kubectl set image deployment/myapp myapp=username/myapp:${DRONE_COMMIT_SHA}
      - kubectl rollout status deployment/myapp
    when:
      branch:
        - main
6. Fanatanterahana misy fepetra:
kind: pipeline
type: docker
name: conditional-deploy

steps:
  - name: deploy-staging
    image: plugins/ssh
    commands:
      - deploy to staging
    when:
      branch:
        - develop

  - name: deploy-production
    image: plugins/ssh
    commands:
      - deploy to production
    when:
      branch:
        - main
      event:
        - push
        - tag

  - name: deploy-on-tag
    image: plugins/ssh
    commands:
      - deploy release
    when:
      event:
        - tag
      ref:
        - refs/tags/v*
7. Serivisy (database, Redis ho an'ny fitsapana):
kind: pipeline
type: docker
name: integration-tests

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

  - name: redis
    image: redis:7

steps:
  - name: test
    image: python:3.11
    environment:
      DATABASE_URL: postgres://testuser:testpass@postgres:5432/testdb
      REDIS_URL: redis://redis:6379
    commands:
      - pip install -r requirements.txt
      - pytest tests/integration/
8. Fitantanana secret:
# Via CLI
drone secret add --repository user/repo --name aws_access_key --data value
drone secret add --repository user/repo --name aws_secret_key --data value

# In pipeline
kind: pipeline
type: docker
name: default

steps:
  - name: deploy
    image: plugins/s3
    settings:
      access_key:
        from_secret: aws_access_key
      secret_key:
        from_secret: aws_secret_key
      bucket: my-bucket
      source: dist/**/*
9. Cache ny fiankinan'ny package:
kind: pipeline
type: docker
name: cached-build

steps:
  - name: restore-cache
    image: drillster/drone-volume-cache
    volumes:
      - name: cache
        path: /cache
    settings:
      restore: true
      mount:
        - ./node_modules

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

  - name: rebuild-cache
    image: drillster/drone-volume-cache
    volumes:
      - name: cache
        path: /cache
    settings:
      rebuild: true
      mount:
        - ./node_modules

volumes:
  - name: cache
    host:
      path: /var/lib/drone/cache
10. Fampandrenesana (Slack, mailaka):
kind: pipeline
type: docker
name: notify

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

  - name: slack
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack_webhook
      channel: deployments
      template: >
        {{#success build.status}}
          ✅ Build #{{build.number}} succeeded. Branch: {{build.branch}}
        {{else}}
          ❌ Build #{{build.number}} failed. Branch: {{build.branch}}
        {{/success}}
    when:
      status:
        - success
        - failure
Fomba tsara:
- Tehirizo ao amin'ny secret ny angona sensitive, aza mametraka mihitsy ao amin'ny .drone.yml
- Ampiasao tag image mazava (node:18) fa tsy latest
- Ahafaho ny cache ho an'ny build haingana kokoa (node_modules, package pip)
- Ampiasao serivisy ho an'ny fitsapana fampidirana amin'ny database tena izy
- Ampiharo ny build matrix mba hitsapana version maro
- Ampiasao fanatanterahana misy fepetra mba hisorohana fametrahana tsy ilaina
- Apetraho fiarovana sampana tsara (mametraka avy amin'ny main/master ihany)
- Jereo ny fahombiazan'ny build ary manatsara ny dingana miadana

Fandraisana an-tànana ara-teknika

Fandraisana an-tànana

  • Fahatsiarovana: 1024RAM 1 MB

Omeo isa ity lahatsoratra ity

★★★★★
-
Maka...

Vonona ny hametraka ny fampiharanao ve ianao? Drone?

Manomboka ao anatin'ny minitra vitsy amin'ny alalan'ny fizotry ny fametrahana tsotra VPS

Mandefa amin'ny manodidina ny 2 minitra • Full root access • Fanohanana amin'ny alalan'ny tapakila sy mailaka