DEV Community

Yash Sonawane
Yash Sonawane

Posted on

1 1 1 1 1

๐Ÿš€ 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! ๐ŸŽฏ

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where youโ€™ll build it, break it, debug it, and fix it. Youโ€™ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good olโ€™ AI to find and fix issues fast.

RSVP here โ†’

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay