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 ๐
Subscribe to my newsletter
Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
