Skip to content

4 aws ecs #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5eead99
Add checkout step
codeguru42 Dec 24, 2022
9ff8b89
Add ecs:DescribeClusters permissions to GithubRole
codeguru42 Dec 24, 2022
364068e
Fix syntax in policy documents
codeguru42 Dec 24, 2022
245467c
Add ecs:CreateCluster permissions to GithubRole
codeguru42 Dec 24, 2022
edaba47
Add ECS Service
codeguru42 Dec 24, 2022
c28c236
Roles for ECS task
codeguru42 Dec 24, 2022
056cfb3
ECS Task Definition
codeguru42 Dec 24, 2022
3754aea
Add CAPABILITY_NAMED_IAM for deploy
codeguru42 Dec 24, 2022
e9b888b
Add AssumeRolePolicyDocument for ExecutionRole
codeguru42 Dec 24, 2022
2b8047d
Add AssumeRolePolicyDocument for TaskRole
codeguru42 Dec 24, 2022
77c28b2
Add iam:CreateRole to GithubRole
codeguru42 Dec 24, 2022
91e66a1
Fix spelling
codeguru42 Dec 24, 2022
678c812
Add container definition
codeguru42 Dec 24, 2022
ac3d268
Define runtime platform for tasks
codeguru42 Dec 24, 2022
0b2bdfe
Add iam:DeleteRole to GithubRole
codeguru42 Dec 24, 2022
671ce37
Add ecs:RegisterTaskDefinition to GithubRole
codeguru42 Dec 24, 2022
ce81e8a
Sort actions
codeguru42 Dec 24, 2022
a29113e
Add iam:PassRole to GithubRole
codeguru42 Dec 24, 2022
7a6cf1e
Correctly set up image tag
codeguru42 Dec 24, 2022
c2c4e0b
Add ecs:DescribeServices to GithubRole
codeguru42 Dec 24, 2022
20222cc
Add ecs:DeregisterTaskDefinition to GithubRole
codeguru42 Dec 24, 2022
1972ca6
Add ecs:CreateService to GithubRole
codeguru42 Dec 24, 2022
a45719c
Add network configuration for ECS Service
codeguru42 Dec 25, 2022
a56a196
Add ec2:CreateVpc to GithubRole
codeguru42 Dec 25, 2022
e52c877
Add GroupDescription for Security Group
codeguru42 Dec 25, 2022
e9fcc3b
Add CidrBlock to subnet
codeguru42 Dec 25, 2022
7b710be
Add policy to ExecutionRole
codeguru42 Dec 25, 2022
29d7009
Add more ec2 permissions to GithubRole
codeguru42 Dec 29, 2022
1a96a98
Add more iam permissions to GithubRole
codeguru42 Dec 29, 2022
ab9c732
Add some more permissions
codeguru42 Dec 29, 2022
6c10a10
Add ec2:DescribeSecurityGroups to GithubRole
codeguru42 Dec 29, 2022
05b8092
Add ec2:DeleteSecurityGroup and ec2:DeleteSubnet permissions to Githu…
codeguru42 Dec 29, 2022
c88f99d
Add ec2:DescribeSubnets to GitHubRole
codeguru42 Dec 29, 2022
b78e0df
Add ecs:DeleteService to GitHubRole
codeguru42 Dec 30, 2022
b2b5614
Revert "Only allow deploy if build is successful"
codeguru42 Jan 1, 2023
103e7ad
Remove paths from roles
codeguru42 Jan 2, 2023
5a4c21f
Make PublicSubnet public
codeguru42 Jan 3, 2023
028f387
Add ec2:ModifySubnetAttribute permission to GithubRole
codeguru42 Jan 3, 2023
ae2cbdf
Add ecs:UpdateService permission to GithubRole
codeguru42 Jan 3, 2023
2392e1c
Add an internet gateway
codeguru42 Jan 3, 2023
5a9edbe
Add ec2:CreateInternetGateway permission to GithubRole
codeguru42 Jan 3, 2023
fd86d5e
Add ec2:DescribeInternetGateways permission to GithubRole
codeguru42 Jan 3, 2023
1044107
Add ec2:DeleteInternetGateway permission to GithubRole
codeguru42 Jan 3, 2023
a66adde
Add ec2:AttachInternetGateway permission to GithubRole
codeguru42 Jan 3, 2023
48efa86
Add iam:DeleteRolePolicy permission to GithubRole
codeguru42 Jan 19, 2023
cc783c5
Add GatewayAttachment and PublicRoute
codeguru42 Feb 22, 2023
0f90d52
Add ec2:AttachInternetGateway and ec2:DetachInternetGateway permissio…
codeguru42 Feb 22, 2023
3e9d1f4
Add ec2:DescribeRouteTables permissions to GithubRole
codeguru42 Feb 22, 2023
c0fbfbc
Add ec2:AssociateRouteTable permissions to GithubRole
codeguru42 Feb 22, 2023
0181d86
Add ec2:CreateRoute permissions to GithubRole
codeguru42 Feb 22, 2023
527efd7
No quotes in YAML
codeguru42 Feb 22, 2023
0eb36d0
Add ec2:DisassociateRouteTable and ec2:DeleteRouteTable permissions t…
codeguru42 Feb 22, 2023
7bdb895
Add LogConfiguration to TaskDefinition
codeguru42 Feb 22, 2023
141a07a
Add options for log configuration
codeguru42 Feb 22, 2023
89dd3de
Add logs:CreateLogGroup permission to GithubRole
codeguru42 Feb 22, 2023
06f1cf7
Add logs:DeleteLogGroup permission to GithubRole
codeguru42 Feb 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
id-token: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: arn:aws:iam::200049542062:role/gocapture/GithubRole
aws-region: us-west-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Deploy ECS Cluster
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: go-capture
IMAGE_TAG: ${{ github.sha }}
uses: aws-actions/aws-cloudformation-github-deploy@v1
with:
name: GoCaptureECSCluster
capabilities: CAPABILITY_NAMED_IAM
parameter-overrides: "TaskImage=${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}"
template: cloud-formation/ecs.yaml
no-fail-on-empty-changeset: 1
108 changes: 108 additions & 0 deletions cloud-formation/ecs.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,113 @@
Parameters:
TaskImage:
Type: String
Resources:
ExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: GoCaptureExecutionRole
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service: ecs-tasks.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
TaskRole:
Type: AWS::IAM::Role
Properties:
RoleName: GoCaptureTaskRole
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service: ecs-tasks.amazonaws.com
Vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
InternetGateway:
Type: AWS::EC2::InternetGateway
VPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref Vpc
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: GoCaptureSecurityGroup
GroupDescription: Security Group for Go Capture ECS Service
VpcId: !Ref Vpc
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.0.0/16
MapPublicIpOnLaunch: true
VpcId: !Ref Vpc
Cluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: GoCaptureCluster
Service:
Type: AWS::ECS::Service
Properties:
Cluster: !Ref Cluster
DesiredCount: 1
LaunchType: FARGATE
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- !Ref SecurityGroup
Subnets:
- !Ref PublicSubnet
ServiceName: GoCaptureECSService
TaskDefinition: !Ref TaskDefinition
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Name: GoCaptureContainer
Image: !Ref TaskImage
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: us-west-1
awslogs-group: !Ref LogGroup
Cpu: .25 vCPU
ExecutionRoleArn: !Ref ExecutionRole
Family: GoCapture
Memory: 0.5 GB
NetworkMode: awsvpc
RuntimePlatform:
CpuArchitecture: X86_64
OperatingSystemFamily: LINUX
TaskRoleArn: !Ref TaskRole
GatewayAttachment:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref Vpc
PublicRoute:
Type: 'AWS::EC2::Route'
DependsOn: GatewayAttachment
Properties:
DestinationCidrBlock: '0.0.0.0/0'
GatewayId: !Ref InternetGateway
RouteTableId: !Ref PublicRouteTable
PublicRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref Vpc
PublicSubnetRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: GoCaptureLogs
76 changes: 70 additions & 6 deletions cloud-formation/github-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Resources:
"Version": "2012-10-17",
"Statement": [
{
"Effect": Allow,
"Effect": "Allow",
"Action": [
cloudformation:CreateChangeSet,
cloudformation:CreateStack,
Expand All @@ -33,17 +33,20 @@ Resources:
cloudformation:ExecuteChangeSet,
],
"Resource": "*"
},
}
]
}
- PolicyName: IamPolicy
PolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": Allow,
"Effect": "Allow",
"Action": [
iam:CreateRole,
iam:CreateUser,
iam:DeleteRole,
iam:DeleteRolePolicy,
iam:DeleteUser,
iam:DeleteUserPolicy,
iam:GetRole,
Expand All @@ -55,15 +58,15 @@ Resources:
iam:UpdateAssumeRolePolicy,
],
"Resource": "*"
},
}
]
}
- PolicyName: EcrPolicy
PolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": Allow,
"Effect": "Allow",
"Action": [
ecr:BatchCheckLayerAvailability,
ecr:BatchGetImage,
Expand All @@ -81,7 +84,68 @@ Resources:
ecr:UploadLayerPart
],
"Resource": "*"
},
}
]
}
- PolicyName: EcsPolicy
PolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
ecs:CreateCluster,
ecs:CreateService,
ecs:DeleteCluster,
ecs:DeleteService,
ecs:DeregisterTaskDefinition,
ecs:DescribeClusters,
ecs:DescribeServices,
ecs:RegisterTaskDefinition,
ecs:UpdateService,
iam:AttachRolePolicy,
iam:DetachRolePolicy,
iam:PassRole,
logs:CreateLogGroup,
logs:DeleteLogGroup
],
"Resource": "*"
}
]
}
- PolicyName: Ec2Policy
PolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
ec2:AssociateRouteTable,
ec2:AttachInternetGateway,
ec2:CreateInternetGateway,
ec2:CreateRoute,
ec2:CreateRouteTable,
ec2:CreateSecurityGroup,
ec2:CreateSubnet,
ec2:CreateTags,
ec2:CreateVpc,
ec2:DeleteInternetGateway,
ec2:DeleteRouteTable,
ec2:DeleteSecurityGroup,
ec2:DeleteSubnet,
ec2:DeleteVpc,
ec2:DescribeInternetGateways,
ec2:DescribeRouteTables,
ec2:DescribeSecurityGroups,
ec2:DescribeSubnets,
ec2:DescribeVpcs,
ec2:DetachInternetGateway,
ec2:DisassociateRouteTable,
ec2:ModifySubnetAttribute,
ec2:ModifyVpcAttribute
],
"Resource": "*"
}
]
}

Expand Down