Gitlab Concepts.. Images & Commands


Gitlab & Runner Setup Commands & Images
Dummy Pipeline without Runner
Dummy Pipeline with Runner
Variables
only & except
Rules
Timeout
When
Needs
Includes
Docker CI Project

Gitlab & Runner Setup Commands & Images

sudo su -
sudo apt  install curl
sudo curl -L --output /usr/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
sudo chmod +x /usr/bin/gitlab-runner
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
sudo gitlab-runner status
gitlab-runner register  --url https://gitlab.com  --token glrt-yE7dapEKq0DzznQ2ZHfpjm86MQpwOjE4enVhbAp0OjMKdTppM2Nwchg.01.1j1j04np8
sudo gitlab-runner restart

sudo journalctl -u gitlab-runner -f

If we are running commands in kishore user without sudo su - Need to use this below 4 lines
sudo cp /home/kishore/.gitlab-runner/config.toml /etc/gitlab-runner/config.toml
sudo chown root:root /etc/gitlab-runner/config.toml
sudo chmod 600 /etc/gitlab-runner/config.toml
sudo gitlab-runner restart

sudo gitlab-runner verify
sudo nano /etc/sudoers					# Add this Line -> gitlab-runner ALL=(ALL) NOPASSWD:ALL
sudo su -
su - gitlab-runner
exit

apt install docker.io
docker --version
systemctl start docker
systemctl enable docker
systemctl status docker
docker ps
cd /etc/gitlab-runner/
ls -lrt
nano config.toml						# Replace Concurrent Session from 1 -> 5
gitlab-runner restart
gitlab-runner status

Deployment Images

Step 1:


Step 2:


Step 3:


Step 4:


Step 5:


Step 6:


Step 7:


Step 8:


Step 9:


Step 10:


Step 11:


Step 12:


Step 13:


Step 14:


Step 15:


Dummy Pipeline without Runner
.gitlab-ci.yml
stages:
    - test
test_job:
    stage: test
    before_script:
        - echo "Setup Done"
    script:
        - echo "Executing tests Cases"
    after_script:
        - echo "All Done"





Dummy Pipeline with Runner
.gitlab-ci.yml
stages:
    - test
test_job:
    stage: test
    tags:
        - eks
    before_script:
        - echo "Setup Done"
    script:
        - echo "Executing tests Cases"
    after_script:
        - echo "All Done"







Variables
.gitlab-ci.yml
stages:
    - build
variables:
    APP_VERSION : "1.0.0"
build_job:
    stage: build
    tags:
        - eks
    script:
        - echo "$APP_VERSION"
        - echo "$CI_PIPELINE_IID"
        - echo "$SECRET"
		






only & except
.gitlab-ci.yml
stages:
  - build
  - test

docker_build_job:
  stage: build
  tags:
    - eks
  only:
    - main
  script:
    - echo "Build Started"

docker_test_job:
  stage: test
  tags:
    - eks
  except:
    - main
  before_script:
    - echo "Image Verification Started"
  script:
    - echo "Test Completed"
	




Rules
stages:
  - build
docker_build_job:
  stage : build
  tags:
    - eks
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
  script:
    - echo “Build Job”
	


Timeout
stages:
  - build
docker_build_job:
  stage : build
  tags:
    - eks
  script:
    - echo “Timeout Example”
    - sleep 80
  timeout: 10s



When
on_success - Default behaviour and when : manual - wait for Approval/Click Play Button in pipeline
stages:
  - build
  - test
  - deploy
build_job:
  stage : build
  tags:
    - eks
  script:
    - echo "Building the project..."
test_job:
  stage : test
  tags:
    - eks
  script :
    - echo "Running tests..."
  when : on_success
deploy_job:
  stage : deploy
  tags:
    - eks
  script :
    - echo "Deploying the project..."
  when : manual




Needs
stages:
  - build
  - test
  - deploy
build_job:
  stage : build
  tags:
    - eks
  needs : []
  script:
    - echo "Building the project..."
test_job:
  stage : test
  tags:
    - eks
  needs : ["build_job"]
  script :
    - echo "Running tests..."
deploy_job:
  stage : deploy
  tags:
    - eks
  needs : []
  script :
    - echo "Deploying the project..."
	


Includes
Includes - Not tried

Docker CI Project
Dockerfile
FROM nginx:latest

# Copy your content files (webpages, static assets)
COPY index.html /usr/share/nginx/html

# Start nginx in the foreground
CMD ["nginx", "-g", "daemon off;"]

index.html
Hello World!

Dockerfile
stages:
  - build

default:
  image: docker:latest
  services:
    - docker:dind
  variables:
    DOCKER_HOST: "tcp://docker:2375"
    DOCKER_TLS_CERTDIR: ""

build_docker_image:
  stage: build
  tags:
    - eks
  before_script:
    - docker version
  script:
    - echo "Building the project..."
    - docker build -t autopilot-docker-image:$CI_PIPELINE_IID .
    - docker image ls















Step :


Step :