AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: Bucket: Type: AWS::S3::Bucket Properties: BucketName: !Sub ${AWS::StackName}-bucket-${AWS::AccountId} WebsiteConfiguration: IndexDocument: index.html Website: Type: AWS::CodeBuild::Project Metadata: StackeryType: website DependsOn: WebsiteRole Properties: Name: !Sub ${AWS::StackName}-Website Artifacts: Type: NO_ARTIFACTS Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 Type: LINUX_CONTAINER EnvironmentVariables: [] ServiceRole: !GetAtt WebsiteRole.Arn Source: Type: NO_SOURCE BuildSpec: !Sub - |- version: 0.2 phases: install: commands: - | _SOURCE_LOCATION="${SourceLocation}" if [ s3 != "${!_SOURCE_LOCATION%%:*}" ]; then git clone "${SourceLocation}" repo cd repo git checkout "${SourceVersion}" else aws s3 cp "${SourceLocation}" repo.tgz tar --strip-components 1 -xvvzf repo.tgz fi - cd ${SourceDirectory} pre_build: commands: - | if [ ! -f yarn.lock -a -f package.json ]; then npm install --production elif [ -f yarn.lock -a -f package.json ]; then yarn install --production elif [ -f requirements.txt ]; then pip install -r requirements.txt elif [ -f Gemfile ]; then bundle install fi - git clone https://github.com/matcornic/hugo-theme-learn.git themes/hugo-theme-learn - cd themes/hugo-theme-learn && git checkout 6cfd61e0f675b45ba85f8325e206d23a4337a14c && cd ../.. - wget https://github.com/gohugoio/hugo/releases/download/v0.82.0/hugo_0.82.0_Linux-64bit.tar.gz -O - | tar -xz build: commands: - ${BuildCommand} - ${BuildCommand} --baseURL /workshops/dotnet --destination public/workshops/dotnet post_build: commands: - if [ $CODEBUILD_BUILD_SUCCEEDING == 0 ]; then exit 1; fi - | _SOURCE_LOCATION=${SourceLocation} if [ s3 != "${!_SOURCE_LOCATION%%:*}" ]; then cd "${!CODEBUILD_SRC_DIR}/repo" else cd "${!CODEBUILD_SRC_DIR}" fi - aws s3 sync '${PublishDirectory}' 's3://${DestinationBucketName}' --acl public-read --cache-control 'max-age=0, must-revalidate, public' --no-progress --delete - PublishDirectory: public BuildCommand: ./hugo SourceDirectory: . DestinationBucketName: !Ref Bucket Tags: - Key: Stackery Project Type Value: Website Builder WebsiteEvents: Type: AWS::Events::Rule Properties: EventPattern: source: - aws.codebuild detail-type: - CodeBuild Build State Change detail: build-status: - SUCCEEDED - FAILED - FAULT - STOPPPED - TIMED_OUT project-name: - !Ref Website Targets: - Arn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:stackery-agent-commander Id: StackeryAgentCommander WebsiteEventsPermission: Type: AWS::Lambda::Permission DependsOn: WebsiteEvents Properties: Action: lambda:InvokeFunction FunctionName: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:stackery-agent-commander Principal: events.amazonaws.com SourceArn: !GetAtt WebsiteEvents.Arn WebsiteRole: Type: AWS::IAM::Role Properties: RoleName: !Sub ${AWS::StackName}-Website AssumeRolePolicyDocument: Version: '2012-10-17' Statement: Effect: Allow Principal: Service: codebuild.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: Logs PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents Resource: - !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/${AWS::StackName}-Website:log-stream:* - PolicyName: DownloadSourceFromStackeryAssetsBucket PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: s3:GetObject Resource: arn:aws:s3:::stackery-assetsbucket-*/* - PolicyName: UploadToDestinationObjectStore PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - s3:DeleteObject - s3:GetBucketLocation - s3:GetObject - s3:ListBucket - s3:PutObject - s3:PutObjectAcl Resource: - !Sub ${Bucket.Arn}/* - !Sub ${Bucket.Arn} WebsiteBuildTrigger: Type: Custom::StackeryWebsiteBuildTrigger DependsOn: WebsiteEvents Properties: ServiceToken: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:stackery-agent-commander Type: website ProjectName: !Ref Website SourceVersion: !Ref SourceVersion Parameters: SourceLocation: Type: String Description: Location of source code for deployment (injected by Stackery at deployment time) SourceVersion: Type: String Description: Source version for deployment (injected by Stackery at deployment time)