Day 11 Task: Advance Git & GitHub for DevOps Engineers: Part-2

Day 11 Task: Advance Git & GitHub for DevOps Engineers: Part-2

Git LFS

Git Large File Storage (LFS) is an extension for Git that allows you to track and manage large files efficiently. It does this by storing the actual file contents outside of the Git repository, and instead storing small pointers to those files within the repository.

Commands

Install git lfs

git lfs install

Track a specific file type with Git LFS

git lfs track "*.mp4"

Commit and push changes:

git add .
git commit -m "Add large files"
git push origin master

This code is finally push to your remote repo. also

Git Lab

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows developers to automate their software development workflows. It enables developers to automate tasks such as building, testing, and deploying code, as well as other tasks such as running static code analysis and linting.

Key benefits of using GitHub Actions in DevOps:

  • Automate repetitive tasks. Frees up developers to focus on more strategic work.

  • Improve code quality. Automates testing and linting to ensure code quality.

  • Faster feedback loops. Identify and fix problems earlier in the development cycle.

  • More reliable deployments. Reduce the risk of errors and downtime.

Example of how GitHub Actions can be used in DevOps:

A common CI/CD workflow using GitHub Actions might look like this:

  1. A developer pushes code to a GitHub repository.

  2. GitHub Actions triggers a workflow that runs a series of jobs.

  3. The first job might build the code.

  4. The second job might run unit tests.

  5. The third job might run static code analysis.

  6. If all jobs pass, the final job might deploy the code to production.

Here is an example of a GitHub Actions workflow file for a simple CI/CD pipeline:

name: CI/CD Pipeline

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install dependencies
        run: npm install
      - name: Build
        run: npm run build

  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install dependencies
        run: npm install
      - name: Test
        run: npm run test

  deploy:
    needs: [ build, test ]
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Deploy to production
        run: echo "Deploying to production..."

This workflow file defines three jobs: build, test, and deploy. The build job builds the code, the test job runs the tests, and the deploy job deploys the code to production. The needs keyword is used to specify that the deploy job can only run if both the build and test jobs have passed.

This is basically the theoretical concept of Git action, but when we give to CICD part of Git Hub, definitely perform practical too.