5-CICD's
GitHub Cicd

Basic CI/CD Workflow for Node.js

Description

This workflow installs dependencies, runs tests, and builds a Node.js project.

Workflow File

name: Node.js CI/CD
 
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
 
jobs:
  build:
    runs-on: ubuntu-latest
 
    strategy:
      matrix:
        node-version: [14.x, 16.x]
 
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
 
    - name: Setup Node.js
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
 
    - name: Install dependencies
      run: npm install
 
    - name: Run tests
      run: npm test
 
    - name: Build project
      run: npm run build

Explanation

  • name: The name of the workflow.
  • on: Defines the events that trigger the workflow (push and pull_request on the main branch).
  • jobs: A list of jobs to run as part of the workflow.
  • runs-on: Specifies the type of runner to use (ubuntu-latest).
  • strategy: Defines a matrix of different Node.js versions to test against.
  • steps: A list of steps to execute in the job, including checking out the code, setting up Node.js, installing dependencies, running tests, and building the project.

CI/CD Workflow for Python Application

Description

This workflow installs dependencies, runs tests, and packages a Python application.

Workflow File

name: Python CI/CD
 
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
 
jobs:
  build:
    runs-on: ubuntu-latest
 
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
 
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.8'
 
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
 
    - name: Run tests
      run: |
        pytest
 
    - name: Package application
      run: |
        python setup.py sdist bdist_wheel

Explanation

  • name: The name of the workflow.
  • on: Defines the events that trigger the workflow (push and pull_request on the main branch).
  • jobs: A list of jobs to run as part of the workflow.
  • runs-on: Specifies the type of runner to use (ubuntu-latest).
  • steps: A list of steps to execute in the job, including checking out the code, setting up Python, installing dependencies, running tests, and packaging the application.

CI/CD Workflow for Docker

Description

This workflow builds and pushes a Docker image to Docker Hub.

Workflow File

name: Docker CI/CD
 
on:
  push:
    branches:
      - main
 
jobs:
  build:
    runs-on: ubuntu-latest
 
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
 
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1
 
    - name: Log in to Docker Hub
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
 
    - name: Build and push Docker image
      uses: docker/build-push-action@v2
      with:
        context: .
        push: true
        tags: username/repository:tag

Explanation

  • name: The name of the workflow.
  • on: Defines the events that trigger the workflow (push on the main branch).
  • jobs: A list of jobs to run as part of the workflow.
  • runs-on: Specifies the type of runner to use (ubuntu-latest).
  • steps: A list of steps to execute in the job, including checking out the code, setting up Docker Buildx, logging in to Docker Hub, and building and pushing the Docker image.

CI/CD Workflow for Java Maven Project

Description

This workflow installs dependencies, runs tests, and packages a Java Maven project.

Workflow File

name: Java CI/CD
 
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
 
jobs:
  build:
    runs-on: ubuntu-latest
 
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
 
    - name: Set up JDK
      uses: actions/setup-java@v2
      with:
        java-version: '11'
 
    - name: Build with Maven
      run: mvn -B package --file pom.xml

Explanation

  • name: The name of the workflow.
  • on: Defines the events that trigger the workflow (push and pull_request on the main branch).
  • jobs: A list of jobs to run as part of the workflow.
  • runs-on: Specifies the type of runner to use (ubuntu-latest).
  • steps: A list of steps to execute in the job, including checking out the code, setting up JDK, and building the project with Maven.

CI/CD Workflow for Deploying to AWS

Description

This workflow builds a Docker image, pushes it to Amazon ECR, and deploys to Amazon ECS.

Workflow File

name: Deploy to AWS
 
on:
  push:
    branches:
      - main
 
jobs:
  deploy:
    runs-on: ubuntu-latest
 
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
 
    - name: Log in to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1
 
    - name: Build and push Docker image
      id: build-image
      uses: docker/build-push-action@v2
      with:
        context: .
        push: true
        tags: ${{ steps.login-ecr.outputs.registry }}/my-repo:latest
 
    - name: Deploy to Amazon ECS
      uses: aws-actions/amazon-ecs-deploy-task-definition@v1
      with:
        task-definition: ecs-task-def.json
        service: my-service
        cluster: my-cluster
        wait-for-service-stability: true

Explanation

  • name: The name of the workflow.
  • on: Defines the events that trigger the workflow (push on the main branch).
  • jobs: A list of jobs to run as part of the workflow.
  • runs-on: Specifies the type of runner to use (ubuntu-latest).
  • steps: A list of steps to execute in the job, including checking out the code, logging in to Amazon ECR, building and pushing the Docker image, and deploying to Amazon ECS.

These sample GitHub Actions workflows cover various use cases, including Node.js, Python, Docker, Java Maven, and AWS deployments. You can customize these workflows to fit your project's specific needs.


💬 Need a Quick Summary?

Hey! Don't have time to read everything? I get it. 😊
Click below and I'll give you the main points and what matters most on this page.
Takes about 5 seconds • Uses Perplexity AI