Skip to content

szabodorka/mern-docker-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

146 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Logo

Full-stack crypto portfolio tracker built with the MERN stack, containerized with Docker and deployed on AWS via Terraform and GitHub Actions CI/CD.
Explore the documentation »

View Architecture · Setup Guide · Report Issue


Table of Contents


About the Project

This crypto portfolio tracker was originally developed as a team project during a full-stack developer course.
The original frontend and backend codebases were built collaboratively and the build process is included in the commit history.

In this repository, the focus has been on optimizing and extending the existing application by adding:

  • Docker containerization of backend and frontend
  • A minimal Terraform infrastructure for AWS provisioning (EC2, Security Groups, IAM, OIDC)
  • A complete GitHub Actions CI/CD pipeline using OIDC authentication

Tech Stack

Backend

Node.js Express.js MongoDB Mongoose

Frontend

React Vite JavaScript

Infrastructure

AWS Terraform Docker GitHub Actions


Architecture Overview

  • Frontend (React + Nginx) → served on an AWS EC2 instance, load-balanced via AWS NLB
  • Backend (Express API) → runs as a Docker container on the same host, available under /api
  • Database (MongoDB Atlas) → secure managed service, IP-whitelisted for EC2
  • Infrastructure → provisioned with Terraform (EC2, SGs, NLB, IAM, OIDC provider)
  • CI/CD → GitHub Actions builds Docker images → pushes to ECR → deploys via SSM command

(back to top)


Setup Instructions

1. Prerequisites

  • AWS account with permissions to create:
    • ECR repositories
    • IAM roles & OIDC provider
    • EC2, Security Groups and NLB
  • Default VPC in your region or in the default region eu-central-1
  • Backend & Frontend ECR repository in the same region
  • Terraform >= 1.5
  • GitHub repository for this project
  • MongoDB Atlas cluster (with MONGO_URI and whitelisted EC2 Public IP)
  • Coingecko API Key (COINGECKO_KEY)

2. Terraform Infrastructure

  1. Clone the repo and switch to the terraform folder:
git clone https://github.com/<your-username>/<your-repo>.git
cd <your-repo>/terraform

Create terraform.tfvars file to define sensitive variables:

ecr_repo_frontend = "mern-docker-frontend"
ecr_repo_backend = "mern-docker-backend"
mongo_uri = "your-mongodb-uri"
coingecko_key = "your-coingecko-key"
github_owner = "your-github-username"
github_repo = "your-github-repo-name"

Initialize and apply:

terraform init
terraform apply

This will create:

  • EC2 instance (Ubuntu 24.04, with Docker, AWS CLI, SSM Agent installed) > Add EC2 public IP to the whitelist of your MongoDB cluster
  • IAM role for GitHub OIDC
  • Security Groups & Network Load Balancer

Note: ECR repositories must exist beforehand


3. GitHub Secrets

Add the following repository secret from Terraform outputs under Git repository Settings > Secrets and variables > Actions:

AWS_ROLE_ARN - The ARN of the OIDC role created by Terraform (e.g., arn:aws:iam::<account_id>:role/gh-actions-mern-docker)


4. CI/CD Workflow

On push to main, GitHub Actions will:

  • Assume the OIDC role in AWS
  • Build backend & frontend Docker images
  • Push them to ECR
  • Trigger SSM command on EC2 > docker compose pull && docker compose up -d

(back to top)


Usage

Access the application via the NLB DNS name printed in Terraform outputs. API base path is /api.

Limitations & Notes

  • Requires existing ECR repositories
  • MongoDB Atlas must have EC2 IP whitelisted
  • Single EC2 host – no auto-scaling yet

About

Full-stack MERN crypto portfolio tracker, containerized with Docker and deployed to AWS using Terraform and GitHub Actions CI/CD.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors