|
| 1 | +--- |
| 2 | +Description: >- |
| 3 | + Pipeline to release Lambda layers publicly when new release is created |
| 4 | +
|
| 5 | +Metadata: |
| 6 | + Author: https://github.com/johnpreston |
| 7 | + |
| 8 | +Parameters: |
| 9 | + RepositoryOrganization: |
| 10 | + Type: String |
| 11 | + Default: compose-x |
| 12 | + |
| 13 | + RepositoryProvider: |
| 14 | + Type: String |
| 15 | + AllowedValues: |
| 16 | + - GitHub |
| 17 | + - CodeCommit |
| 18 | + Default: GitHub |
| 19 | + RepositoryName: |
| 20 | + Type: String |
| 21 | + |
| 22 | + BuildLogsRetentionDays: |
| 23 | + Type: Number |
| 24 | + AllowedValues: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653] |
| 25 | + Default: 14 |
| 26 | + |
| 27 | + ReferenceBranchName: |
| 28 | + Type: String |
| 29 | + Default: main |
| 30 | + |
| 31 | + DockerBuildspecFile: |
| 32 | + Type: String |
| 33 | + Default: .cicd/buildspec.yml |
| 34 | + |
| 35 | + |
| 36 | +Mappings: |
| 37 | + RepoUrlPrefixes: |
| 38 | + GitHub: |
| 39 | + Prefix: https://github.com/ |
| 40 | + |
| 41 | +Conditions: |
| 42 | + UseGitHub: !Equals [ !Ref RepositoryProvider, 'GitHub'] |
| 43 | + UseCodeCommit: !Equals [ !Ref RepositoryProvider, 'CodeCommit'] |
| 44 | + |
| 45 | +Resources: |
| 46 | + BuildLogsGroup: |
| 47 | + Type: AWS::Logs::LogGroup |
| 48 | + Properties: |
| 49 | + LogGroupName: !Sub 'codebuild/pr-builds/${RepositoryName}' |
| 50 | + RetentionInDays: !Ref BuildLogsRetentionDays |
| 51 | + CodeBuildRole: |
| 52 | + Type: AWS::IAM::Role |
| 53 | + Properties: |
| 54 | + AssumeRolePolicyDocument: |
| 55 | + Version: '2012-10-17' |
| 56 | + Statement: |
| 57 | + - Action: |
| 58 | + - sts:AssumeRole |
| 59 | + Effect: Allow |
| 60 | + Principal: |
| 61 | + Service: |
| 62 | + - !Sub 'codebuild.${AWS::URLSuffix}' |
| 63 | + Policies: |
| 64 | + - PolicyName: ContentAccess |
| 65 | + PolicyDocument: |
| 66 | + Version: '2012-10-17' |
| 67 | + Statement: |
| 68 | + - Sid: CloudWatchLogs |
| 69 | + Effect: Allow |
| 70 | + Action: |
| 71 | + - logs:CreateLogStream |
| 72 | + - logs:PutLogEvents |
| 73 | + Resource: |
| 74 | + - !Sub '${BuildLogsGroup.Arn}' |
| 75 | + - Sid: CodeBuildReportsAccess |
| 76 | + Effect: Allow |
| 77 | + Resource: |
| 78 | + - !Sub 'arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:report-group/*' |
| 79 | + Action: |
| 80 | + - codebuild:UpdateReportGroup |
| 81 | + - codebuild:CreateReportGroup |
| 82 | + - codebuild:CreateReport |
| 83 | + - codebuild:UpdateReport |
| 84 | + - codebuild:BatchPut* |
| 85 | + - Sid: CodeBuildBatch |
| 86 | + Effect: Allow |
| 87 | + Resource: |
| 88 | + - !Sub 'arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:*' |
| 89 | + Action: |
| 90 | + - codebuild:StartBuild |
| 91 | + - codebuild:RetryBuild |
| 92 | + - Sid: ECRAuthAndGetFromAny |
| 93 | + Effect: Allow |
| 94 | + Resource: |
| 95 | + - "*" |
| 96 | + Action: |
| 97 | + - "ecr:GetAuthorizationToken" |
| 98 | + - "ecr:BatchGetImage" |
| 99 | + - "ecr:BatchCheckLayerAvailability" |
| 100 | + - "ecr:GetDownloadUrlForLayer" |
| 101 | + - Sid: ECRPublishToAnyPrivateRepo |
| 102 | + Effect: Allow |
| 103 | + Resource: |
| 104 | + - !Sub "arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/*" |
| 105 | + Action: |
| 106 | + - "ecr:InitiateLayerUpload" |
| 107 | + - "ecr:UploadLayerPart" |
| 108 | + - "ecr:CompleteLayerUpload" |
| 109 | + - "ecr:PutImage" |
| 110 | + |
| 111 | + - Sid: PublicEcrAuth |
| 112 | + Effect: Allow |
| 113 | + Resource: |
| 114 | + - "*" |
| 115 | + Action: [ |
| 116 | + "ecr-public:GetAuthorizationToken", |
| 117 | + "sts:GetServiceBearerToken", |
| 118 | + "ecr-public:BatchCheckLayerAvailability", |
| 119 | + "ecr-public:GetRepositoryPolicy", |
| 120 | + "ecr-public:DescribeRepositories", |
| 121 | + "ecr-public:DescribeRegistries", |
| 122 | + "ecr-public:DescribeImages", |
| 123 | + "ecr-public:DescribeImageTags", |
| 124 | + "ecr-public:GetRepositoryCatalogData", |
| 125 | + "ecr-public:GetRegistryCatalogData", |
| 126 | + ] |
| 127 | + |
| 128 | + - Sid: PublicEcrPublish |
| 129 | + Effect: Allow |
| 130 | + Resource: |
| 131 | + - !Sub "arn:${AWS::Partition}:ecr-public::${AWS::AccountId}:repository/*" |
| 132 | + Action: [ |
| 133 | + "ecr-public:InitiateLayerUpload", |
| 134 | + "ecr-public:UploadLayerPart", |
| 135 | + "ecr-public:CompleteLayerUpload", |
| 136 | + "ecr-public:PutImage" |
| 137 | + ] |
| 138 | + |
| 139 | + DockerImagesBuild: |
| 140 | + Type: AWS::CodeBuild::Project |
| 141 | + Properties: |
| 142 | + ServiceRole: !GetAtt 'CodeBuildRole.Arn' |
| 143 | + Description: !Sub 'Publishes new docker images on updates' |
| 144 | + LogsConfig: |
| 145 | + CloudWatchLogs: |
| 146 | + GroupName: !Ref BuildLogsGroup |
| 147 | + Status: ENABLED |
| 148 | + StreamName: docker-builds |
| 149 | + BadgeEnabled: True |
| 150 | + Artifacts: |
| 151 | + Type: NO_ARTIFACTS |
| 152 | + BuildBatchConfig: |
| 153 | + CombineArtifacts: False |
| 154 | + Restrictions: |
| 155 | + ComputeTypesAllowed: |
| 156 | + - BUILD_GENERAL1_SMALL |
| 157 | + - BUILD_GENERAL1_MEDIUM |
| 158 | + - BUILD_GENERAL1_LARGE |
| 159 | + MaximumBuildsAllowed: 10 |
| 160 | + ServiceRole: !GetAtt 'CodeBuildRole.Arn' |
| 161 | + TimeoutInMins: 60 |
| 162 | + Environment: |
| 163 | + ComputeType: BUILD_GENERAL1_SMALL |
| 164 | + Image: aws/codebuild/standard:5.0 |
| 165 | + Type: LINUX_CONTAINER |
| 166 | + Source: |
| 167 | + Type: GITHUB |
| 168 | + ReportBuildStatus: True |
| 169 | + Location: !If |
| 170 | + - UseGitHub |
| 171 | + - !Sub 'https://github.com/${RepositoryOrganization}/${RepositoryName}' |
| 172 | + - !Sub 'https://codecommit.${AWS::Region}.${AWS::URLSuffix}' |
| 173 | + InsecureSsl: False |
| 174 | + BuildSpec: !Ref DockerBuildspecFile |
| 175 | + Triggers: |
| 176 | + Webhook: True |
| 177 | + BuildType: BUILD_BATCH |
| 178 | + FilterGroups: |
| 179 | + - - Type: EVENT |
| 180 | + Pattern: "PULL_REQUEST_MERGED" |
| 181 | + ExcludeMatchedPattern: False |
| 182 | + - Type: HEAD_REF |
| 183 | + Pattern: '^refs/heads/.*$' |
| 184 | + ExcludeMatchedPattern: False |
| 185 | + - Type: BASE_REF |
| 186 | + Pattern: !Sub '^refs/heads/${ReferenceBranchName}$' |
| 187 | + ExcludeMatchedPattern: False |
| 188 | + - - Type: EVENT |
| 189 | + Pattern: "PUSH" |
| 190 | + ExcludeMatchedPattern: False |
| 191 | + - Type: HEAD_REF |
| 192 | + Pattern: !Sub '^refs/tags/v.*$' |
| 193 | + ExcludeMatchedPattern: False |
0 commit comments