{"id":26796001,"url":"https://github.com/dhanikaa/cicd-pipeline","last_synced_at":"2026-05-03T01:43:13.112Z","repository":{"id":282822033,"uuid":"902538934","full_name":"dhanikaa/cicd-pipeline","owner":"dhanikaa","description":"This project automates the deployment of a Node.js app using Terraform for infrastructure provisioning, Docker for containerization, and AWS for hosting.","archived":false,"fork":false,"pushed_at":"2025-03-17T05:15:28.000Z","size":747,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-28T00:37:02.676Z","etag":null,"topics":["aws","aws-cli","aws-ec2","aws-ecr","aws-s3","cicd","docker","dockerhub","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhanikaa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-12T19:06:01.000Z","updated_at":"2025-03-17T05:15:31.000Z","dependencies_parsed_at":"2025-03-17T06:36:33.698Z","dependency_job_id":null,"html_url":"https://github.com/dhanikaa/cicd-pipeline","commit_stats":null,"previous_names":["dhanikaa/cicd-pipeline"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dhanikaa/cicd-pipeline","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2Fcicd-pipeline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2Fcicd-pipeline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2Fcicd-pipeline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2Fcicd-pipeline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhanikaa","download_url":"https://codeload.github.com/dhanikaa/cicd-pipeline/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhanikaa%2Fcicd-pipeline/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32555839,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T00:31:16.350Z","status":"ssl_error","status_checked_at":"2026-05-03T00:31:15.546Z","response_time":132,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-cli","aws-ec2","aws-ecr","aws-s3","cicd","docker","dockerhub","terraform"],"created_at":"2025-03-29T18:16:51.255Z","updated_at":"2026-05-03T01:43:13.092Z","avatar_url":"https://github.com/dhanikaa.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# CI/CD with Terraform, Docker, and AWS\n\nThis project demonstrates a Continuous Integration/Continuous Deployment (CI/CD) pipeline using **Terraform**, **Docker**, and **AWS**. The pipeline automates the deployment of a Node.js application to an EC2 instance, leveraging AWS Elastic Container Registry (ECR) for Docker image storage. The application is built using Express.js, Dockerized, and deployed via GitHub Actions.\n\n## Project Overview\n\nThis project includes the following components:\n\n1. **Node.js Application (`app.js`)**: A simple Express.js application that serves a \"Service is up and running\" message.\n2. **Dockerfile**: A Dockerfile to containerize the Node.js application.\n3. **Terraform Configuration (`main.tf`)**: Terraform configuration to provision an EC2 instance on AWS and set up the necessary IAM roles, security groups, and key pairs.\n4. **GitHub Actions Workflow (`deploy.yml`)**: A CI/CD pipeline using GitHub Actions to automate the deployment process.\n\n## Prerequisites\n\n- **AWS Account**: Ensure you have an AWS account with the necessary permissions to create EC2 instances, ECR repositories, and other resources.\n- **GitHub Account**: A GitHub repository to store the project files and configure GitHub Actions.\n- **Terraform**: Terraform must be installed locally for initial setup and execution.\n- **Docker**: Docker must be installed on the local machine for building the Docker image.\n- **AWS CLI**: AWS CLI must be installed and configured for interacting with AWS services.\n\n## Project Structure\n\n```plaintext\n.\n├── nodeapp/\n│   ├── app.js          # Node.js application\n│   └── Dockerfile      # Dockerfile to containerize the app\n├── terraform/\n│   ├── main.tf         # Terraform configuration for provisioning AWS resources\n    └── variables.tf    # Terraform configuration for the variables\n├── .github/\n│   └── workflows/\n│       └── deploy.yml  # GitHub Actions workflow for CI/CD\n├── README.md           # Project documentation\n└── package.json        # Node.js dependencies\n```\n\n## Setup\n\n### 1. **Terraform Configuration**\n\nThe `main.tf` file contains the Terraform configuration to provision AWS resources:\n\n- **EC2 Instance**: A `t3.micro` instance is created to run the Docker container.\n- **IAM Role and Instance Profile**: An IAM role (`ec2-ecr-auth`) is created to allow the EC2 instance to authenticate with AWS ECR.\n- **Security Group**: A security group is created with the following rules:\n  - Port 22 (SSH) open for remote access.\n  - Port 80 (HTTP) and 443 (HTTPS) open for application traffic.\n- **Key Pair**: An AWS EC2 key pair is created to enable SSH access to the EC2 instance.\n\n### 2. **Dockerfile**\n\nThe `Dockerfile` builds a Docker image for the Node.js application:\n\n```dockerfile\nFROM node:14\nWORKDIR /usr/app\nCOPY package.json .\nRUN npm install\nCOPY . .\nEXPOSE 8080\nCMD [ \"node\", \"app.js\" ]\n```\n\n- **Node.js**: The application is based on Node.js version 14.\n- **Working Directory**: The working directory is set to `/usr/app` inside the container.\n- **Dependencies**: The `package.json` file is copied, and `npm install` is run to install dependencies.\n- **Expose Port**: Port 8080 is exposed for the application to listen on.\n- **Run Command**: The application is started using `node app.js`.\n\n### 3. **Node.js Application (`app.js`)**\n\nThe `app.js` file contains a simple Express.js server:\n\n```javascript\nconst express = require(\"express\");\nconst app = express();\n\napp.get(\"/\", (req, res) =\u003e {\n    res.send(\"Service is up and running\");\n});\n\napp.listen(8080, () =\u003e {\n    console.log(\"Server is up\");\n});\n```\n\n- **Express.js**: A basic Express.js application that listens on port 8080 and serves a \"Service is up and running\" message.\n\n### 4. **GitHub Actions Workflow (`deploy.yml`)**\n\nThe `deploy.yml` file defines a GitHub Actions workflow for the CI/CD pipeline:\n\n#### Workflow Breakdown:\n\n- **`deploy-infrastructure` Job**:\n  - **Terraform Init**: Initializes Terraform with an S3 backend for storing the state file.\n  - **Terraform Plan**: Creates an execution plan for provisioning AWS resources.\n  - **Terraform Apply**: Applies the Terraform plan to provision the infrastructure.\n  - **Outputs EC2 Public IP**: Retrieves and outputs the public IP of the EC2 instance.\n\n- **`deploy-app` Job**:\n  - **Ensure ECR Repository Exists**: Checks if the ECR repository exists, and creates it if necessary.\n  - **Docker Image Build and Push**: Builds the Docker image and pushes it to AWS ECR.\n  - **Deploy to EC2**: Connects to the EC2 instance via SSH, installs Docker, AWS CLI, and other dependencies, then pulls and runs the Docker container.\n\n```yaml\nname: CI/CD with terraform\n\non: [push, workflow_dispatch]\n\njobs:\n  deploy-infrastructure:\n    runs-on: ubuntu-latest\n    steps:\n      # Terraform steps to provision EC2 instance and related resources\n\n  deploy-app:\n    runs-on: ubuntu-latest\n    needs: deploy-infrastructure\n    steps:\n      # Docker build, push, and EC2 deployment steps\n```\n\n## How to Use\n\n### 1. **Set Up AWS Credentials**\n\nStore your AWS credentials as GitHub Secrets:\n\n- `AWS_ACCESS_KEY_ID`\n- `AWS_SECRET_ACCESS_KEY`\n- `AWS_SSH_KEY_PRIVATE` (Private SSH key for EC2 access)\n- `AWS_SSH_KEY_PUBLIC` (Public SSH key for EC2 access)\n- `AWS_TF_STATE_BUCKET_NAME` (S3 bucket for Terraform state)\n\n### 2. **Configure Terraform Variables**\n\nEnsure the following variables are configured in the `terraform/main.tf` file or passed as input variables:\n\n- `AWS_REGION`: The AWS region to deploy resources in.\n- `AWS_SSH_KEY_PUBLIC`: Your public SSH key.\n- `AWS_SSH_KEY_PRIVATE`: Your private SSH key.\n- `AWS_TF_STATE_BUCKET_NAME`: The S3 bucket name for storing Terraform state.\n\n### 3. **Push to GitHub**\n\nPush the code to your GitHub repository. The workflow will trigger on every push to the repository and execute the CI/CD pipeline.\n\n### 4. **Monitor Deployment**\n\n- The GitHub Actions workflow will provision the infrastructure, build the Docker image, and deploy the application to the EC2 instance.\n- You can monitor the progress in the **Actions** tab of your GitHub repository.\n\n### 5. **Access the Application**\n\nOnce the deployment is complete, access the application by visiting the public IP of the EC2 instance in your browser.\n\n```plaintext\nhttp://\u003cEC2_PUBLIC_IP\u003e\n```\n\nYou should see the message: \"Service is up and running\".\n\n## Conclusion\n\nThis project demonstrates a fully automated CI/CD pipeline that provisions infrastructure with Terraform, builds and pushes Docker images to AWS ECR, and deploys the application to an EC2 instance. It integrates multiple AWS services and GitHub Actions to streamline the deployment process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhanikaa%2Fcicd-pipeline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhanikaa%2Fcicd-pipeline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhanikaa%2Fcicd-pipeline/lists"}