Day 85: GitLab CI/CD Project

Today I built a full GitLab CI/CD pipeline for a simple Node.js app using Docker and deploying it to AWS. This was one of the most practical exercises yet, as it tied together GitLab runners, Docker, Docker Hub, and AWS deployment.


๐Ÿ”น Pipeline Overview

My pipeline had 4 stages:

1๏ธโƒฃ Build โ†’ Build the Docker image for the Node.js app
2๏ธโƒฃ Test โ†’ Run basic checks/tests
3๏ธโƒฃ Push to Docker Hub โ†’ Push the built image to Docker Hub
4๏ธโƒฃ Deploy to AWS โ†’ Deploy using Docker Compose on an AWS EC2


๐Ÿ”น .gitlab-ci.yml Pipeline Code

stages:
  - build
  - test
  - push_to_docker
  - deploy_to_aws

variables:
  DOCKERIMAGE_NAME: node-app

build_stage:
  script:
    - docker build -t $DOCKERIMAGE_NAME:$CI_COMMIT_REF_SLUG ./gitlab-ci/01__node-todo-cicd
  tags:
    - deploy

test_job:
  stage: test
  script:
    - echo "testing the image ..."

push_job:
  stage: push_to_docker
  script:
    - docker login -u $DOCKERHUB_USER -p $DOCKERHUB_PASS
    - docker image tag $DOCKERIMAGE_NAME:$CI_COMMIT_REF_SLUG $DOCKERHUB_USER/$DOCKERIMAGE_NAME:$CI_COMMIT_REF_SLUG
    - docker push $DOCKERHUB_USER/$DOCKERIMAGE_NAME:$CI_COMMIT_REF_SLUG
  tags:
    - deploy

deploy_job:
  stage: deploy_to_aws
  script:
    - echo "deploying to AWS..."
    - docker compose -f ./gitlab-ci/01__node-todo-cicd/docker-compose.yaml up -d
  tags:
    - deploy

๐Ÿ”น Key Learnings

โœ… How to use GitLab variables like $CI_COMMIT_REF_SLUG for versioning
โœ… How to authenticate & push images to Docker Hub securely
โœ… Using GitLab self-hosted runner with Docker to run builds/deployments
โœ… Simple AWS deployment with Docker Compose


๐Ÿ”น Why This Matters

This exercise showed me how powerful GitLab CI/CD can be when integrated with Docker and AWS. Instead of manually building/pushing/deploying, the entire process becomes automated, repeatable, and reliable.

I now have a mini production pipeline:
Code โ†’ Build โ†’ Test โ†’ Push โ†’ Deploy ๐Ÿš€

0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir