Gerrit Master-Slave

This set of Templates provide all the components to deploy a single Gerrit master and a single Gerrit slave in ECS

Architecture

Four templates are provided in this example:

  • cf-cluster: define the ECS cluster and the networking stack
  • cf-service-master: define the service stack running Gerrit master
  • cf-service-slave: define the service stack running Gerrit slave
  • cf-dns-route: define the DNS routing for the service

Networking

  • Single VPC:
  • CIDR: 10.0.0.0/16
  • Single Availability Zone
  • 1 public Subnets:
  • CIDR: 10.0.0.0/24
  • 1 public NLB exposing:
  • Gerrit master HTTP on port 8080
  • Gerrit master SSH on port 29418
  • 1 public NLB exposing:
  • Gerrit slave HTTP on port 8081
  • Gerrit slave SSH on port 39418
  • SSH agent on port 1022
  • Git daemon on port 9418
  • 1 Internet Gateway
  • 2 type A alias DNS entry, for Gerrit master and slave
  • A SSL certificate available in AWS Certificate Manager

Data persistency

  • EBS volumes for:
    • Indexes
    • Caches
    • Data
    • Git repositories

Deployment type

  • Latest Gerrit version deployed using the official Docker image
  • Application deployed in ECS on a single EC2 instance

Logging

  • Gerrit error_log is exported in a Log Group in CloudWatch
  • Other Gerrit logs still need to be exported

Monitoring

  • Standard CloudWatch monitoring metrics for each component

How to run it

Setup

The setup.env.template is an example of setup file for the creation of the stacks.

Before creating the stacks, create a setup.env in the Makefile directory and correctly set the value of the environment variables.

This is the list of available parameters:

  • DOCKER_REGISTRY_URI: Mandatory. URI of the Docker registry. See the prerequisites section for more details.
  • SSL_CERTIFICATE_ARN: Mandatory. ARN of the SSL Certificate.
  • CLUSTER_STACK_NAME: Optional. Name of the cluster stack. gerrit-cluster by default.
  • SERVICE_MASTER_STACK_NAME: Optional. Name of the master service stack. gerrit-service-master by default.
  • SERVICE_SLAVE_STACK_NAME: Optional. Name of the slave service stack. gerrit-service-slave by default.
  • DNS_ROUTING_STACK_NAME: Optional. Name of the DNS routing stack. gerrit-dns-routing by default.
  • HOSTED_ZONE_NAME: Optional. Name of the hosted zone. mycompany.com by default.
  • MASTER_SUBDOMAIN: Optional. Name of the master sub domain. gerrit-master-demo by default.
  • SLAVE_SUBDOMAIN: Optional. Name of the slave sub domain. gerrit-slave-demo by default.
  • GERRIT_KEY_PREFIX : Optional. Secrets prefix used during the Import into AWS Secret Manager. gerrit_secret by default.
  • CLUSTER_DESIRED_CAPACITY: Optional. Number of EC2 instances composing the cluster. 1 by default.
  • GERRIT_RAM: RAM allocated (MiB) to the Gerrit container. 70000 by default.
  • GERRIT_CPU: vCPU units allocated to the Gerrit container. 10240 by default.
  • GERRIT_HEAP_LIMIT: Maximum heap size of the Java process running Gerrit, in bytes. See Gerrit documentation 35g by default.
  • JGIT_CACHE_SIZE: Maximum number of bytes to load and cache in memory from pack files. See Gerrit documentation for more details. 12g by default.

NOTE: if you are planning to run the monitoring stack, set the CLUSTER_DESIRED_CAPACITY value to at least 2. The resources provided by a single EC2 instance won't be enough for all the services that will be ran

Prerequisites

Follow the steps described in the Prerequisites section

Getting Started

  • Create the cluster, services and DNS routing stacks:
make create-all

The slave will start with 5 min delay to allow the replication from master of All-Users and All-Projects to happen. You can now check in the slave logs to see when the slave is up and running.

NOTE: the creation of the cluster needs an EC2 key pair are useful when you need to connect to the EC2 instances for troubleshooting purposes. The key pair is automatically generated and store them in a pem file on the current directory. To use when ssh-ing into your instances as follow: ssh -i cluster-keys.pem ec2-user@<ec2_instance_ip>

Cleaning up

make delete-all

Access your Gerrit instances

Get the URL of your Gerrit master instance this way:

aws cloudformation describe-stacks \
  --stack-name <SERVICE_MASTER_STACK_NAME> \
  | grep -A1 '"OutputKey": "CanonicalWebUrl"' \
  | grep OutputValue \
  | cut -d'"' -f 4

Similarly for the slave:

aws cloudformation describe-stacks \
  --stack-name <SERVICE_SLAVE_STACK_NAME> \
  | grep -A1 '"OutputKey": "CanonicalWebUrl"' \
  | grep OutputValue \
  | cut -d'"' -f 4

Gerrit master instance ports:

  • HTTP 8080
  • SSH 29418

Gerrit slave instance ports:

  • HTTP 9080
  • SSH 39418

External Services

If you need to setup some external services (maybe for testing purposes, such as SMTP or LDAP), you can follow the instructions here

Monitoring

If you want to monitor your system, you can add a Prometheus and Grafana stack. Here you can find the details on how to add it.

Docker

Refer to the Docker section for information on how to setup docker or how to publish images