Skip to content

Commit 903884b

Browse files
committed
Add readme for EC2
1 parent 759785e commit 903884b

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,73 @@ TODO: add link to kubernetes
2828

2929
### EC2
3030

31+
#### Overview
32+
33+
This project uses GitHub Actions, Terraform, and Ansible to provision an EC2 instance, configure it, and deploy the app stack (via Docker Compose) on AWS.
34+
All infra-as-code and automation is in infra/.
35+
36+
#### Triggering Deployment
37+
38+
Deployment is triggered manually via the GitHub Actions workflow:
39+
.github/workflows/aws-ec2-deploy.yml
40+
41+
You provide:
42+
43+
* SSH private key (base64)
44+
* AWS credentials (access key, secret, session token)
45+
* GHCR (GitHub Container Registry) token
46+
47+
#### Workflow Steps
48+
49+
a. **Checkout & Secrets**
50+
Repo is checked out.
51+
Secrets are masked for safety.
52+
SSH key is decoded and saved as infra/priv.pem.
53+
54+
b. **Tooling Setup**
55+
Installs Terraform (v1.12.1) and Ansible (v11.6.0).
56+
57+
c. **Deploying EC2 (Terraform)**
58+
Runs make deploy in infra/:
59+
Applies main.tf to create a new EC2 instance (Debian, public IP, SSH open, HTTP/HTTPS open).
60+
Security group allows ports 22, 80, 443 from anywhere.
61+
Waits for the instance to be reachable via SSH.
62+
63+
d. **Inventory Update**
64+
Extracts the new EC2 public IP and injects it into the Ansible inventory (inventory.ini).
65+
66+
e. **SSH Test**
67+
Verifies SSH connectivity to the new instance using the provided key.
68+
69+
f. **Provisioning (Ansible)**
70+
Runs make ansible in infra/:
71+
Executes playbook.yml against the new EC2 instance.
72+
Installs Docker, Docker Compose, Python, pip, etc.
73+
Logs into GHCR to pull images.
74+
Copies all needed config files, secrets, and scripts.
75+
Writes the EC2 public IP to .env.production (for Traefik/public routing).
76+
Copies and sets up backend config, monitoring, and mock data scripts.
77+
Runs Docker Compose (compose.aws.yml) to start all services (Traefik, app services, Postgres, monitoring, etc).
78+
Waits for Traefik to be up, then loads mock users and profiles via scripts.
79+
80+
#### Result
81+
82+
The EC2 instance is fully provisioned, running all services via Docker Compose, with Traefik as the reverse proxy.
83+
All services are accessible via the EC2 public IP (HTTP/HTTPS, depending on your compose config).
84+
Monitoring (Prometheus, Grafana) and mock data are loaded and ready.
85+
You can access the website by using the public ip of your deployed ec2,
86+
Access monitoring by {ec2.public\_ip/prometheus} {ec2.public\_ip/grafana}
87+
88+
#### Files of Interest
89+
90+
infra/main.tf — Terraform infra definition (EC2, security group)
91+
infra/playbook.yml — Ansible provisioning and deployment
92+
infra/compose.aws.yml — Docker Compose stack (all services)
93+
.github/workflows/aws-ec2-deploy.yml — GitHub Actions workflow for automation
94+
95+
96+
Push the button in GitHub Actions, provide secrets, and the workflow will spin up a new EC2, configure it, and deploy the full stack automatically.
97+
3198
## Endpoint Documentation
3299

33100
The endpoints are documented using OpenAPI or Swagger schemas:

0 commit comments

Comments
 (0)