|
| 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 | + DocsBuildspecFile: |
| 32 | + Type: String |
| 33 | + Default: .cicd/buildspec_docs.yml |
| 34 | + |
| 35 | + DocsBucketName: |
| 36 | + Type: String |
| 37 | + |
| 38 | + CftDistributionId: |
| 39 | + Type: String |
| 40 | + |
| 41 | +Mappings: |
| 42 | + RepoUrlPrefixes: |
| 43 | + GitHub: |
| 44 | + Prefix: https://github.com/ |
| 45 | + |
| 46 | +Conditions: |
| 47 | + UseGitHub: !Equals [ !Ref RepositoryProvider, 'GitHub'] |
| 48 | + UseCodeCommit: !Equals [ !Ref RepositoryProvider, 'CodeCommit'] |
| 49 | + |
| 50 | +Resources: |
| 51 | + BuildLogsGroup: |
| 52 | + Type: AWS::Logs::LogGroup |
| 53 | + Properties: |
| 54 | + LogGroupName: !Sub 'codebuild/${RepositoryName}/${AWS::StackName}' |
| 55 | + RetentionInDays: !Ref BuildLogsRetentionDays |
| 56 | + CodeBuildRole: |
| 57 | + Type: AWS::IAM::Role |
| 58 | + Properties: |
| 59 | + AssumeRolePolicyDocument: |
| 60 | + Version: '2012-10-17' |
| 61 | + Statement: |
| 62 | + - Action: |
| 63 | + - sts:AssumeRole |
| 64 | + Effect: Allow |
| 65 | + Principal: |
| 66 | + Service: |
| 67 | + - !Sub 'codebuild.${AWS::URLSuffix}' |
| 68 | + Policies: |
| 69 | + - PolicyName: ContentAccess |
| 70 | + PolicyDocument: |
| 71 | + Version: '2012-10-17' |
| 72 | + Statement: |
| 73 | + - Sid: CloudFrontAccess |
| 74 | + Effect: Allow |
| 75 | + Action: |
| 76 | + - cloudfront:CreateInvalidation |
| 77 | + Resource: |
| 78 | + - !Sub 'arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/${CftDistributionId}' |
| 79 | + - Sid: S3ObjectsAccess |
| 80 | + Effect: Allow |
| 81 | + Action: |
| 82 | + - s3:PutObject* |
| 83 | + - s3:GetObject* |
| 84 | + - s3:DeleteObject* |
| 85 | + Resource: |
| 86 | + - !Sub "arn:${AWS::Partition}:s3:::${DocsBucketName}/*" |
| 87 | + - Sid: S3BucketsAccess |
| 88 | + Effect: Allow |
| 89 | + Action: |
| 90 | + - s3:ListBucket |
| 91 | + Resource: |
| 92 | + - !Sub "arn:${AWS::Partition}:s3:::${DocsBucketName}" |
| 93 | + - Sid: CloudWatchLogs |
| 94 | + Effect: Allow |
| 95 | + Action: |
| 96 | + - logs:CreateLogStream |
| 97 | + - logs:PutLogEvents |
| 98 | + Resource: |
| 99 | + - !Sub '${BuildLogsGroup.Arn}' |
| 100 | + - Sid: CodeBuildReportsAccess |
| 101 | + Effect: Allow |
| 102 | + Resource: |
| 103 | + - !Sub 'arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:report-group/*' |
| 104 | + Action: |
| 105 | + - codebuild:UpdateReportGroup |
| 106 | + - codebuild:CreateReportGroup |
| 107 | + - codebuild:CreateReport |
| 108 | + - codebuild:UpdateReport |
| 109 | + - codebuild:BatchPut* |
| 110 | + - Sid: CodeBuildBatch |
| 111 | + Effect: Allow |
| 112 | + Resource: |
| 113 | + - !Sub 'arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:*' |
| 114 | + Action: |
| 115 | + - codebuild:StartBuild |
| 116 | + - codebuild:RetryBuild |
| 117 | + |
| 118 | + |
| 119 | + DocsImagesBuild: |
| 120 | + Type: AWS::CodeBuild::Project |
| 121 | + Properties: |
| 122 | + ServiceRole: !GetAtt 'CodeBuildRole.Arn' |
| 123 | + Description: !Sub 'Publishes ${RepositoryName} new documentation' |
| 124 | + LogsConfig: |
| 125 | + CloudWatchLogs: |
| 126 | + GroupName: !Ref BuildLogsGroup |
| 127 | + Status: ENABLED |
| 128 | + StreamName: docker-builds |
| 129 | + BadgeEnabled: True |
| 130 | + Artifacts: |
| 131 | + Type: NO_ARTIFACTS |
| 132 | + Environment: |
| 133 | + ComputeType: BUILD_GENERAL1_SMALL |
| 134 | + Image: aws/codebuild/standard:5.0 |
| 135 | + Type: LINUX_CONTAINER |
| 136 | + EnvironmentVariables: |
| 137 | + - Name: PY_VERSION |
| 138 | + Type: PLAINTEXT |
| 139 | + Value: 3.8 |
| 140 | + - Type: PLAINTEXT |
| 141 | + Name: DOCS_BUCKET |
| 142 | + Value: !Ref DocsBucketName |
| 143 | + - Type: PLAINTEXT |
| 144 | + Name: DISTRIBUTION_ID |
| 145 | + Value: !Ref CftDistributionId |
| 146 | + Source: |
| 147 | + Type: GITHUB |
| 148 | + ReportBuildStatus: True |
| 149 | + Location: !If |
| 150 | + - UseGitHub |
| 151 | + - !Sub 'https://github.com/${RepositoryOrganization}/${RepositoryName}' |
| 152 | + - !Sub 'https://codecommit.${AWS::Region}.${AWS::URLSuffix}' |
| 153 | + InsecureSsl: False |
| 154 | + BuildSpec: !Ref DocsBuildspecFile |
| 155 | + Triggers: |
| 156 | + Webhook: True |
| 157 | +# BuildType: BUILD_BATCH |
| 158 | + FilterGroups: |
| 159 | + - - Type: EVENT |
| 160 | + Pattern: "PUSH" |
| 161 | + ExcludeMatchedPattern: False |
| 162 | + - Type: HEAD_REF |
| 163 | + Pattern: !Sub '^refs/tags/v.*$' |
| 164 | + ExcludeMatchedPattern: False |
| 165 | +# - - Type: EVENT |
| 166 | +# Pattern: "PULL_REQUEST_MERGED" |
| 167 | +# ExcludeMatchedPattern: False |
| 168 | +# - Type: HEAD_REF |
| 169 | +# Pattern: '^refs/heads/.*$' |
| 170 | +# ExcludeMatchedPattern: False |
| 171 | +# - Type: BASE_REF |
| 172 | +# Pattern: !Sub '^refs/heads/${ReferenceBranchName}$' |
| 173 | +# ExcludeMatchedPattern: False |
0 commit comments