--- AWSTemplateFormatVersion: 2010-09-09 Parameters: GitHubRepo002: Type: String GitHubBranch: Type: String GitHubToken: Type: String NoEcho: true GitHubUser: Type: String Cluster: Type: String Service: Type: String CodeBuildServiceRole: Type: String CodePipelineServiceRoleArn: Type: String ArtifactBucketName: Type: String Resources: Repository: Type: AWS::ECR::Repository DeletionPolicy: Retain CodeBuildProject: Type: AWS::CodeBuild::Project Properties: Artifacts: Type: CODEPIPELINE Source: Type: CODEPIPELINE BuildSpec: | version: 0.2 phases: pre_build: commands: - $(aws ecr get-login --no-include-email) - TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)" - IMAGE_URI="${REPOSITORY_URI}:${TAG}" build: commands: - mvn package -Pdocker -Ddocker.repo=$REPOSITORY_URI -Ddocker.tag=$TAG post_build: commands: - docker tag $REPOSITORY_URI/webapp:$TAG $IMAGE_URI - docker push "$IMAGE_URI" - printf '[{"name":"webapp","imageUri":"%s"}]' "$IMAGE_URI" > images-webapp.json artifacts: files: images-webapp.json Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/java:openjdk-8 PrivilegedMode: true Type: LINUX_CONTAINER EnvironmentVariables: - Name: AWS_DEFAULT_REGION Value: !Ref AWS::Region - Name: REPOSITORY_URI Value: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${Repository} Name: !Ref AWS::StackName ServiceRole: !Ref CodeBuildServiceRole Pipeline: Type: AWS::CodePipeline::Pipeline Properties: RoleArn: !Ref CodePipelineServiceRoleArn ArtifactStore: Type: S3 Location: !Ref ArtifactBucketName Stages: - Name: Source Actions: - Name: App ActionTypeId: Category: Source Owner: ThirdParty Version: 1 Provider: GitHub Configuration: Owner: !Ref GitHubUser Repo: !Ref GitHubRepo002 Branch: !Ref GitHubBranch OAuthToken: !Ref GitHubToken OutputArtifacts: - Name: App RunOrder: 1 - Name: Build Actions: - Name: Build ActionTypeId: Category: Build Owner: AWS Version: 1 Provider: CodeBuild Configuration: ProjectName: !Ref CodeBuildProject InputArtifacts: - Name: App OutputArtifacts: - Name: BuildOutput RunOrder: 1 - Name: Deploy Actions: - Name: Deploy ActionTypeId: Category: Deploy Owner: AWS Version: 1 Provider: ECS Configuration: ClusterName: !Ref Cluster ServiceName: !Ref Service FileName: images-webapp.json InputArtifacts: - Name: BuildOutput RunOrder: 1 Outputs: PipelineUrl: Value: !Sub https://console.aws.amazon.com/codepipeline/home?region=${AWS::Region}#/view/${Pipeline}