generated from leptos-rs/start-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Crease
committed
Feb 26, 2024
1 parent
634658a
commit dbb6d68
Showing
12 changed files
with
1,281 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
#!/usr/bin/env bash | ||
sudo yum update -y | ||
sudo yum install -y docker python3 | ||
sudo service docker start | ||
sudo yum install -y docker python3 pip | ||
sudo yum remove -y python-requests aws-cli | ||
sudo service docker start | ||
sudo usermod -aG docker ec2-user | ||
pip uninstall awscli | ||
pip install docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
|
||
all: | ||
children: | ||
managers: | ||
hosts: | ||
--- | ||
managers: | ||
hosts: | ||
%{~ for ec2_name, address in managers ~} | ||
${ec2_name}: | ||
ansible_host: ${address} | ||
%{ endfor } | ||
vars: | ||
ansible_user: ec2-user | ||
ansible_ssh_private_key_file: ../modules/cluster/node_key | ||
workers: | ||
hosts: | ||
%{~ for ec2_name, address in workers~} | ||
${ec2_name}: | ||
ansible_host: ${address} | ||
${ec2_name}: | ||
ansible_host: ${address} | ||
%{~ endfor ~} | ||
vars: | ||
ansible_user: ec2-user | ||
ansible_ssh_private_key_file: ../modules/cluster/node_key | ||
|
||
vars: | ||
ansible_user: ec2-user | ||
ansible_ssh_private_key_file: ../modules/cluster/node_key | ||
workers: | ||
hosts: | ||
%{~ for ec2_name, address in workers ~} | ||
${ec2_name}: | ||
ansible_host: ${address} | ||
%{~ endfor ~} | ||
vars: | ||
ansible_user: ec2-user | ||
ansible_ssh_private_key_file: ../modules/cluster/node_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
resource "aws_lb" "main" { | ||
name = "cluster-lb" | ||
internal = false | ||
load_balancer_type = "application" | ||
security_groups = [aws_security_group.lb.id] | ||
subnets = toset(var.subnet_ids.public[*]) | ||
} | ||
|
||
resource "aws_lb_listener" "http" { | ||
count = var.environment == "dev" ? 1 : 0 | ||
load_balancer_arn = aws_lb.main.arn | ||
port = 80 | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = aws_lb_target_group.public.arn | ||
} | ||
} | ||
|
||
resource "aws_lb_listener" "http_redirect" { | ||
count = var.environment == "dev" ? 0 : 1 | ||
load_balancer_arn = aws_lb.main.arn | ||
port = 80 | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
type = "redirect" | ||
redirect { | ||
port = "443" | ||
protocol = "HTTPS" | ||
status_code = "HTTP_301" | ||
} | ||
} | ||
} | ||
|
||
resource "aws_lb_target_group" "public" { | ||
name = "${var.service}-${var.environment}-public" | ||
port = 80 | ||
protocol = "HTTP" | ||
vpc_id = var.vpc_id | ||
target_type = "ip" | ||
|
||
health_check { | ||
protocol = "HTTP" | ||
path = "/" | ||
matcher = "200-299" | ||
} | ||
} | ||
|
||
resource "aws_lb_target_group_attachment" "all" { | ||
for_each = toset(local.targets) | ||
target_group_arn = aws_lb_target_group.public.arn | ||
target_id = each.key | ||
port = 80 | ||
} | ||
|
||
locals { | ||
targets = flatten([aws_instance.bootstrap[*].id, aws_instance.workers[*].id, aws_instance.managers[*].id]) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
resource "aws_db_instance" "default" { | ||
allocated_storage = 5 | ||
db_name = "forum" | ||
engine = "postgresql" | ||
instance_class = "db.t3.micro" | ||
username = "backend" | ||
manage_master_user_password = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: Configure Host | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: install dependencies | ||
yum: | ||
name: "{{ item }}" | ||
update_cache: yes | ||
loop: | ||
- vim | ||
- python3 | ||
- pip | ||
- name: install ansible-docker deps | ||
shell: /usr/bin/pip install docker | ||
- name: start docker service | ||
service: | ||
enabled: true | ||
name: docker | ||
state: started |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
--- | ||
- name: Docker Service | ||
hosts: managers[0] | ||
community.docker.docker_swarm_service: | ||
name: nginx | ||
image: nginx | ||
replicas: 1 | ||
resolve_image: true # update based on digest (i.e even if latest) | ||
publish: | ||
mode: host | ||
published_port: 80 | ||
target_port: 80 | ||
healthcheck: | ||
# Check if nginx server is healthy by curl'ing the server. | ||
# If this fails or timeouts, the healthcheck fails. | ||
test: ["CMD", "curl", "--fail", "http://nginx.host.com"] | ||
interval: 1m30s | ||
timeout: 10s | ||
retries: 3 | ||
start_period: 30s | ||
update_config: | ||
parallelism: 2 | ||
delay: 10s | ||
order: stop-first | ||
failure_action: rollback | ||
rollback_config: | ||
parallelism: 2 | ||
delay: 10s | ||
order: stop-first | ||
reservations: | ||
cpus: 0.25 | ||
memory: 20M | ||
limits: | ||
cpus: 0.50 | ||
memory: 50M | ||
tasks: | ||
- name: Docker Swarm Service | ||
community.docker.docker_swarm_service: | ||
name: nginx | ||
image: nginx | ||
replicas: 1 | ||
resolve_image: true # update based on digest (i.e even if latest) | ||
publish: | ||
- mode: host | ||
published_port: 80 | ||
target_port: 80 | ||
healthcheck: | ||
# Check if nginx server is healthy by curl'ing the server. | ||
# If this fails or timeouts, the healthcheck fails. | ||
test: ["CMD", "curl", "--fail", "http://nginx.host.com"] | ||
interval: 1m30s | ||
timeout: 10s | ||
retries: 3 | ||
start_period: 30s | ||
update_config: | ||
parallelism: 2 | ||
delay: 10s | ||
order: stop-first | ||
failure_action: rollback | ||
rollback_config: | ||
parallelism: 2 | ||
delay: 10s | ||
order: stop-first | ||
reservations: | ||
cpus: 0.25 | ||
memory: 20M | ||
limits: | ||
cpus: 0.50 | ||
memory: 50M |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"version": 4, | ||
"terraform_version": "1.7.3", | ||
"serial": 178, | ||
"lineage": "0ed00022-0f3f-d407-af82-f16daaae8de3", | ||
"outputs": {}, | ||
"resources": [], | ||
"check_results": null | ||
} |
Oops, something went wrong.