Rajan Silwal
  • 👋Welcome to My Personal Page
  • Project
    • 👨‍💼Daily Activities
    • ⚠️Monitoring Tools
    • ✍️Git
    • 🏎️Automation Tools
    • 💻Virtualization
    • 🖥️Immutable Infrastructure
    • 🔶Cloud (AWS)
    • ⛲Container
  • ⚠️Monitoring Tools
    • 💡Prometheus
      • How to Setup Prometheus
      • Setup Node-exporter
      • Setup Prometheus to get metrics
    • 💡Grafana
    • 💡Nagios
  • ✍️Git
    • 🐇CI/CD in Git
      • Setup Git for CICD
  • ⛲Container
    • 📍Docker
      • Docker image
      • Same Docker image in VM
  • 🚗k8s
    • Install K8S
  • 🏎️Automation Tools
    • 🖨️Ansible
      • List of my Ansible Playbook
    • Terraform
      • Setup Terraform in AWS
      • Create VPC using .tf
      • Create EC2 using .tf
      • Command Familiars in Terraform
  • 💻Virtualization
    • 🔄OpenNebula
      • Setup OpenNebula
      • Onehost Server
      • Build VM in OpenNebula
  • 🔶Cloud (AWS)
    • 🌥️EC2
    • 🌥️IAM
    • 🌥️VPC
    • 🌥️Load Balancer
    • 🌥️S3 Bucket
    • 🌥️Route 53
  • 🖥️Immutable Infrastructure
    • 1️⃣1⃣ Content
    • 2️⃣2⃣ Virt-Install
    • 3️⃣3⃣ Base Image
    • 4️⃣4⃣ Golden-Image
    • 5️⃣5⃣ After-Golden-Image
Powered by GitBook
On this page
  1. Git
  2. CI/CD in Git

Setup Git for CICD

PreviousCI/CD in GitNextDocker

Last updated 2 years ago

Step 1: Create a account in Gitlab using email address. We can use free as well. Provide a repository name with permission.

Step 2: Clone the repository with SSH which helps to edit the code easily using different IDE.

git clone git@gitlab.com......

Step 3: Open the folder in VS code and starting writng a script in .gitlab-ci.yml. In the following script I am using docker to build a CI/CD pipeline. In order to use a docker we need to have docker in docker hub and create a Dockerfile folder. Include image with version and mention port number in dockerfile.

Stages:
    - test
    - build
    - stg
    - production
    
test artifacts:
    stage: test
    image: python:3.9-slim-buster
    before_script:
        - apt-get update && apt-get install make
    script:
        - mkdir /data
        - cd /data
        - touch rajan.txt
        -  echo "Rajan Silwal" > rajan.txt


build the car:
    stage: build
    image: docker:20.10
    services:
        - docker::20.10-dind
    variables:
        DOCKER_TLS_CERTFIR: "/certs"
    before_script:
        - docker login -u $REGISTRY_USER -p $REGISTRY_PASS
    script:
        - docker build -f Dockerfile -t rajansilwal04/cicd:python-app-1.0 . 
        - docker push rajansilwal04/cicd:python-app-1.0 

testing staging:
    stage: stg
    image: python:3.9-slim-buster
    before_script:
        - apt-get update && apt-get install make
    script:
        - mkdir /data
        - cd /data
        - touch rajan.txt
        -  echo "Rajan Silwal" > rajan.txt

Production:
    stage: production
    image: python:3.9-slim-buster
    before_script:
        - apt-get update && apt-get install make
    script:
        - mkdir /data
        - cd /data
        - touch rajan.txt
        -  echo "Rajan Silwal" > rajan.txt

Step 4: Once you done with your code you can commit and push into a git. It will automatically start running CICD pipeline in gitlab. We can see the pipeline under CICD menu.

If you want to see the log of pipeline, We can see that logs under jobs.

✍️
🐇