GitLab Project-Setting Up CI/CD for Node.js To-Do App on a Self-Hosted GitLab Runner
Step 1: Clone the Project to GitLab
- Go to GitLab and click on Import Project.
- Copy the GitHub repository URL for
node-todo-cicd(search forshubham londheon GitHub). - Paste the URL into GitLab and start the import process.
- Once imported, you’ll see the project on your GitLab homepage.
Step 2: Configure GitLab Runner
- Go to Groups > Settings > CI/CD.
- Find Runners and click Project Runner.
- Click New Project Runner.
- Add a tag (e.g.,
dev)—this is similar to labels in Jenkins. - Click Create Runner.
Step 3: Install GitLab Runner on an EC2 Instance
- Copy the installation commands from GitLab (look for How to Install… section).
- SSH into your EC2 instance and run the commands as a superuser (
sudo su). - Choose the appropriate architecture (e.g.,
amd64). - Once installed, start the service:
sudo gitlab-runner status # Verify it's running
Step 4: Register GitLab Runner
- Run the command:
gitlab-runner register
2. Enter the GitLab URL and token from the runner settings.
3. Press Enter to accept the default GitLab URL.
4. Verify the runner with a name (e.g., raees-qazi).
5. Select the executor type (e.g., shell).
6. The runner is now registered successfully.
Step 5: Set Up SSH Keys
- Generate SSH keys:
ssh-keygen
2. Copy the public key:
cat ~/.ssh/id_rsa.pub
3. In GitLab, go to User Settings > SSH Keys.
4. Click New Key, paste the public key, and save it.
Step 6: Install Docker on EC2
Run the following commands to install Docker and configure permissions:
sudo apt-get update
sudo apt-get install docker.io docker-compose-v2 -y
sudo usermod -aG docker ubuntu
sudo usermod -aG docker gitlab-runnerVerify groups:
cat /etc/groupStep 7: Configure Environment Variables for Docker Hub
- In GitLab, go to Settings > CI/CD > Variables.
- Click Expand and add the following variables:
DOCKERHUB_USER: Your Docker Hub username (masked, protected).DOCKERHUB_PASS: Your Docker Hub password/PAT (masked, protected).
Step 8: Create .gitlab-ci.yml Pipeline
Write the CI/CD pipeline in YAML format:
stages:
- build
- test
- push_to_dockerhub
- deploybuild_job:
stage: build
script:
- docker build -t node-app:latest .
tags:
- devtest_job:
stage: test
script:
- echo "testing..."
tags:
- devpush_job:
stage: push_to_dockerhub
script:
- docker login -u $DOCKERHUB_USER -p $DOCKERHUB_PASS
- docker tag node-app:latest $DOCKERHUB_USER/node-app:latest
- docker push $DOCKERHUB_USER/node-app:latest
tags:
- devdeploy_job:
stage: deploy
script:
- docker compose up -d
tags:
- dev

Step 9: Configure AWS Security Group
- Go to AWS Security Groups.
- Allow port 8000 (or change based on project needs).
Step 10: Verify Deployment
- Navigate to the project directory:
cd /home/gitlab-runner/builds/0/<project-name> ls # Your project files should be visible
2. Configure shell settings:
cd /home/gitlab-runner ls -a # List hidden files vim .bash_logout # Open file in Vim editor- Add comments inside the file:
# if # <command will be written> # fi- Save and exit Vim.
3. Return to the main terminal:
cd ~
4. Run the GitLab Runner:
gitlab-runner run

Your Node.js To-Do application is now set up with CI/CD using a self-hosted GitLab Runner on AWS EC2!
Comments
Post a Comment