Bitbucket SmartMirror Automation

This is simply a short and sweet method to provision an AWS EC2 instance as an Atlassian Bitbucket Data Center SmartMirror server with no ssh login interaction required, utilizing an EC2 user_data script.

I realize this could be automated even further using tools such as Ansible, Terraform or CloudFormation….but due to the limitless variations in your computing environment, this script focuses purely on the EC2 instance itself.

Assumptions:

This post assumes that you have a fairly advanced knowledge of AWS including EC2, Load Balancers, AWS Certificate Manager, Security Groups, etc.. Please reference the AWS documentation for additional info on those topics.

Prerequisites:

  • Create an AWS Classic internal Load Balancer with listeners: (22 -> 7999, 7999 -> 7999, 443 -> 7990) # Attach an AWS cert for SSL termination on 443. (‘Classic’ is the only LB which allows a mix of both HTTPS & TCP ports. After Aug 15, 2022, AWS will discontinue the Classic LB, and you’ll need to use some other reverse proxy such as HaProxy or Nginx.)
  • Your LB Security Group should allow access to ports 22, 7999 and 443 from your internal network CIDR’s or specific IP’s.
  • Your EC2 instance Security Group should allow access to ports 22, 7999 and 7990 from your LB Security Group above.
  • Register an internal DNS CNAME which points to your LB’s DNS address. Add this to <YOUR_REVERSE_PROXY> below.
  • Below you will be spinning up an EC2 instance with at least 2-CPU, 8Gb-RAM, and enough disk storage to hold the repos you intend to mirror.
  • Modify <YOUR_REVERSE_PROXY>, <YOUR_MIRROR_NAME> and <YOUR_BITBUCKET> below, then paste everything into the “user_data” text field during EC2 launch.

After setup, add your new instance to your Load Balancer (instances tab).

That’s it!

Now login to your Bitbucket Data Center cluster as a user with Admin privileges and click on the “Administration” cog:

…then click on the “Mirrors” link on the left:

If all went well, you should see a Mirror Request from your new EC2 instance waiting to be accepted. Once accepted, you can choose which projects to mirror, or mirror ALL projects (hopefully you’ve allocated enough storage on your mirror for this).

I hope this post makes creating additional Bitbucket SmartMirrors a little quicker and simpler as it did for me. After configuring my DNS and AWS Load Balancer, I’m able to provision a new mirror in just a couple of minutes.

Obsessed with Automation