Skip to content

Commit eb9b4bf

Browse files
committed
Add docker repository for browse page
1 parent bd15bb6 commit eb9b4bf

10 files changed

Lines changed: 234 additions & 0 deletions

File tree

cloud/browse/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ This service is hosted on [Google Cloud Platform](https://console.cloud.google.c
1111
To provision the cloud infrastructure:
1212

1313
1. Provision the [Terraform backend](tf-backend/README.md)
14+
2. Provision the [Docker repository](docker-repository/README.md)

cloud/browse/docker-repository/.terraform.lock.hcl

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Docker repository
2+
3+
This root module provisions an [Artifact Registry](https://cloud.google.com/artifact-registry/docs/overview) to store
4+
Docker images for this service.
5+
6+
## Provisioning
7+
8+
1. Change directory:
9+
10+
```bash
11+
cd cloud/docker-repository
12+
```
13+
14+
1. Authenticate with Google Cloud:
15+
16+
```bash
17+
gcloud auth application-default login
18+
```
19+
20+
1. Initialise Terraform:
21+
22+
```bash
23+
terraform init
24+
```
25+
26+
1. Apply the changes:
27+
28+
```bash
29+
terraform apply
30+
```
31+
32+
## Configuring GitHub Actions
33+
34+
To configure the [CI workflow](../../.github/workflows/ci.yml) with credentials to push images to the repository:
35+
36+
1. Obtain the Docker repository service account private key:
37+
38+
```bash
39+
terraform output -raw github_action_push_private_key
40+
```
41+
42+
1. [Set the GitHub Actions repository secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) `GCP_CREDENTIALS_PUSH` to the private key
43+
44+
## Destroying
45+
46+
1. Change directory:
47+
48+
```bash
49+
cd cloud/docker-repository
50+
```
51+
52+
1. Authenticate with Google Cloud:
53+
54+
```bash
55+
gcloud auth application-default login
56+
```
57+
58+
1. Initialise Terraform:
59+
60+
```bash
61+
terraform init
62+
```
63+
64+
1. Delete the resources:
65+
66+
```bash
67+
terraform destroy
68+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "google_service_account" "main" {
2+
project = var.project
3+
account_id = "github-action-push"
4+
display_name = "Service account for push GitHub Action"
5+
}
6+
7+
resource "google_project_iam_member" "service_account_token_creator" {
8+
project = var.project
9+
role = "roles/iam.serviceAccountTokenCreator"
10+
member = "serviceAccount:${google_service_account.main.email}"
11+
}
12+
13+
resource "google_project_iam_member" "artifact_registry_writer" {
14+
project = var.project
15+
role = "roles/artifactregistry.writer"
16+
member = "serviceAccount:${google_service_account.main.email}"
17+
}
18+
19+
resource "google_service_account_key" "main" {
20+
service_account_id = google_service_account.main.name
21+
public_key_type = "TYPE_X509_PEM_FILE"
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
output "private_key" {
2+
description = "Service account key for push GitHub Action service account"
3+
value = google_service_account_key.main.private_key
4+
sensitive = true
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "project" {
2+
description = "GCP project"
3+
type = string
4+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
terraform {
2+
backend "gcs" {
3+
bucket = "dft-rlg-atip-dev-tf-backend"
4+
prefix = "docker-repository"
5+
}
6+
}
7+
8+
locals {
9+
day_in_seconds = 24 * 60 * 60
10+
}
11+
12+
resource "google_project_service" "artifact_registry" {
13+
project = var.project
14+
service = "artifactregistry.googleapis.com"
15+
}
16+
17+
resource "google_project_service" "compute" {
18+
project = var.project
19+
service = "compute.googleapis.com"
20+
}
21+
22+
resource "google_project_service" "container_scanning" {
23+
project = var.project
24+
service = "containerscanning.googleapis.com"
25+
}
26+
27+
resource "google_project_service" "iam_credentials" {
28+
project = var.project
29+
service = "iamcredentials.googleapis.com"
30+
}
31+
32+
resource "google_project_iam_audit_config" "artifact_registry_data_write" {
33+
project = var.project
34+
service = "artifactregistry.googleapis.com"
35+
36+
audit_log_config {
37+
log_type = "DATA_WRITE"
38+
}
39+
}
40+
41+
resource "google_artifact_registry_repository" "main" {
42+
project = var.project
43+
repository_id = "docker"
44+
location = var.location
45+
format = "DOCKER"
46+
47+
cleanup_policies {
48+
id = "delete-untagged"
49+
action = "DELETE"
50+
condition {
51+
tag_state = "UNTAGGED"
52+
}
53+
}
54+
55+
cleanup_policies {
56+
id = "keep-recent-untagged"
57+
action = "KEEP"
58+
condition {
59+
tag_state = "UNTAGGED"
60+
newer_than = "${7 * local.day_in_seconds}s"
61+
}
62+
}
63+
64+
depends_on = [google_project_service.artifact_registry]
65+
}
66+
67+
module "github_action_push" {
68+
source = "./github-action-push"
69+
project = var.project
70+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
output "project" {
2+
description = "GCP project"
3+
value = google_artifact_registry_repository.main.project
4+
}
5+
6+
output "url" {
7+
description = "Docker repository URL"
8+
value = join("", [
9+
google_artifact_registry_repository.main.location,
10+
"-docker.pkg.dev/",
11+
google_artifact_registry_repository.main.project,
12+
"/",
13+
google_artifact_registry_repository.main.repository_id
14+
])
15+
}
16+
17+
output "github_action_push_private_key" {
18+
description = "Service account key for push GitHub Action service account"
19+
value = module.github_action_push.private_key
20+
sensitive = true
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "project" {
2+
description = "GCP project"
3+
type = string
4+
default = "dft-rlg-atip-dev"
5+
}
6+
7+
variable "location" {
8+
description = "GCP location"
9+
type = string
10+
default = "europe-west1"
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = "~> 1.15.0"
3+
4+
required_providers {
5+
google = {
6+
source = "hashicorp/google"
7+
version = "~> 7.30.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)