We use Hashicorp Packer to build images:
-
Run
packer init
(ignore any warnings about unused variables here):packer init --var-file=./packer/dev/dev-variables.hcl ./packer/dev/dev-builder.pkr.hcl packer init --var-file=./packer/build-variables.hcl ./packer/aws/aws-builder.pkr.hcl packer init --var-file=./packer/build-variables.hcl ./packer/aws-latest/aws-builder.pkr.hcl packer init --var-file=./packer/build-variables.hcl ./packer/gcp/gcp-builder.pkr.hcl
-
- In AWS, select the username dropdown in the top right of the page and choose Security credentials to create an access key.
- In your
~/.zshrc
,~/.bash_profile
, etc. add:
export AWS_ACCESS_KEY_ID="xxx" export AWS_SECRET_ACCESS_KEY="yyy" export AWS_DEFAULT_REGION="us-west-1"
doc/
: project documentationpacker/
AMI-specific build scripts (Packer files)install/
: installation scripts ran on a machine to turn it into a Sourcegraph deploymentinstall.sh
: primary installation script ran on machine to turn it into a Sourcegraph deployment. Installs k3s, runs helm install, etc.ingress.yaml
: Kubernetes ingress controller configurationreboot.sh
: a cronjob script ran on reboot to deal with the IP address / networking interfaces changing, upgrades, etc.override.<size>.yaml
: The Helm override file we use for a given T-shirt size.
build.sh
: builds all AMIs and publishes to all supported regionslint.sh
: run code formatters, validate Packer files, etc.
To create an AMI for a given T-shirt size, follow the instructions in our development docs and refer to the following tables.
Size | Users | Repositories | Largest Repo Size | Concurrent Users | Instance type | Storage | IOPS |
---|---|---|---|---|---|---|---|
XS | 00,500 | 1,000 | 5GB | 100 | m6a.2xlarge | gp3 | default |
S | 01,000 | 10,000 | 23GB | 200 | m6a.4xlarge | gp3 | default |
M | 05,000 | 50,000 | 23GB | 1,000 | m6a.8xlarge | gp3 | default |
L | 10,000 | 100,000 | 35GB | 2,000 | m6a.12xlarge | io2 | 16,000 |
XL | 20,000 | 250,000 | 35GB | 4,000 | m6a.24xlarge | io2 | 16,000 |
Coming soon.
Coming soon.
To build a single AMI for testing, update the packer/dev/dev-variables.hcl
file with the instance version and instance size. This file provides the configuration which is used by /packer/dev/dev-builder.pkr.hcl
to build a single image using XS instance setting. The name of the output AMI will be "Sourcegraph-DEV-v${var.instance_version}-${formatdate("YYYY-MM-DD", timestamp())}"
, with the NAME=ami-dev
tag.
Then run:
packer init packer/dev
packer build -var-file=/packer/dev/dev-variables.hcl /packer/dev/dev-builder.pkr.hcl
To create images for all cloud providers:
- Update the
instance_version
variable on line 1 inside the packer/build-variables.hcl file with the version number for the build- If trying to create a non-development build, also set
dev = false
.
- If trying to create a non-development build, also set
- Run
bash build.sh
from the root of this repository, which will:- Build the images for all sizes for each supported cloud provider
- Copy them to the relevant regions
- Mark them as public
- Update CHANGELOG.md with the list of image IDs you just published for the new version
- Update the
instance_version
variable on line 1 inside the packer/build-variables.hcl file with the version number for the build - Run
packer build --var-file=./packer/build-variables.hcl ./packer/aws/aws-builder.pkr.hcl
from the root of this repository, which will:- Build the AWS AMIs for all sizes
- Copy them to the relevant regions
- Update CHANGELOG.md with the list of AMI IDs you just published for the new version
- Run
packer build --var-file=./packer/build-variables.hcl ./packer/aws-latest/aws-builder.pkr.hcl
- Copy the AMI ID output into
packer/aws-latest/_ami.yaml
- maintaining yaml structure - Run
cd packer/aws-latest/ && cat _ami.yaml | yj | ./_convert.py
- Copy the output to
packer/aws-latest/sg-basic.yaml
under theMappings
-RegionMap
- Upload
packer/aws-latest/sg-basic.yaml
to the S3 bucketsourcegraph-cloudformation
in theSourcegraph AMI
AWS account
- Update the
instance_version
variable on line 1 inside the packer/build-variables.hcl file with the version number for the build - Run
packer build --var-file=./packer/build-variables.hcl ./packer/gcp/gcp-builder.pkr.hcl
(insure version is not specified) from the root of this repository, which will:- Build the Google Compute Machine Images for all sizes
- Copy them to the storage buckets
- Mark them as public
- Update CHANGELOG.md with the list of image IDs you just published for the new version, along with the links to the storage buckets
- Once the release is published with all the commits merged, run the following commands on the
main
branch:
# e.g. git tag v4.0.1
git tag v${instance_version}
# e.g. git push origin v4.0.1
git push origin v${instance_version}
IMPORTANT: AMI will be published to all regions by default.
If adding a new region, you may need to create a subnet with the Name
tag packer-build
(Packer finds the subnet based on the name):
- Navigate to the Subnets
- Create subnet
- VPC: default
- Subnet name: packer-build
- IPv4 CIDR block: 10.0.0.0/24