Skip to content

Commit d5e4042

Browse files
authored
Add CI pipeline (#3)
1 parent 8191af9 commit d5e4042

File tree

15 files changed

+373
-87
lines changed

15 files changed

+373
-87
lines changed

.buildkite/pipeline.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
steps:
2+
- label: ":lipstick:"
3+
command: .buildkite/shfmt.sh
4+
- label: ":lipstick:"
5+
command: .buildkite/terraform-fmt.sh
6+
- label: ":lint-roller:"
7+
command: .buildkite/shellcheck.sh
8+
- label: ":terraform:"
9+
command: .buildkite/terraform-validate.sh

.buildkite/shellcheck.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
cd "$(dirname "${BASH_SOURCE[0]}")"/..
6+
7+
SHELL_SCRIPTS=()
8+
while IFS='' read -r line; do SHELL_SCRIPTS+=("$line"); done < <(find . -type f -name '*.sh')
9+
shellcheck --external-sources --source-path="SCRIPTDIR" --color=always "${SHELL_SCRIPTS[@]}"

.buildkite/shfmt.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
cd "$(dirname "${BASH_SOURCE[0]}")"/..
6+
7+
shfmt -i 2 -ci -d .

.buildkite/terraform-fmt.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
cd "$(dirname "${BASH_SOURCE[0]}")"/..
6+
7+
terraform fmt -check -recursive .

.buildkite/terraform-validate.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
cd "$(dirname "${BASH_SOURCE[0]}")"/..
6+
7+
MODULES=(
8+
./modules/networking
9+
./modules/docker-mirror
10+
./modules/executors
11+
.
12+
)
13+
14+
# Ensure terraform validate has a valid region
15+
# https://github.com/hashicorp/terraform/issues/21408#issuecomment-495746582
16+
export AWS_DEFAULT_REGION=us-east-2
17+
18+
for module in "${MODULES[@]}"; do
19+
pushd "${module}"
20+
terraform init
21+
terraform validate .
22+
popd
23+
done

.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
root = true
2+
3+
[*]
4+
insert_final_newline = true
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
[*.go]
12+
indent_style = tab
13+
14+
[{*.json,*.yml,*.yaml,*.md}]
15+
indent_size = 2
16+
17+
[*.md]
18+
trim_trailing_whitespace = false
19+
20+
[{*.sh,*.bash}]
21+
indent_style = space
22+
indent_size = 2
23+
switch_case_indent = true
24+
25+
[**/node_modules/**]
26+
ignore = true

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"EditorConfig.editorconfig"
4+
]
5+
}

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"editor.formatOnSave": true,
32
"files.exclude": {
43
"**/.git": true,
54
"**/.svn": true,
@@ -8,5 +7,7 @@
87
"**/.DS_Store": true,
98
"**/Thumbs.db": true,
109
"plan": true
11-
}
10+
},
11+
"editor.formatOnSave": true,
12+
"shellformat.flag": "-i 2 -ci",
1213
}

main.tf

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
locals {
2-
availability_zone = "us-west-2a"
3-
docker_mirror_static_ip = "10.0.1.4"
4-
}
5-
61
# Datasource to fetch the latest AMI of Ubuntu 20.04 for use in the docker mirror.
72
data "aws_ami" "ubuntu" {
83
most_recent = true
@@ -19,23 +14,51 @@ data "aws_ami" "ubuntu" {
1914
}
2015

2116
module "aws-networking" {
22-
source = "./modules/networking/aws"
23-
availability_zone = local.availability_zone
17+
source = "./modules/networking"
18+
19+
availability_zone = var.availability_zone
2420
}
2521

2622
module "aws-docker-mirror" {
27-
source = "./modules/docker-mirror/aws"
23+
source = "./modules/docker-mirror"
2824

29-
availability_zone = local.availability_zone
30-
vpc_id = module.aws-networking.vpc_id
31-
subnet_id = module.aws-networking.subnet_id
32-
machine_ami = data.aws_ami.ubuntu.id
33-
static_ip = local.docker_mirror_static_ip
25+
vpc_id = module.aws-networking.vpc_id
26+
subnet_id = module.aws-networking.subnet_id
27+
machine_ami = coalesce(var.docker_mirror_machine_ami, data.aws_ami.ubuntu.id)
28+
machine_type = var.docker_mirror_machine_type
29+
boot_disk_size = var.docker_mirror_boot_disk_size
30+
static_ip = var.docker_mirror_static_ip
31+
ssh_access_cidr_range = var.docker_mirror_ssh_access_cidr_range
32+
http_access_cidr_range = var.docker_mirror_http_access_cidr_range
3433
}
3534

3635
module "aws-executor" {
37-
source = "./modules/executors/aws"
36+
source = "./modules/executors"
3837

39-
vpc_id = module.aws-networking.vpc_id
40-
subnet_id = module.aws-networking.subnet_id
38+
vpc_id = module.aws-networking.vpc_id
39+
subnet_id = module.aws-networking.subnet_id
40+
resource_prefix = var.executor_resource_prefix
41+
machine_image = var.executor_machine_image
42+
machine_type = var.executor_machine_type
43+
boot_disk_size = var.executor_boot_disk_size
44+
preemptible_machines = var.executor_preemptible_machines
45+
instance_tag = var.executor_instance_tag
46+
ssh_access_cidr_range = var.executor_ssh_access_cidr_range
47+
http_access_cidr_range = var.executor_http_access_cidr_range
48+
sourcegraph_external_url = var.executor_sourcegraph_external_url
49+
sourcegraph_executor_proxy_username = var.executor_sourcegraph_executor_proxy_username
50+
sourcegraph_executor_proxy_password = var.executor_sourcegraph_executor_proxy_password
51+
queue_name = var.executor_queue_name
52+
maximum_runtime_per_job = var.executor_maximum_runtime_per_job
53+
maximum_num_jobs = var.executor_maximum_num_jobs
54+
num_total_jobs = var.executor_num_total_jobs
55+
max_active_time = var.executor_max_active_time
56+
firecracker_num_cpus = var.executor_firecracker_num_cpus
57+
firecracker_memory = var.executor_firecracker_memory
58+
firecracker_disk_space = var.executor_firecracker_disk_space
59+
min_replicas = var.executor_min_replicas
60+
max_replicas = var.executor_max_replicas
61+
jobs_per_instance_scaling = var.executor_jobs_per_instance_scaling
62+
metrics_environment_label = var.executor_metrics_environment_label
63+
docker_registry_mirror = var.executor_docker_registry_mirror
4164
}

modules/docker-mirror/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ variable "static_ip" {
3333
variable "ssh_access_cidr_range" {
3434
type = string
3535
default = "0.0.0.0/0"
36-
description = "CIDR range from where SSH access to the EC2 instance is acceptable from."
36+
description = "CIDR range from where SSH access to the EC2 instance is acceptable."
3737
}
3838

3939
variable "http_access_cidr_range" {
4040
type = string
4141
default = "10.0.0.0/16"
42-
description = "CIDR range from where HTTP access to the Docker registry is acceptable from."
42+
description = "CIDR range from where HTTP access to the Docker registry is acceptable."
4343
}

0 commit comments

Comments
 (0)