This project demonstrates a complete Infrastructure-as-Code (IaC) and CI/CD pipeline for deploying a containerized static website to AWS.
The project uses Terraform to provision the necessary AWS infrastructure, including an EC2 instance, an ECR container registry, and all required IAM roles. A GitHub Actions pipeline automates the process of building a Docker image, pushing it to ECR, and deploying it securely to the EC2 instance using AWS Systems Manager (SSM) instead of SSH.
- Infrastructure as Code: All AWS resources are managed by Terraform.
- Dockerized Application: The static website is served by Nginx in a Docker container.
- CI/CD Automation: GitHub Actions pipelines for both infrastructure and application deployment.
- Secure Deployment: Uses AWS SSM Run Command for deployments, avoiding the need for SSH keys or open SSH ports.
- Tag-Based Releases: The deployment pipeline is triggered by pushing new version tags (e.g.,
v1.0.0). - OIDC Authentication: GitHub Actions securely authenticate with AWS using OpenID Connect.
The diagram below illustrates the CI/CD pipeline for this project.
Before you begin, ensure you have the following:
-
Clone the Repository:
git clone git@github.com:Veras-D/advanced-devops-project.git cd advanced-devops-project -
Create IAM Roles for GitHub Actions: This project requires IAM Roles in your AWS account for GitHub Actions to use. Create them with the following permissions and establish a trust relationship with your GitHub repository.
- Build Role: Needs permissions to push images to Amazon ECR.
- Deploy Role: Needs
ssm:SendCommandandec2:DescribeInstancespermissions. - Terraform Role: Needs broad permissions to manage your AWS resources (EC2, ECR, IAM, VPC, etc.).
-
Update Workflow Files: Replace the placeholder
role-to-assumeARNs in.github/workflows/deploy.yamland.github/workflows/terraform.yamlwith the real ARNs of the roles you created in the previous step. -
Create GitHub Secrets: In your GitHub repository settings under "Secrets and variables" > "Actions", create the following secret:
SSH_IP_ADDRESS: Your local IP address, used by Terraform to allow SSH access for initial setup or debugging.
-
Deploy the Infrastructure: Initialize and apply the Terraform configuration.
cd Terraform terraform init terraform applyThis will provision all the necessary AWS resources.
To deploy a new version of the website:
- Make your changes to the code in the
website/directory. - Commit your changes.
- Create and push a new version tag:
git tag v1.0.1 git push origin v1.0.1
- This will trigger the
Pipeline CI/CDworkflow in GitHub Actions, which will automatically build and deploy your new version.
You can manage your Terraform infrastructure manually via the Terraform CI/CD workflow in the GitHub Actions tab. This allows you to run terraform plan, apply, or destroy from your browser.
This project is licensed under the MIT License. See the LICENSE file for details.
