Setup Git for CICD

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.

Last updated