DEV Community

Yash Sonawane
Yash Sonawane

Posted on

πŸš€ Deploying a Web App with GitLab CI/CD: A Step-by-Step Journey

Introduction

In my DevOps learning journey, I recently built a CI/CD pipeline using GitLab to automate the process of building, testing, pushing, and deploying a Dockerized application. This was my first hands-on experience creating a structured multi-stage pipeline, and I’m excited to share my approach!

Understanding the Pipeline

The image below shows my GitLab CI/CD pipeline in action:

GitLab CI/CD Pipeline

The pipeline consists of four main stages:

Image description

βœ… Build - Creating the Docker image.

βœ… Test - Running multiple tests in parallel.

βœ… Push - Pushing the image to Docker Hub.

βœ… Deploy - Deploying the application to an EC2 instance.

GitLab CI/CD Configuration

Here’s the .gitlab-ci.yml file I used:

stages:
    - build
    - test
    - push
    - deploy

build_job:
    stage: build
    script:
        - echo "this build is done using command <docker build -t tag .>"

test_job:
    stage: test
    script:
        - echo "this is testing of out docker build"

push_job:
    stage: push
    script:
        - echo  "this"
        - echo "is pushing to docker hub"

deploy_job:
    stage: deploy
    script:
        - echo  "this"
        - echo "is deploying to EC2 instance"

dev_test_job:
    stage: test
    script:
        - echo "tested for dev"

prd_test_job:
    stage: test
    script:
        - echo "tested for prd"
Enter fullscreen mode Exit fullscreen mode

Key Features of This Pipeline

πŸ”Ή Parallel Testing - Multiple test jobs (dev_test_job, prd_test_job, test_job) run at the same time to speed up validation.

πŸ”Ή Automated Deployment - The final stage deploys the application to an EC2 instance.

πŸ”Ή Scalability - This structure can be extended for real-world projects by adding linting, security scans, and rollback mechanisms.

Lessons Learned & Next Steps

  • Setting up a proper .gitlab-ci.yml file was crucial.
  • Parallel testing significantly improves efficiency.
  • Automating deployments reduces manual errors and saves time.

Next Steps:

πŸ”Ή Integrate container scanning for security.

πŸ”Ή Automate infrastructure provisioning with Terraform.

πŸ”Ή Deploy using Kubernetes for better scalability.

Final Thoughts

This was a great learning experience in GitLab CI/CD, and I’m excited to enhance this pipeline further. If you’re new to GitLab CI/CD, I highly recommend starting simple and gradually adding complexity. πŸš€

Let me know if you have any feedback or if you're working on something similar! 🎯

Top comments (0)