Skip to content
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

Create ECS Task Definition (and role as which task runs) when building container #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
58 changes: 57 additions & 1 deletion container-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,55 @@ Resources:
VpcId: !Ref CodeBuildVPC
Subnets: !Ref CodeBuildSubnets
SecurityGroupIds: !Ref CodeBuildSecurityGroups

ECSTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Sub
- 'bastion-${BastionUser}'
- BastionUser: !Ref BastionUser
RequiresCompatibilities:
- FARGATE
NetworkMode: awsvpc
Cpu: 256
Memory: 512
ExecutionRoleArn: !GetAtt ECSTaskRole.Arn
ContainerDefinitions:
- Name: bastion
Image: !Sub
- '${AccountId}.dkr.ecr.${Region}.amazonaws.com/${BastionECRRepositoryName}:${BastionUser}'
- AccountId: !Ref 'AWS::AccountId'
Region: !Ref 'AWS::Region'
BastionECRRepositoryName: !Ref BastionECRRepositoryName
BastionUser: !Ref BastionUser
PortMappings:
- ContainerPort: 22

ECSTaskRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Version: '2012-10-17'
Policies:
- PolicyName: CodeBuildAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- ecr:GetAuthorizationToken
- ecr:BatchCheckLayerAvailability
- ecr:GetDownloadUrlForLayer
- ecr:BatchGetImage
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*'

CodeBuildRole:
Type: AWS::IAM::Role
Properties:
Expand Down Expand Up @@ -153,4 +202,11 @@ Resources:
- !Ref BastionECRRepositoryName
Outputs:
CodeBuildProject:
Value: !Ref CodeBuildProject
Value: !Ref CodeBuildProject
Image:
Value: !Sub
- '${AccountId}.dkr.ecr.${Region}.amazonaws.com/${BastionECRRepositoryName}:${BastionUser}'
- AccountId: !Ref 'AWS::AccountId'
Region: !Ref 'AWS::Region'
BastionECRRepositoryName: !Ref BastionECRRepositoryName
BastionUser: !Ref BastionUser