- Rename forgejo.yaml to forgejo-cl.yaml - Make S3 bucket and IAM ARNs region-agnostic - Disable CodePipeline S3 polling - Enable S3 → EventBridge notifications - Add EventBridge rule and IAM role to trigger pipeline on object creation - Tighten IAM permissions for CodeBuild and CodePipeline - Normalize file mode for forgejo-efs.yaml
222 lines
7.1 KiB
YAML
222 lines
7.1 KiB
YAML
AWSTemplateFormatVersion: "2010-09-09"
|
|
Description: S3 -> CodePipeline -> CodeBuild(ARM) -> ECR pipeline for Forgejo
|
|
|
|
Parameters:
|
|
SourceBucketName:
|
|
Type: String
|
|
Default: forgejo-source-bucket
|
|
|
|
SourceObjectKey:
|
|
Type: String
|
|
Default: forgejo-source.zip
|
|
|
|
ForgejoRepositoryName:
|
|
Type: String
|
|
Default: forgejo-repository
|
|
|
|
Resources:
|
|
|
|
SourceBucket:
|
|
Type: AWS::S3::Bucket
|
|
Properties:
|
|
BucketName: !Sub "${AWS::Region}-${AWS::AccountId}-${SourceBucketName}"
|
|
Tags:
|
|
- Key: Project
|
|
Value: Git-server
|
|
VersioningConfiguration:
|
|
Status: Enabled
|
|
NotificationConfiguration:
|
|
EventBridgeConfiguration:
|
|
EventBridgeEnabled: true
|
|
|
|
ForgejoRepository:
|
|
Type: AWS::ECR::Repository
|
|
Properties:
|
|
RepositoryName: !Ref ForgejoRepositoryName
|
|
ImageScanningConfiguration:
|
|
ScanOnPush: true
|
|
|
|
CodeBuildRole:
|
|
Type: AWS::IAM::Role
|
|
Properties:
|
|
AssumeRolePolicyDocument:
|
|
Version: "2012-10-17"
|
|
Statement:
|
|
- Effect: Allow
|
|
Principal:
|
|
Service: codebuild.amazonaws.com
|
|
Action: sts:AssumeRole
|
|
Policies:
|
|
- PolicyName: CodeBuildPolicy
|
|
PolicyDocument:
|
|
Version: "2012-10-17"
|
|
Statement:
|
|
- Effect: Allow
|
|
Action:
|
|
- logs:CreateLogGroup
|
|
- logs:CreateLogStream
|
|
- logs:PutLogEvents
|
|
Resource: "*"
|
|
- Effect: Allow
|
|
Action:
|
|
- ecr:GetAuthorizationToken
|
|
Resource: "*"
|
|
- Effect: Allow
|
|
Action:
|
|
- ecr:BatchCheckLayerAvailability
|
|
- ecr:InitiateLayerUpload
|
|
- ecr:UploadLayerPart
|
|
- ecr:CompleteLayerUpload
|
|
- ecr:PutImage
|
|
Resource:
|
|
- !Sub "arn:aws:ecr:ap-northeast-1:${AWS::AccountId}:repository/forgejo-repository"
|
|
- Effect: Allow
|
|
Action:
|
|
- s3:GetObject
|
|
- s3:PutObject
|
|
- s3:ListBucket
|
|
Resource:
|
|
- !Sub "arn:aws:s3:::codebuild-${AWS::Region}-${AWS::AccountId}-input-bucket"
|
|
- !Sub "arn:aws:s3:::codebuild-${AWS::Region}-${AWS::AccountId}-input-bucket/*"
|
|
- !Sub "arn:aws:s3:::${AWS::Region}-${AWS::AccountId}-${SourceBucketName}"
|
|
- !Sub "arn:aws:s3:::${AWS::Region}-${AWS::AccountId}-${SourceBucketName}/*"
|
|
|
|
|
|
ForgejoBuildProject:
|
|
Type: AWS::CodeBuild::Project
|
|
Properties:
|
|
ServiceRole: !GetAtt CodeBuildRole.Arn
|
|
Artifacts:
|
|
Type: CODEPIPELINE
|
|
Environment:
|
|
Type: ARM_CONTAINER
|
|
ComputeType: BUILD_GENERAL1_MEDIUM
|
|
Image: aws/codebuild/amazonlinux2-aarch64-standard:3.0
|
|
PrivilegedMode: true
|
|
EnvironmentVariables:
|
|
- Name: ECR_REPOSITORY
|
|
Value: !Ref ForgejoRepositoryName
|
|
Source:
|
|
Type: CODEPIPELINE
|
|
TimeoutInMinutes: 30
|
|
|
|
CodePipelineRole:
|
|
Type: AWS::IAM::Role
|
|
Properties:
|
|
AssumeRolePolicyDocument:
|
|
Version: "2012-10-17"
|
|
Statement:
|
|
- Effect: Allow
|
|
Principal:
|
|
Service: codepipeline.amazonaws.com
|
|
Action: sts:AssumeRole
|
|
Policies:
|
|
- PolicyName: CodePipelinePolicy
|
|
PolicyDocument:
|
|
Version: '2012-10-17'
|
|
Statement:
|
|
- Effect: Allow
|
|
Action:
|
|
- s3:GetBucketAcl
|
|
- s3:GetObjectTagging
|
|
- s3:GetObjectVersionTagging
|
|
- s3:GetObject
|
|
- s3:GetObjectVersion
|
|
- s3:PutObject
|
|
- s3:ListBucket
|
|
- s3:GetBucketLocation
|
|
- s3:GetBucketVersioning
|
|
Resource:
|
|
- !Sub "arn:aws:s3:::codebuild-${AWS::Region}-${AWS::AccountId}-input-bucket"
|
|
- !Sub "arn:aws:s3:::codebuild-${AWS::Region}-${AWS::AccountId}-input-bucket/*"
|
|
- !Sub "arn:aws:s3:::${AWS::Region}-${AWS::AccountId}-${SourceBucketName}"
|
|
- !Sub "arn:aws:s3:::${AWS::Region}-${AWS::AccountId}-${SourceBucketName}/*"
|
|
- Effect: Allow
|
|
Action:
|
|
- codebuild:StartBuild
|
|
- codebuild:BatchGetBuilds
|
|
Resource:
|
|
- !Sub "arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:build/*"
|
|
- !Sub "arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:project/*"
|
|
- Effect: Allow
|
|
Action:
|
|
- codepipeline:PutApprovalResult
|
|
- codepipeline:StartPipelineExecution
|
|
Resource: !Sub "arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:*"
|
|
|
|
ForgejoPipeline:
|
|
Type: AWS::CodePipeline::Pipeline
|
|
Properties:
|
|
PipelineType: V2
|
|
RoleArn: !GetAtt CodePipelineRole.Arn
|
|
ArtifactStore:
|
|
Type: S3
|
|
Location: !Sub "codebuild-ap-northeast-1-${AWS::AccountId}-input-bucket"
|
|
Stages:
|
|
- Name: Source
|
|
Actions:
|
|
- Name: S3Source
|
|
ActionTypeId:
|
|
Category: Source
|
|
Owner: AWS
|
|
Provider: S3
|
|
Version: "1"
|
|
Configuration:
|
|
S3Bucket: !Ref SourceBucket
|
|
S3ObjectKey: !Ref SourceObjectKey
|
|
PollForSourceChanges: false
|
|
OutputArtifacts:
|
|
- Name: SourceOutput
|
|
- Name: Build
|
|
Actions:
|
|
- Name: BuildImage
|
|
ActionTypeId:
|
|
Category: Build
|
|
Owner: AWS
|
|
Provider: CodeBuild
|
|
Version: "1"
|
|
InputArtifacts:
|
|
- Name: SourceOutput
|
|
Configuration:
|
|
ProjectName: !Ref ForgejoBuildProject
|
|
|
|
S3SourceChangeRule:
|
|
Type: AWS::Events::Rule
|
|
Properties:
|
|
Description: Trigger CodePipeline on S3 source update
|
|
EventPattern:
|
|
source:
|
|
- aws.s3
|
|
detail-type:
|
|
- Object Created
|
|
detail:
|
|
bucket:
|
|
name:
|
|
- !Ref SourceBucket
|
|
object:
|
|
key:
|
|
- !Ref SourceObjectKey
|
|
Targets:
|
|
- Arn: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${ForgejoPipeline}
|
|
RoleArn: !GetAtt EventBridgeInvokePipelineRole.Arn
|
|
Id: CodePipelineTarget
|
|
|
|
EventBridgeInvokePipelineRole:
|
|
Type: AWS::IAM::Role
|
|
Properties:
|
|
AssumeRolePolicyDocument:
|
|
Version: '2012-10-17'
|
|
Statement:
|
|
- Effect: Allow
|
|
Principal:
|
|
Service: events.amazonaws.com
|
|
Action: sts:AssumeRole
|
|
Policies:
|
|
- PolicyName: AllowStartPipeline
|
|
PolicyDocument:
|
|
Version: '2012-10-17'
|
|
Statement:
|
|
- Effect: Allow
|
|
Action:
|
|
- codepipeline:StartPipelineExecution
|
|
Resource: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${ForgejoPipeline}
|