Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mbund committed Feb 13, 2025
1 parent 5b5e271 commit 4dd0165
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 67 deletions.
68 changes: 2 additions & 66 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,7 @@ vars:
cluster: "infra2-cluster"

tasks:
bastion:
desc: SSH into the bastion host
dir: terraform/out
cmds:
- ssh -i bastion_key.pem admin@$(cat bastion_public_ip)

traefik:
desc: SSH into the traefik host
dir: terraform/out
cmds:
- ssh -i traefik_key.pem ec2-user@$(cat traefik_public_ip)

challenges:
desc: List all running ECS tasks by name
ecs-services:
desc: List all running ECS services by name
cmds:
- aws ecs list-services --cluster {{.cluster }} | jq .serviceArns[] -r | awk -F '/' '{print $NF}'

connect-to:
desc: get shell in the container running challenge
dir: terraform/out
cmds:
- |
# Check if task_name is set
if [ -z "{{.CLI_ARGS}}" ]; then
echo "Error: task_name is not set. Please provide a valid task name." >&2
exit 1
fi
echo "Fetching task Arn..."
task_arn=$(aws ecs list-tasks --cluster {{.cluster }} --service-name {{.CLI_ARGS}} | jq -r '.taskArns[]')
echo "Describing tasks for $task_arn..."
container_instance_arn=$(aws ecs describe-tasks --cluster {{.cluster }} --tasks "$task_arn" | jq '.tasks[].containerInstanceArn' -r)
echo "Describing Container Instances for ARN: $container_instance_arn"
ec2_instance_id=$(aws ecs describe-container-instances --cluster {{.cluster }} --container-instances "$container_instance_arn" | jq '.containerInstances[].ec2InstanceId' -r)
echo "EC2 Instance ID: $ec2_instance_id"
private_ip=$(aws ec2 describe-instances --instance-ids $ec2_instance_id | jq '.Reservations[].Instances[].PrivateIpAddress' -r)
echo "Private IP Address: $private_ip"
ssh -o ProxyCommand="ssh -i bastion_key.pem -W %h:%p admin@$(cat bastion_public_ip)" -i challenges_key.pem ec2-user@$private_ip -t 'docker exec -it $(docker ps --filter "name={{.CLI_ARGS}}" | awk "NR==2 {print \$1}") /bin/sh'
connect-to-ec2:
desc: ssh into the ec2 instance running the challenge
dir: terraform/out
cmds:
- |
# Check if task_name is set
if [ -z "{{.CLI_ARGS}}" ]; then
echo "Error: task_name is not set. Please provide a valid task name." >&2
exit 1
fi
echo "Fetching task Arn..."
task_arn=$(aws ecs list-tasks --cluster {{.cluster }} --service-name {{.CLI_ARGS}} | jq -r '.taskArns[]')
echo "Describing tasks for $task_arn..."
container_instance_arn=$(aws ecs describe-tasks --cluster {{.cluster }} --tasks "$task_arn" | jq '.tasks[].containerInstanceArn' -r)
echo "Describing Container Instances for ARN: $container_instance_arn"
ec2_instance_id=$(aws ecs describe-container-instances --cluster {{.cluster }} --container-instances "$container_instance_arn" | jq '.containerInstances[].ec2InstanceId' -r)
echo "EC2 Instance ID: $ec2_instance_id"
private_ip=$(aws ec2 describe-instances --instance-ids $ec2_instance_id | jq '.Reservations[].Instances[].PrivateIpAddress' -r)
echo "Private IP Address: $private_ip"
ssh -o ProxyCommand="ssh -i bastion_key.pem -W %h:%p admin@$(cat bastion_public_ip)" -i challenges_key.pem ec2-user@$private_ip
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
terraform
terraform-ls
go-task
infracost
];
};
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4dd0165

Please sign in to comment.