DEV Community

Patrick Odhiambo
Patrick Odhiambo

Posted on

How I Built a CI/CD Pipeline with GitHub Actions, Docker, Terraform & AWS EC2

Introduction

Deploying applications the modern DevOps way can seem daunting, but with the right tools and a step-by-step approach, it becomes an exciting journey. In this blog post, I’ll share how I built and automated the deployment of a simple Node.js application using GitHub Actions, Docker, Terraform, and AWS EC2.

This project was inspired by the incredible Kubekode video tutorial, but I extended it further by adding features like automated cleanup and deeper debugging strategies for a robust CI/CD flow.


📋 Overview

Here’s a high-level summary of what we’ll walk through:

  1. Building a Node.js app
  2. Dockerizing the application
  3. Setting up GitHub Actions
  4. Managing secrets securely
  5. Provisioning AWS EC2 with Terraform
  6. Deploying the Docker container
  7. Handling real-world CI/CD pipeline errors
  8. Adding a cleanup step to reduce AWS costs

Let’s dive in.


🧱 Step 1: Build a Simple Node.js App

We start with a basic Node.js web server. For this demo, the app listens on a port and responds with a message:


js
const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => res.send('Hello from CI/CD pipeline!'));

app.listen(port, () => {
  console.log(`Node app running at http://localhost:${port}`);
});



Enter fullscreen mode Exit fullscreen mode

Top comments (0)