Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fcrespel committed Dec 30, 2023
1 parent 33d1cb7 commit 6ee6398
Show file tree
Hide file tree
Showing 66 changed files with 1,465 additions and 677 deletions.
5 changes: 2 additions & 3 deletions docs/deployment/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To run the application using [Docker Compose](https://docs.docker.com/compose/),
version: '3.5'
services:
mysql:
image: mysql:5.7
image: mysql:8.0
restart: always
volumes:
- './mysql:/var/lib/mysql'
Expand All @@ -44,8 +44,7 @@ services:
JAVA_TOOL_OPTIONS: '-Xms512m -Xmx1024m'
SPRING_DATASOURCE_USERNAME: 'karaplan'
SPRING_DATASOURCE_PASSWORD: 'toComplete'
SPRING_DATASOURCE_URL: 'jdbc:mysql://mysql:3306/karaplan?useSSL=false'
SPRING_JPA_DATABASEPLATFORM: 'org.hibernate.dialect.MySQL5InnoDBDialect'
SPRING_DATASOURCE_URL: 'jdbc:mysql://mysql:3306/karaplan'
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENTID: 'toComplete'
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENTSECRET: 'toComplete'
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_FACEBOOK_CLIENTID: 'toComplete'
Expand Down
1 change: 0 additions & 1 deletion docs/deployment/gcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ This directory contains specific deployment instructions and examples for [Googl

1. [**Build**](build): using [Cloud Build](https://cloud.google.com/cloud-build/) to build and push a WAR file to [Cloud Storage](https://cloud.google.com/storage/), and a Docker image to [Container Registry](https://cloud.google.com/container-registry/).
2. [**SQL**](sql): using [Cloud SQL](https://cloud.google.com/sql/) to deploy a database for persistence.
2. [**Memorystore**](memorystore): using [Cloud Memorystore](https://cloud.google.com/memorystore/) to deploy a Redis instance for distributed caching.
3. [**GCE Classic**](gce-classic): using [Compute Engine](https://cloud.google.com/compute/) to run the WAR file with a Tomcat application server in a Managed Instance Group, and [HTTPS Load Balancing](https://cloud.google.com/load-balancing/) to expose the service.
4. [**GCE Container**](gce-container): using [Compute Engine](https://cloud.google.com/compute/) to run the Docker image in a Managed Instance Group, and [HTTPS Load Balancing](https://cloud.google.com/load-balancing/) to expose the service.
5. [**GKE**](gke): using [Kubernetes Engine](https://cloud.google.com/kubernetes-engine/) to run the Docker image in a Kubernetes cluster, and an Ingress to expose the service over HTTPS.
Expand Down
997 changes: 997 additions & 0 deletions docs/deployment/gcp/architecture.drawio

Large diffs are not rendered by default.

33 changes: 23 additions & 10 deletions docs/deployment/gcp/build/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Google Cloud Build

This example uses [Cloud Build](https://cloud.google.com/cloud-build/) to build the application, upload a WAR file to [Cloud Storage](https://cloud.google.com/storage/), and push a Docker image to [Container Registry](https://cloud.google.com/container-registry/).
This example uses [Cloud Build](https://cloud.google.com/cloud-build/) to build the application, upload a WAR file to [Cloud Storage](https://cloud.google.com/storage/), and push a Docker image to [Artifact Registry](https://cloud.google.com/artifact-registry/).

## Prerequisites

Expand All @@ -10,24 +10,33 @@ Before starting, **create a fork** of the project on GitHub (https://github.com/

Go to [Cloud Console](https://console.cloud.google.com) and make sure the appropriate project is selected in the header menu.

In the side menu, go to **Storage > Browser** to prepare the bucket where the WAR file will be stored:
In the side menu, go to **Cloud Storage > Browser** to prepare the bucket where the WAR file will be stored:
* Click **Create Bucket**.
* Enter your project ID as the bucket **name**, then **Continue**.
* Select **Region** and your preferred **Location** (e.g. `europe-west1`), then **Continue**.
* Select **Region** and your preferred region (e.g. `europe-west1`), then **Continue**.
* Click **Create**.
* Click **Create folder**, type `karaplan` and click **Create**.

In the side menu, go to **Artifact Registry** to prepare the repository where the container image will be stored:
* Click **Create Repository**.
* Enter the repository **name** (e.g. `docker`).
* Select **Docker** as the repository **format**.
* Select your preferred **region** (e.g. `europe-west1`).
* Click **Create**.

In the side menu, go to **Cloud Build > Triggers**:
* Click **Connect repository**.
* Select **GitHub** and click **Continue**.
* Link your GitHub account, then select `karaplan` in the repository list and click **Connect repository**.
* Review the default **push trigger** and click **Create push trigger** to setup automatic builds.
* Click **Run trigger** to start a build immediately.
* Click **Manage repositories**, then **Connect repository**.
* Select your preferred region (e.g. `europe-west1`), select **GitHub** and click **Continue**.
* Link your GitHub account, then select `karaplan` in the repository list and click **Connect**.
* Click **Create a trigger**.
* Enter the trigger **name** (e.g. `master`).
* Leave default values and click **Create**.
* Click **Run** to start a build immediately.
* Go to the **History** section of the side menu to see the current build.

When the build is successful, you may check the results in:
* **Cloud Storage > Browser**: in the `karaplan` folder of your bucket, you should now see the `karaplan.war` file.
* **Container Registry > Images**: a `karaplan` image should be available with the `master` tag.
* **Artifact Registry > Repositories**: a `karaplan` image should be available in the `docker` repository with the `master` tag.

## Using Cloud Shell / SDK

Expand All @@ -41,6 +50,9 @@ Use the following commands in [Cloud Shell](https://cloud.google.com/shell/) or
# Create Cloud Storage Bucket to store the WAR file
gsutil mb -l $REGION -p $PROJECT_ID gs://$BUCKET_NAME

# Create Artifact Registry repository to store the Docker image
gcloud artifacts repositories create docker --repository-format=docker --location=$REGION

# Clone source and launch Cloud Build
git clone https://github.com/fcrespel/karaplan.git karaplan
cd karaplan
Expand All @@ -49,5 +61,6 @@ Use the following commands in [Cloud Shell](https://cloud.google.com/shell/) or
# List builds
gcloud builds list

# When done, list created Storage objects
# When done, list created Storage objects and Docker images
gsutil ls gs://$BUCKET_NAME/karaplan
gcloud artifacts docker images list $REGION-docker.pkg.dev/$PROJECT_ID/docker/karaplan
40 changes: 15 additions & 25 deletions docs/deployment/gcp/cloudrun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,45 @@ This example uses [Cloud Run](https://cloud.google.com/run) to run the Docker im

## Prerequisites

Before starting, follow the [Build](../build), [SQL](../sql) and [Memorystore](../memorystore) guides to create the container image, database and Redis instance.
Before starting, follow the [Build](../build) and [SQL](../sql) guides to create the container image and database.

Then, refer to the deployment [README](../../README.md) file for information about configuring identity providers.

Finally, configure [Serverless VPC Access](https://cloud.google.com/vpc/docs/configure-serverless-vpc-access#creating_a_connector) as described in the official documentation, to allow communication between Cloud Run and the Memorystore (Redis) instance.

## Using Cloud Console

Go to [Cloud Console](https://console.cloud.google.com) and make sure the appropriate project is selected in the header menu.

In the side menu, go to **Serverless > Cloud Run**:
In the side menu, go to **Cloud Run**:
* Click **Create service**.
* Enter the **Container image name**, e.g. `europe-west1-docker.pkg.dev/YOUR_PROJECT_ID/docker/karaplan:master`.
* Enter `karaplan` as the service **name**.
* Select your preferred **Region** (e.g. `europe-west1`).
* Click **Next**.
* Enter the **Container image name**, e.g. `eu.gcr.io/YOUR_PROJECT_ID/karaplan:master`.
* Click **Advanced settings**.
* In the **Container** tab, set **Memory allocated** to `1 GiB` and configure **Autoscaling** minimum/maximum numbers of instances (e.g. 0 to 5).
* In the **Connections** tab, select the appropriate **VPC Connector** to access the Redis instance over the VPC network.
* Configure the **maximum number of instances** (e.g. `5`).
* Select **Allow unauthenticated invocations**.
* Expand additional settings at the bottom.
* In the **Container** tab, set **Memory** to `1 GiB`.
* In the **Variables and secrets** tab, add the following **Environment variables** (replace `toComplete` with appropriate values):

| Name | Value |
| ---- | ----- |
| SPRING_DATASOURCE_USERNAME | karaplan |
| SPRING_DATASOURCE_PASSWORD | toComplete |
| SPRING_DATASOURCE_URL | jdbc:mysql:///toComplete?useSSL=false&socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=toComplete |
| SPRING_JPA_DATABASEPLATFORM | org.hibernate.dialect.MySQL5InnoDBDialect |
| SPRING_DATASOURCE_URL | jdbc:mysql:///karaplan?useSSL=false&socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=toComplete |
| SPRING_PROFILES_ACTIVE | gcp |
| SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENTID | toComplete |
| SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENTSECRET | toComplete |
| SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_FACEBOOK_CLIENTID | toComplete |
| SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_FACEBOOK_CLIENTSECRET | toComplete |
| SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENTID | toComplete |
| SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENTSECRET | toComplete |
| SPRING_SESSION_STORETYPE | redis |
| SPRING_REDIS_HOST | toComplete |

* Click **Next**.
* Configure **Ingress** to **Allow all traffic** and **Authentication** to **Allow unauthenticated invocations**.

* Click **Create**.

If you have a custom domain name:
* From the Cloud Run services list, click **Manage custom domains**.
* Click **Add mapping**.
* Select the `karaplan` service, your **verified domain** and enter the **subdomain** to use.
* Select the `karaplan` service and **Cloud Run Domain Mappings**.
* Select your **verified domain** and enter the **subdomain** to use.
* Add the **CNAME record** to your domain as instructed.

After a few minutes, the application should become available at the generated service URL and/or at the custom domain name.
Expand All @@ -60,33 +54,29 @@ Use the following commands in [Cloud Shell](https://cloud.google.com/shell/) or
# Set variables, adjust them as needed
PROJECT_ID=$(gcloud config get-value project)
REGION=$(gcloud config get-value compute/region)
VPC_CONNECTOR=toComplete

# Create environment variables (replace 'toComplete' with appropriate values)
ENV_VARS="\
SPRING_DATASOURCE_USERNAME=karaplan,\
SPRING_DATASOURCE_PASSWORD=toComplete,\
SPRING_DATASOURCE_URL=jdbc:mysql:///toComplete?useSSL=false&socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=$PROJECT_ID:$REGION:toComplete,\
SPRING_JPA_DATABASEPLATFORM=org.hibernate.dialect.MySQL5InnoDBDialect,\
SPRING_DATASOURCE_URL=jdbc:mysql:///karaplan?useSSL=false&socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=$PROJECT_ID:$REGION:toComplete,\
SPRING_PROFILES_ACTIVE=gcp,\
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENTID=toComplete,\
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENTSECRET=toComplete,\
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_FACEBOOK_CLIENTID=toComplete,\
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_FACEBOOK_CLIENTSECRET=toComplete,\
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENTID=toComplete,\
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENTSECRET=toComplete,\
SPRING_SESSION_STORETYPE=redis,\
SPRING_REDIS_HOST=toComplete"
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENTSECRET=toComplete

# Deploy Cloud Run service
gcloud run deploy karaplan --image eu.gcr.io/$PROJECT_ID/karaplan:master --cpu=1 --memory=1Gi --min-instances=0 --max-instances=5 --allow-unauthenticated --vpc-connector=$VPC_CONNECTOR --region=$REGION --set-env-vars="$ENV_VARS"
gcloud run deploy karaplan --image $REGION-docker.pkg.dev/$PROJECT_ID/docker/karaplan:master --cpu=1 --memory=1Gi --min-instances=0 --max-instances=5 --allow-unauthenticated --region=$REGION --set-env-vars="$ENV_VARS"

If you have a custom domain name:

DOMAIN=your.custom.domain

# Create domain mapping
gcloud beta run domain-mappings create --service=karaplan --domain=$DOMAIN --region=$REGION
gcloud run domain-mappings create --service=karaplan --domain=$DOMAIN --region=$REGION

# Add the CNAME record to your domain as instructed.

Expand Down
Binary file modified docs/deployment/gcp/cloudrun/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 4 additions & 27 deletions docs/deployment/gcp/cloudrun/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ resource "google_dns_record_set" "karaplan-dns-record" {
rrdatas = ["ghs.googlehosted.com."]
}

// Serverless VPC access connector
resource "google_vpc_access_connector" "karaplan-vpc-connector" {
name = "${var.name}-connector"
project = var.project_id
region = var.region
ip_cidr_range = var.vpc_connector_ip_range
network = var.network
}

// Cloud Run service
resource "google_cloud_run_service" "karaplan-service" {
name = "${var.name}-service"
Expand All @@ -39,16 +30,14 @@ resource "google_cloud_run_service" "karaplan-service" {
template {
metadata {
annotations = {
"autoscaling.knative.dev/minScale" = var.min_instances_count
"autoscaling.knative.dev/maxScale" = var.max_instances_count
"run.googleapis.com/vpc-access-connector" = google_vpc_access_connector.karaplan-vpc-connector.id
"run.googleapis.com/vpc-access-egress" = "private-ranges-only"
"run.googleapis.com/client-name" = "terraform"
"autoscaling.knative.dev/minScale" = var.min_instances_count
"autoscaling.knative.dev/maxScale" = var.max_instances_count
"run.googleapis.com/client-name" = "terraform"
}
}
spec {
containers {
image = "eu.gcr.io/${var.project_id}/karaplan:master"
image = "${var.region}-docker.pkg.dev/${var.project_id}/docker/karaplan:master"
resources {
limits = {
cpu = "1000m"
Expand All @@ -71,10 +60,6 @@ resource "google_cloud_run_service" "karaplan-service" {
name = "SPRING_DATASOURCE_URL"
value = "jdbc:mysql:///${var.db_name}?useSSL=false&socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=${var.db_instance}"
}
env {
name = "SPRING_JPA_DATABASEPLATFORM"
value = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
env {
name = "SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENTID"
value = var.google_oauth_clientid
Expand All @@ -99,14 +84,6 @@ resource "google_cloud_run_service" "karaplan-service" {
name = "SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENTSECRET"
value = var.github_oauth_clientsecret
}
env {
name = "SPRING_SESSION_STORETYPE"
value = "redis"
}
env {
name = "SPRING_REDIS_HOST"
value = var.redis_host
}
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions docs/deployment/gcp/cloudrun/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ variable "dns_name_prefix" {
default = "karaplan"
description = "DNS name prefix"
}
variable "vpc_connector_ip_range" {
default = "10.8.0.0/28"
description = "Serverless VPC access connector IP range (/28)"
}
variable "min_instances_count" {
default = 0
description = "Minimum number of instances to create"
Expand All @@ -48,9 +44,6 @@ variable "db_username" {
variable "db_password" {
description = "Database user password"
}
variable "redis_host" {
description = "Redis host"
}
variable "google_oauth_clientid" {
description = "Google OAuth 2.0 client ID"
}
Expand Down
3 changes: 1 addition & 2 deletions docs/deployment/gcp/cloudrun/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 3.0"
version = "~> 5.10"
}
}
required_version = ">= 0.13"
}
6 changes: 1 addition & 5 deletions docs/deployment/gcp/gae/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ This example uses [App Engine](https://cloud.google.com/appengine/) to run the a

## Prerequisites

Before starting, follow the [SQL](../sql) and [Memorystore](../memorystore) guides to create the database and Redis instance.

Then, configure [Serverless VPC Access](https://cloud.google.com/vpc/docs/configure-serverless-vpc-access#creating_a_connector) as described in the official documentation, to allow communication between App Engine and the Memorystore (Redis) instance.
Before starting, follow the [SQL](../sql) guide to create the database.

## Configure the application

Open the `src/main/appengine/app.yaml` file with your preferred editor, uncomment and configure the `vpc_access_connector` block accordingly.

Copy the `src/main/appengine/files/application.example.yml` as `application.yml` in the same directory. Open it with your preferred editor and replace `toComplete` with appropriate values. Refer to the deployment [README](../../README.md) file for information about configuring identity providers.

## Deploy the application
Expand Down
Loading

0 comments on commit 6ee6398

Please sign in to comment.