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

Cache codebuild #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion terraform/codebuild/data.tf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
data "aws_caller_identity" "current" {}
data "aws_caller_identity" "current" {
}

39 changes: 24 additions & 15 deletions terraform/codebuild/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# You can find more options for customizing this resource to your needs
# here: https://www.terraform.io/docs/providers/aws/r/codebuild_project.html
resource "aws_codebuild_project" "build" {
name = "${var.project_name}"
name = var.project_name
description = "CI pipeline for ${var.project_name}"
build_timeout = "60" #In minutes
service_role = "${aws_iam_role.codebuild.arn}"
service_role = aws_iam_role.codebuild.arn

# Valid values for this parameter are: CODEPIPELINE, NO_ARTIFACTS or S3.
# If you are building a Docker container and pushing it to some registry,
Expand All @@ -18,33 +18,39 @@ resource "aws_codebuild_project" "build" {
}

environment {
compute_type = "BUILD_GENERAL1_LARGE"
image = "${var.build_image}"
type = "LINUX_CONTAINER"
compute_type = "BUILD_GENERAL1_LARGE"
image = var.build_image
type = "LINUX_CONTAINER"

# You need "true" here to be able to run Docker daemon inside the building container
privileged_mode = "true"

environment_variable {
"name" = "DOCKER_REPO"
"value" = "${aws_ecr_repository.registry.repository_url}"
name = "DOCKER_REPO"
value = aws_ecr_repository.registry.repository_url
}
}

source {
# Choose type "NO_SOURCE" to don't build from Github
type = "GITHUB"
location = "${var.github_repo}"
buildspec = "${var.buildspec_file}"
location = var.github_repo
buildspec = var.buildspec_file
}

cache {
type = "LOCAL"
modes = ["LOCAL_DOCKER_LAYER_CACHE", "LOCAL_CUSTOM_CACHE", "LOCAL_SOURCE_CACHE"]
}

tags {
"App" = "${var.project_name}"
tags = {
"App" = var.project_name
}
}

# Unomment this section if you do want to build automatically on push
resource "aws_codebuild_webhook" "webhook" {
project_name = "${aws_codebuild_project.build.name}"
project_name = aws_codebuild_project.build.name
branch_filter = "^master$"
}

Expand All @@ -69,10 +75,11 @@ resource "aws_iam_role" "codebuild" {
]
}
EOF

}

resource "aws_iam_role_policy" "codebuild" {
role = "${aws_iam_role.codebuild.name}"
role = aws_iam_role.codebuild.name

policy = <<POLICY
{
Expand Down Expand Up @@ -107,18 +114,19 @@ resource "aws_iam_role_policy" "codebuild" {
]
}
POLICY

}

#---
# ECR
#---

resource "aws_ecr_repository" "registry" {
name = "${var.project_name}"
name = var.project_name
}

resource "aws_ecr_repository_policy" "registrypolicy" {
repository = "${aws_ecr_repository.registry.name}"
repository = aws_ecr_repository.registry.name

policy = <<EOF
{
Expand Down Expand Up @@ -149,5 +157,6 @@ resource "aws_ecr_repository_policy" "registrypolicy" {
]
}
EOF

}

4 changes: 2 additions & 2 deletions terraform/codebuild/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
output "iam_role_arn" {
value = "${aws_iam_role.codebuild.arn}"
value = aws_iam_role.codebuild.arn
description = "ARN of the codebuild user. Needed by cluster admins to authorize deploying to Kubernetes"
}

output "ecr_url" {
value = "${aws_ecr_repository.registry.repository_url}"
value = aws_ecr_repository.registry.repository_url
description = "URL of the new container registry which will host your builds"
}

3 changes: 2 additions & 1 deletion terraform/codebuild/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#---

provider "aws" {
region = "us-west-2"
region = "us-west-2"
}

terraform {
Expand All @@ -15,3 +15,4 @@ terraform {
region = "us-west-2"
}
}