Bitbucket Server / CI integration

Setting up the Bitbucket Server / CI integration

There is an official AWS Quick Start which can be found here: https://aws.amazon.com/quickstart/architecture/git-to-s3-using-webhooks/ This Quick Start will be used to setup the integration between Bitbucket Server and Codepipeline.

Click on the Deployment Guide for more details.

Enhance the Makefile in the infrastructure git project with the following content:

CI_BITBUCKET_BUCKET_NAME         := myorg-bitbucket-s3
CI_GIT2S3_TEMPLATE_BUCKET_NAME   := myorg-bitbucket-s3-template

###############################################################################################

.PHONY: ci-bitbucket-s3
ci-bitbucket-s3:
	aws cloudformation deploy \
		--no-fail-on-empty-changeset \
		--template-file ci/git2s3-template-bucket.yml \
		--stack-name bitbucket-s3-template-bucket \
		--parameter-overrides BucketName=$(CI_GIT2S3_TEMPLATE_BUCKET_NAME) \
		--region $(AWS_REGION)
	aws cloudformation deploy \
		--no-fail-on-empty-changeset \
		--template-file ci/git2s3.json \
		--s3-bucket $(CI_GIT2S3_TEMPLATE_BUCKET_NAME) \
		--stack-name bitbucket-s3 \
		--parameter-overrides OutputBucketName=$(CI_BITBUCKET_BUCKET_NAME) \
		--capabilities CAPABILITY_IAM \
		--region $(AWS_REGION)

Create a new cloudformation template in ci/git2s3-template-bucket.yml and define the template bucket in there:

---
AWSTemplateFormatVersion: 2010-09-09
Description: Template bucket for Git2S3, used because the template is to large to use it directly

Parameters:
  BucketName:
    Type: String
Resources:
  Bucket:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName: !Ref BucketName
      PublicAccessBlockConfiguration:
        BlockPublicAcls: true
        IgnorePublicAcls: true
        BlockPublicPolicy: true
        RestrictPublicBuckets: true
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256

Additionally create a new cloudformation template in ci/git2s3.json and fill in the template from the quickstart:

Get the template:

mkdir -p ci
curl -flL https://github.com/aws-quickstart/quickstart-git2s3/raw/c9a09bbc280ca425f7c85fe6a12be967268611f2/templates/git2s3.template -o ci/git2s3.json

Create the Cloudformation stack with the following command:

AWS_PROFILE=myorg-ci make ci-bitbucket-s3