🔗 Inhaltsverzeichnis
CI/CD PipelinesGitHub Actions, Jenkins & GitLab CI
Vollautomated Deployment-Pipelines mit GitHub Actions, Jenkins und GitLab CI – Konzepte, Vergleich und best practices für moderne Software Development.
💡 Was ist CI/CD?
Continuous Integration (CI) und Continuous Delivery/Deployment (CD) sind Praktiken, die darauf abzielen, den Software Developmentsprozess durch Automation zu beschleunigen und zu verbessern. Eine CI/CD-Pipeline automatisiert die Schritte von der Codeänderung bis zur Auslieferung an die Benutzer.
- Continuous Integration (CI): Developers regularly integrate code into a central repository. Each push triggers an automated build and test.
- Continuous Delivery (CD): Extension of CI in which code changes are automatically deployed to a production-like environment (staging). Deployment to production is done manually.
- Continuous Deployment (CDP): Every code change that passes all tests is automatically deployed to production.
GitHub Actions
GitHub Actions ist eine CI/CD-Plattform, die direkt in GitHub integriert ist. Workflows werden in YAML-Dateien definiert und können auf Ereignisse im Repository reagieren (z.B. Push, Pull Request).
Beispiel Workflow (Node.js):
name: Node.js CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- run: npm ci
- run: npm run build --if-present
- run: npm test
Vorteile:
- Tiefe Integration mit GitHub Repositories.
- Large selection of ready-made promotions in the Marketplace.
- Support for Linux, macOS, Windows, ARM and containers.
- Generous free contingents for public and private repos.
⚙️ Jenkins
Jenkins ist ein weit verbreiteter, Open-Source Automationsserver. Er ist extrem flexibel und erweiterbar durch tausende von Plugins. Pipelines können über die UI (klassisch) oder als Code (Jenkinsfile) definiert werden.
Beispiel Jenkinsfile (Declarative Pipeline):
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'npm install'
sh 'npm run build'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
// Deploy-Schritte hier
}
}
}
}
Vorteile:
- Very high flexibility and adaptability.
- Huge community and plugin ecosystem.
- On-premise or cloud deployment possible.
- Supports complex and distributed builds.
🦊 GitLab CI/CD
GitLab CI/CD ist tief in die GitLab-Plattform integriert und bietet eine umfassende DevOps-Lösung aus einer Hand. Pipelines werden in einer `.gitlab-ci.yml`-Datei im Repository definiert.
Beispiel .gitlab-ci.yml:
image: node:18
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- npm install
- npm run build
test_job:
stage: test
script:
- npm test
deploy_job:
stage: deploy
script:
- echo "Deploying application..."
# Deploy-Skripte hier
only:
- main # Nur auf dem main branch deployen
Vorteile:
- Nahtlose Integration in den GitLab-Workflow (Issues, Merge Requests, Registry).
- Eingebaute Container Registry und Kubernetes-Integration.
- Auto DevOps for automatic pipeline creation.
- Available as SaaS (GitLab.com) or self-managed.
🛠️ Werkzeuge im Vergleich
Kriterium | GitHub Actions | Jenkins | GitLab CI |
---|---|---|---|
Hosting | Cloud (GitHub) | Self-Managed / Cloud | Cloud (GitLab) / Self-Managed |
Configuration | YAML | Groovy (Jenkinsfile) / UI | YAML |
Integration | Sehr gut mit GitHub | Extrem viele Plugins | Sehr gut mit GitLab |
Kosten (Basis) | Free for public repos, freemium for private repos | Open Source (kostenlos) | Free for public repos, freemium for private repos |
🔢 Pipeline Phasen
Eine typische CI/CD-Pipeline besteht aus mehreren Phasen:
- Source: Code changes are pushed to the repository.
- Build: Der Code wird kompiliert, Artefakte werden erstellt.
- Test: Automated tests (unit, integration, etc.) are executed.
- Deploy (Staging): Die Anwendung wird in einer Testumgebung bereitgestellt.
- Deploy (Production): (Nach manueller oder automatischer Freigabe) Die Anwendung wird in der Manufacturingsumgebung bereitgestellt.
👍 best practices
- Pipeline as Code: Definiere Pipelines in versioniertem Code (z.B. YAML, Jenkinsfile).
- Fast feedback: Optimize pipelines for short throughput times.
- Atomare Builds: Jeder Build sollte ein potenziell auslieferbares Inkrement sein.
- Umfassende Testautomatisierung: Vertrauen in die Pipeline durch gute Testabdeckung.
- Secrets Management: Secure management of passwords and keys.
- Monitoring: Monitor both the pipeline and the deployed application.
- Idempotent deployments: Repeated deployments should lead to the same result.
🛡️ DevSecOps in CI/CD
DevSecOps integriert Secureheitspraktiken ("Security as Code") in jede Phase der CI/CD-Pipeline:
- Static Application Security Testing (SAST): Code-Analyse auf Schwachstellen.
- Software Composition Analysis (SCA): Checking dependencies.
- Dynamic Application Security Testing (DAST): Tests der laufenden Anwendung.
- Container Image Scanning: Security check of Docker images.
- Infrastructure as Code (IaC) Scanning: Checking Terraform, CloudFormation etc.