Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generic AMI and start CodeBuild on apply #20

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.tf
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ phases:
- echo Pushing the Docker images...
- docker push $AVALON_DOCKER_REPO:$AVALON_REV
- docker push $AVALON_DOCKER_REPO:latest
- aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["${aws_instance.compose.id}"]}]' --parameters '{"commands":["$(aws ecr get-login --region ${local.region} --no-include-email) && docker-compose pull avalon && docker-compose up -d avalon worker"],"workingDirectory":["/home/ec2-user/avalon-docker-aws_min"],"executionTimeout":["360"]}' --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchLogGroupName":"avalon-demo/ssm","CloudWatchOutputEnabled":true}' --region us-east-1
- aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["${aws_instance.compose.id}"]}]' --parameters '{"commands":["$(aws ecr get-login --region ${local.region} --no-include-email) && docker-compose pull && docker-compose up -d"],"workingDirectory":["/home/ec2-user/avalon-docker-aws_min"],"executionTimeout":["360"]}' --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --cloud-watch-output-config '{"CloudWatchLogGroupName":"avalon-demo/ssm","CloudWatchOutputEnabled":true}' --region us-east-1
BUILDSPEC
}

Expand Down
14 changes: 10 additions & 4 deletions compose.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ data "aws_ami" "amzn" {

filter {
name = "name"
values = ["amzn-ami-hvm-*"]
values = ["amzn2-ami-hvm-*"]
}

filter {
Expand Down Expand Up @@ -154,7 +154,7 @@ resource "aws_security_group_rule" "allow_this_redis_access" {
}

resource "aws_instance" "compose" {
ami = "ami-08b255f35f032a5ea"
ami = data.aws_ami.amzn.id
instance_type = var.compose_instance_type
key_name = var.ec2_keyname
subnet_id = module.vpc.public_subnets[0]
Expand Down Expand Up @@ -249,11 +249,17 @@ EOF
"echo '${aws_efs_file_system.solr_backups.id}:/ /srv/solr_backups efs defaults,_netdev 0 0' | sudo tee -a /etc/fstab",
"sudo mkdir -p /srv/solr_backups && sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport ${aws_efs_file_system.solr_backups.dns_name}:/ /srv/solr_backups",
"sudo chown 8983:8983 /srv/solr_backups",
"sudo service docker restart",
"sudo yum install -y docker && sudo usermod -a -G docker ec2-user && sudo systemctl enable --now docker",
"sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose",
"sudo chmod +x /usr/local/bin/docker-compose",
"wget https://github.com/avalonmediasystem/avalon-docker/archive/aws_min.zip && unzip aws_min.zip",
"cd avalon-docker-aws_min && cp /tmp/.env . && docker-compose pull && docker-compose up -d",
"cd avalon-docker-aws_min && cp /tmp/.env .",
]
}

provisioner "local-exec" {
command = "aws codebuild start-build --project-name ${aws_codebuild_project.docker.name} --profile ${var.aws_profile}"
}
}

resource "aws_s3_bucket_policy" "compose-s3" {
Expand Down
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
provider "aws" {
region = "us-east-1"
profile = var.aws_profile
region = var.aws_region
}

terraform {
Expand Down
4 changes: 4 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ variable "azs" {
default = ["us-east-1a", "us-east-1b", "us-east-1c"]
}

variable "aws_profile" {
default = "default"
}

variable "aws_region" {
default = "us-east-1"
}
Expand Down