-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lcard
committed
Aug 23, 2023
1 parent
62eba78
commit b5fcddd
Showing
20 changed files
with
231 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
data "terraform_remote_state" "vpc-state" { | ||
backend = "s3" | ||
workspace = "prod" | ||
|
||
config = { | ||
key = "vpc/terraform.tfstate" | ||
bucket = var.state_bucket | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
resource "null_resource" "packer_build" { | ||
triggers = { | ||
sha256_ami_config = filesha256("${path.module}/template.json") | ||
sha256_ami_install = filesha256("${path.module}/install.sh") | ||
version = var.pipeline_ami_version | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = <<EOF | ||
set -ex; | ||
PACKER_LOG=1 packer validate \ | ||
-var "version=${var.pipeline_ami_version}" \ | ||
-var "subnet_id=${data.terraform_remote_state.vpc-state.outputs.public_subnets_ids[0]}" \ | ||
-var "vpc_id=${data.terraform_remote_state.vpc-state.outputs.vpc_id}" \ | ||
-var "region=${var.aws_region}" \ | ||
template.json | ||
PACKER_LOG=1 packer build \ | ||
-var "version=${var.pipeline_ami_version}" \ | ||
-var "subnet_id=${data.terraform_remote_state.vpc-state.outputs.public_subnets_ids[0]}" \ | ||
-var "vpc_id=${data.terraform_remote_state.vpc-state.outputs.vpc_id}" \ | ||
-var "region=${var.aws_region}" \ | ||
template.json | ||
EOF | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
terraform { | ||
backend "s3" { | ||
key = "pipeline-ami/terraform.tfstate" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"variables": { | ||
"version": "", | ||
"region": "", | ||
"subnet_id": "", | ||
"vpc_id": "" | ||
}, | ||
"builders": [ | ||
{ | ||
"ami_description": "An AMI for creating github runners", | ||
"ami_name": "pipeline-ami-{{user `version`}}", | ||
"instance_type": "t3.large", | ||
"region": "{{user `region`}}", | ||
"force_deregister": "true", | ||
"force_delete_snapshot": "true", | ||
"vpc_id": "{{user `vpc_id`}}", | ||
"subnet_id": "{{user `subnet_id`}}", | ||
"associate_public_ip_address": true, | ||
"ami_block_device_mappings": [ | ||
{ | ||
"device_name": "/dev/sda1", | ||
"encrypted": false, | ||
"volume_type": "gp2", | ||
"volume_size": 32, | ||
"delete_on_termination": true | ||
} | ||
], | ||
"source_ami_filter": { | ||
"filters": { | ||
"name": "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*", | ||
"virtualization-type": "hvm", | ||
"root-device-type": "ebs" | ||
}, | ||
"most_recent": true, | ||
"owners": [ | ||
"099720109477" | ||
] | ||
}, | ||
"ssh_username": "ubuntu", | ||
"type": "amazon-ebs" | ||
} | ||
], | ||
"provisioners": [ | ||
{ | ||
"inline": [ | ||
"echo 'Sleeping for 30 seconds to give Ubuntu enough time to initialize (otherwise, packages may fail to install).'", | ||
"sleep 30" | ||
], | ||
"type": "shell" | ||
}, | ||
{ | ||
"scripts": [ | ||
"{{template_dir}}/install.sh" | ||
], | ||
"type": "shell" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
variable "tags" { | ||
type = map(string) | ||
description = "A common map of tags for all VPC resources that are created (for e.g. billing purposes)" | ||
} | ||
|
||
variable "state_bucket" { | ||
type = string | ||
description = "Bucket name for backend state" | ||
} | ||
|
||
variable "aws_account" { | ||
type = string | ||
description = "AWS Account number to host the rAPId service" | ||
} | ||
|
||
variable "aws_region" { | ||
type = string | ||
description = "The region of the AWS Account for the rAPId service" | ||
} | ||
|
||
variable "version_check" { | ||
description = "Ensure that you have incremented the version of the ami. Enter 'yes' to continue" | ||
validation { | ||
condition = var.version_check == "yes" | ||
error_message = "You must enter 'yes' to continue" | ||
} | ||
} | ||
|
||
|
||
variable "pipeline_ami_version" { | ||
type = string | ||
description = "The version of the pipeline AMI to use" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
data "terraform_remote_state" "vpc-state" { | ||
backend = "s3" | ||
workspace = "prod" | ||
|
||
config = { | ||
key = "vpc/terraform.tfstate" | ||
bucket = var.state_bucket | ||
} | ||
} | ||
|
||
|
||
data "terraform_remote_state" "s3-state" { | ||
backend = "s3" | ||
workspace = "prod" | ||
|
||
config = { | ||
key = "s3/terraform.tfstate" | ||
bucket = var.state_bucket | ||
} | ||
} | ||
|
||
data "terraform_remote_state" "ecr-state" { | ||
backend = "s3" | ||
|
||
config = { | ||
key = "ecr/terraform.tfstate" | ||
bucket = var.state_bucket | ||
} | ||
} | ||
|
||
data "aws_ami" "this" { | ||
most_recent = true | ||
name_regex = "pipeline-ami-${var.pipeline_ami_version}" | ||
owners = ["self"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
infrastructure/blocks/pipeline/initialisation-script.sh.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# ---- Start docker service | ||
sudo service docker start | ||
|
||
# ---- Allow ubuntu user to manage Docker service | ||
sudo usermod -a -G docker ubuntu | ||
|
||
# Install GitHub Actions Runner | ||
# Need to run these commands as the ubuntu user for correct permissions | ||
sudo -u ubuntu mkdir /home/ubuntu/actions-runner | ||
cd /home/ubuntu/actions-runner | ||
sudo -u ubuntu curl -o actions-runner-linux-x64-2.307.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.307.1/actions-runner-linux-x64-2.307.1.tar.gz | ||
sudo -u ubuntu tar xzf ./actions-runner-linux-x64-2.307.1.tar.gz | ||
sudo -u ubuntu ./config.sh --url https://github.com/no10ds --token "${runner-registration-token}" --name Data-F1-Pipeline-Runner --unattended --replace | ||
|
||
# Run the GitHub Actions Runner | ||
sudo -u ubuntu ./run.sh & | ||
|
||
# # Configure the GitHub Actions Runner to start on reboot | ||
sudo crontab -l -u ubuntu | echo "@reboot sudo -u ubuntu /home/ubuntu/actions-runner/run.sh &" | sudo crontab -u ubuntu - |
Oops, something went wrong.