This document provides detailed and professional CI/CD pipeline configurations for GitHub Actions, GitLab CI, and Jenkins. These configurations are designed to be comprehensive, covering essential stages such as linting, testing, building, and deployment, and are tailored for a generic containerized application, offering a robust foundation for your development workflow.
This deliverable fulfills the generate_configs step of the "DevOps Pipeline Generator" workflow. We have generated complete CI/CD pipeline configurations for three leading platforms: GitHub Actions, GitLab CI, and Jenkins. Each configuration includes a structured approach to automate your software delivery process, ensuring code quality, reliability, and efficient deployment.
The provided examples are designed for a hypothetical Node.js application that is containerized using Docker. While the specific commands will need adjustment for your application's language, framework, and deployment target, the overall structure, stages, and best practices are universally applicable.
The following assumptions and considerations have guided the generation of these configurations:
npm or yarn).main (or master) triggers production deployments, and feature branches trigger CI.Each generated pipeline incorporates the following critical stages:
* Purpose: Enforces code style, catches potential errors, and ensures consistency across the codebase.
* Actions: Runs linters (e.g., ESLint for Node.js, Black/Flake8 for Python, Checkstyle for Java).
* Outcome: Fails the pipeline if linting issues are found.
* Purpose: Verifies the correctness and functionality of the application.
* Actions: Executes unit tests, integration tests, and potentially end-to-end tests.
* Outcome: Fails the pipeline if tests fail. Generates test reports.
* Purpose: Compiles source code, packages artifacts, and creates deployable images.
* Actions: Installs dependencies, compiles code (if applicable), builds a Docker image, and tags it appropriately.
* Outcome: A deployable artifact (e.g., Docker image) is created and potentially pushed to a registry.
* Purpose: Releases the built application to a target environment.
* Actions: Pushes the Docker image to a container registry, and then triggers an update or deployment to a specific environment (e.g., Staging, Production). This stage is highly customizable based on your infrastructure.
* Outcome: Application is running in the specified environment.
GitHub Actions provides a flexible and powerful way to automate workflows directly within your GitHub repository.
.github/workflows/ci-cd.ymlpush events on main branch and pull_request events on any branch.lint, test, build, deploy.DOCKER_USERNAME, DOCKER_PASSWORD, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY).#### 4.3. Customization Notes for GitHub Actions * **Node.js Version & Cache:** Adjust `NODE_VERSION` and `cache` type (`npm` or `yarn`) as needed. * **Build Commands:** Modify `npm ci`, `npm run lint`, `npm test` to match your project's build tools (e.g., `mvn install`, `pip install`, `go test`). * **Docker Image Naming:** Update `DOCKER_IMAGE_NAME` and `CONTAINER_REGISTRY`. * **Deployment Logic:** The `deploy` stage is a placeholder. You **must** replace the `run` command with your specific deployment logic (e.g., `kubectl`, `aws cli`, `az cli`, `gcloud cli`, Ansible, Terraform, custom scripts). * **Secrets:** Configure `DOCKER_USERNAME`, `DOCKER_PASSWORD`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` (or equivalent for your cloud provider) in your GitHub repository secrets. * **Environments:** Leverage GitHub Environments for deployment protection rules and environment-specific secrets. * **Conditional Deployments:** The `if: github.ref == 'refs/heads/main'` ensures deployment only from the main branch. Adjust for staging/production deployments based on branch names. --- ### 5. GitLab CI Configuration GitLab CI is deeply integrated with GitLab repositories, providing a seamless CI/CD experience. #### 5.1. Overview * **File Location:** `.gitlab-ci.yml` * **Trigger:** `push` events on `main` branch and `merge_request` events. * **Stages:** `lint`, `test`, `build`, `deploy`. * **Secrets:** Utilizes GitLab CI/CD Variables for sensitive information. * **Docker-in-Docker:** Often used for building Docker images within GitLab CI runners. #### 5.2. Example YAML Configuration
Workflow: DevOps Pipeline Generator
Step: gemini → analyze_infrastructure_needs
Description: This step thoroughly analyzes the foundational infrastructure requirements and existing ecosystem to inform the generation of robust, efficient, and secure CI/CD pipeline configurations. Understanding these needs is critical for tailoring the pipeline to your specific environment and ensuring optimal performance and maintainability.
This deliverable initiates the "DevOps Pipeline Generator" workflow by providing a comprehensive analysis of the infrastructure considerations essential for designing effective CI/CD pipelines. Given the broad nature of "DevOps Pipeline Generator," this analysis focuses on identifying key decision points, potential challenges, and best practices that will guide the subsequent steps of pipeline configuration. The goal is to lay a solid foundation, ensuring the generated pipelines (for GitHub Actions, GitLab CI, or Jenkins) are perfectly aligned with your operational context, technology stack, and strategic objectives.
To generate a truly effective CI/CD pipeline, a detailed understanding of the underlying infrastructure and existing tooling is paramount. Below are the critical areas we must analyze:
* Platform: GitHub, GitLab, Bitbucket, Azure DevOps Repos, others.
* Branching Strategy: GitFlow, GitHub Flow, GitLab Flow, Trunk-based development.
* Repository Structure: Monorepo vs. Polyrepo.
* Languages: Python, Java (Maven/Gradle), Node.js (npm/Yarn), .NET (MSBuild/dotnet CLI), Go, Ruby, PHP, etc.
* Frameworks: Spring Boot, Django, React, Angular, Vue.js, ASP.NET Core.
* Database: PostgreSQL, MySQL, MongoDB, SQL Server, etc. (for integration testing).
* Containerization: Docker, Kubernetes manifests.
* Cloud Provider: AWS, Azure, Google Cloud Platform (GCP), On-premises.
* Deployment Model:
* Virtual Machines (VMs): EC2, Azure VMs, Compute Engine, dedicated servers.
* Container Orchestration: Kubernetes (EKS, AKS, GKE, OpenShift), ECS, Azure Container Instances.
* Serverless: AWS Lambda, Azure Functions, Google Cloud Functions.
* Platform-as-a-Service (PaaS): Heroku, AWS Elastic Beanstalk, Azure App Service, Google App Engine.
* Networking: VPCs, subnets, security groups, firewalls, load balancers.
* Infrastructure as Code (IaC): Terraform, AWS CloudFormation, Azure Resource Manager (ARM) templates, Pulumi.
* Container Registries: Docker Hub, AWS ECR, Azure Container Registry (ACR), Google Container Registry (GCR).
* Package Managers: Maven Central, JFrog Artifactory, Sonatype Nexus, npm registry, PyPI.
* Object Storage: AWS S3, Azure Blob Storage, Google Cloud Storage.
* Secrets Management: AWS Secrets Manager, Azure Key Vault, Google Secret Manager, HashiCorp Vault.
* Vulnerability Scanning: SAST (Static Application Security Testing - SonarQube, Snyk), DAST (Dynamic Application Security Testing - OWASP ZAP), SCA (Software Composition Analysis).
* Compliance: GDPR, HIPAA, PCI DSS, SOC 2.
* Access Control: IAM roles, service principles, least privilege principles.
* Logging: ELK Stack (Elasticsearch, Logstash, Kibana), Splunk, Datadog, AWS CloudWatch, Azure Monitor, Google Cloud Logging.
* Monitoring: Prometheus, Grafana, Datadog, New Relic, AppDynamics.
Understanding current trends is crucial for building future-proof pipelines.
* GitHub Actions: Rapidly growing due to its tight integration with GitHub repositories, extensive marketplace of actions, and developer-friendly YAML syntax. Ideal for projects already on GitHub.
* GitLab CI: Offers a comprehensive, single-platform solution from SCM to CI/CD, container registry, and security scanning. Strong choice for those fully invested in the GitLab ecosystem.
* Jenkins: Remains a powerful, highly customizable, and extensible option, especially for complex on-premises environments or scenarios requiring deep integration with a wide array of legacy tools. Its plugin ecosystem is unparalleled.
Based on the analysis of infrastructure needs and industry trends, we recommend the following strategic approaches:
To proceed with generating tailored CI/CD pipeline configurations, we require specific details about your current environment and preferences. The next step will involve a deeper dive into these areas.
Actionable Next Steps for the Customer:
By providing these details, we can move efficiently to the next stage of Pipeline Design and Configuration, ensuring the generated pipelines are perfectly optimized for your infrastructure and development practices.
yaml
stages:
- lint
- test
- build
- deploy
variables:
NODE_VERSION: '18.x'
DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE # Uses GitLab's built-in image name variable
DOCKER_DRIVER: overlay2 # Recommended for Docker-in-Docker
default:
image: node:${NODE_VERSION}-alpine # Base image for linting and testing jobs
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
policy: pull-push
.install_dependencies:
before_script:
- npm ci --cache .npm --prefer-offline # or yarn install --frozen-lockfile
lint:
stage: lint
script:
- !reference [.install_dependencies, before_script]
- npm run lint # Assumes a 'lint' script in package.json
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
test:
stage: test
script:
- !reference [.install_dependencies, before_script]
- npm test # Assumes a 'test' script in package.json
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
artifacts:
when: always
reports:
junit: junit.xml # Path to your test report (e.g., from Jest/Mocha with JUnit reporter)
build:
stage: build
image: docker:20.10.16-dind-alpine3.16 # Docker-in-Docker image for building Docker images
services:
- docker:20.10.16-dind
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $DOCKER_IMAGE_NAME:$CI
This document provides detailed and actionable CI/CD pipeline configurations for GitHub Actions, GitLab CI, and Jenkins, encompassing essential stages such as linting, testing, building, and deployment. These configurations are designed to provide a robust foundation for automating your software delivery process, ensuring code quality, reliability, and efficient deployment.
The generated pipelines are structured to follow best practices in modern software development, promoting continuous integration and continuous delivery. Each configuration is tailored to its respective platform while maintaining a consistent logical flow across stages.
Key Benefits:
Each generated pipeline includes the following fundamental stages:
* Purpose: Static code analysis to identify stylistic issues, potential bugs, and non-compliance with coding standards.
* Outcome: Early detection of code quality problems before compilation or testing.
* Purpose: Execution of unit, integration, and (optionally) end-to-end tests to validate application functionality and prevent regressions.
* Outcome: Assurance that new changes do not break existing features and that new features work as expected.
* Purpose: Compiling source code, resolving dependencies, and packaging the application into a deployable artifact (e.g., Docker image, JAR, WAR, executable, frontend bundle).
* Outcome: A ready-to-deploy artifact that is consistent and versioned.
* Purpose: Automating the release of the built artifact to a target environment (e.g., development, staging, production).
* Outcome: The application is live and accessible in the specified environment.
GitHub Actions provides a flexible way to automate workflows directly within your GitHub repository.
File: .github/workflows/main.yml
name: CI/CD Pipeline
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
env:
NODE_VERSION: '18.x' # Example: Specify Node.js version
jobs:
lint:
name: Lint Code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run linter (ESLint example)
run: npm run lint # Assumes 'lint' script in package.json
test:
name: Run Tests
runs-on: ubuntu-latest
needs: lint # This job depends on 'lint' completing successfully
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run unit and integration tests (Jest example)
run: npm test # Assumes 'test' script in package.json
# - name: Upload test results (e.g., for coverage)
# uses: actions/upload-artifact@v4
# with:
# name: test-results
# path: coverage/
build:
name: Build Application
runs-on: ubuntu-latest
needs: test # This job depends on 'test' completing successfully
outputs:
image_tag: ${{ steps.docker_build.outputs.image_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Docker Hub (or other registry)
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker image
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: your-docker-repo/your-app:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
# - name: Upload build artifact (e.g., for non-Docker builds)
# uses: actions/upload-artifact@v4
# with:
# name: build-artifact
# path: dist/your-app.zip # Adjust path as needed
deploy:
name: Deploy to Environment
runs-on: ubuntu-latest
needs: build # This job depends on 'build' completing successfully
environment:
name: Production # Or Staging, Development
if: github.ref == 'refs/heads/main' # Only deploy 'main' branch to Production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download build artifact (if not Docker)
uses: actions/download-artifact@v4
with:
name: build-artifact
path: ./dist # Adjust path as needed
- name: Deploy to AWS EKS (example using kubectl)
uses: azure/k8s-set-context@v3 # Or other cloud provider setup
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Update Kubernetes deployment
run: |
kubectl set image deployment/your-app your-app-container=your-docker-repo/your-app:${{ needs.build.outputs.image_tag }} -n your-namespace
kubectl rollout status deployment/your-app -n your-namespace
env:
KUBECONFIG: ${{ secrets.KUBE_CONFIG_PATH }} # Path to kubeconfig if not using in-action method
# - name: Alternative: Deploy to AWS S3 (e.g., for static sites)
# uses: jakejarvis/s3-sync-action@master
# with:
# args: --acl public-read --follow-symlinks --delete
# env:
# AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: 'us-east-1'
Key Features for GitHub Actions:
push and pull_request events for specified branches.needs keyword ensures sequential execution of stages.secrets.DOCKER_USERNAME, secrets.KUBE_CONFIG, etc.) for sensitive information.actions/checkout, docker/login-action, etc.).environment for deployment, allowing for environment-specific secrets and protections.GitLab CI is an integrated part of GitLab, allowing you to define your pipeline directly in your repository.
File: .gitlab-ci.yml
stages:
- lint
- test
- build
- deploy
variables:
DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE/$CI_PROJECT_NAME
DOCKER_IMAGE_TAG: $CI_COMMIT_SHA
NODE_VERSION: '18.x' # Example: Specify Node.js version
lint_job:
stage: lint
image: node:${NODE_VERSION}-alpine # Use a Docker image for the job environment
script:
- npm install
- npm run lint # Assumes 'lint' script in package.json
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "develop"
when: always
test_job:
stage: test
image: node:${NODE_VERSION}-alpine
script:
- npm install
- npm test # Assumes 'test' script in package.json
artifacts:
when: always
reports:
junit: junit.xml # Example: For test report parsing
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "develop"
when: always
build_job:
stage: build
image: docker:latest # Use Docker image with Docker-in-Docker (dind) capabilities
services:
- docker:dind # Required for building Docker images
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG .
- docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG
rules:
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "develop"
when: always
deploy_production_job:
stage: deploy
image: alpine/helm:3.9.0 # Example: Use a Helm client image for Kubernetes deployment
dependencies:
- build_job # Explicitly declare dependency
needs: ["build_job"]
variables:
KUBE_CONTEXT: "my-kubernetes-cluster" # Define your Kubernetes context
script:
- echo "$KUBE_CONFIG" > kubeconfig.yaml # KUBE_CONFIG should be a CI/CD variable
- export KUBECONFIG=$(pwd)/kubeconfig.yaml
- kubectl config use-context $KUBE_CONTEXT
- kubectl set image deployment/your-app your-app-container=$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG -n your-namespace
- kubectl rollout status deployment/your-app -n your-namespace
# - helm upgrade --install your-app ./helm-chart -n your-namespace --set image.tag=$DOCKER_IMAGE_TAG
environment:
name: Production
url: https://your-app.your-domain.com
rules:
- if: $CI_COMMIT_BRANCH == "main"
when: manual # Manual deployment to production for safety
# when: on_success # Uncomment for automatic deployment
Key Features for GitLab CI:
stages and individual jobs that run within those stages.services keyword allows Docker commands to be run within a job, essential for building Docker images.$CI_REGISTRY_IMAGE, $CI_COMMIT_SHA).rules keyword provides fine-grained control over when jobs run based on branch, event, etc.needs keyword ensures job execution order.Jenkins offers a powerful automation server. Declarative Pipelines are a modern way to define CI/CD pipelines as code in a Jenkinsfile.
File: Jenkinsfile