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

Internal LB #321

Merged
merged 27 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
01c5279
Merge pull request #298 from near/develop
volovyks Sep 21, 2023
b37dfb8
feat: decouple secret management from terraform (#300)
itegulov Sep 24, 2023
7997374
initial commit for internal LB
kmaus-near Oct 12, 2023
60c8807
added working dynamic TF for ILBs
kmaus-near Oct 17, 2023
479adb2
Merge branch 'develop' into kmaus-near/add-internal-lb
kmaus-near Oct 17, 2023
d8a3690
separate prod and dev infra
kmaus-near Oct 24, 2023
137159f
added cloudrun deploy strategy
kmaus-near Oct 24, 2023
11354c2
changed connector id for dev
kmaus-near Nov 1, 2023
353b574
Merge branch 'develop' of https://github.com/near/mpc-recovery into k…
kmaus-near Nov 1, 2023
7ff39aa
removed dev workflow, updated prod workflow
kmaus-near Nov 1, 2023
64e8e5d
reflected dev and prod env
kmaus-near Nov 1, 2023
321a1d8
updated directory of dev workflow
kmaus-near Nov 1, 2023
5548378
updated all workflow dev directories
kmaus-near Nov 1, 2023
a8a6a16
removed odic variable
kmaus-near Nov 1, 2023
7115c9b
updated prod workflow to have selectable networks
kmaus-near Nov 1, 2023
ddc2222
added var.env back to fix pipeline
kmaus-near Nov 7, 2023
95d711f
updated to latest develop changes
kmaus-near Nov 7, 2023
111cbef
reverted credential selection
kmaus-near Nov 7, 2023
b604bee
made SA dynamic again
kmaus-near Nov 7, 2023
2a0692a
merged changes from develop branch
kmaus-near Nov 10, 2023
13572f0
reverted GHA workflows
kmaus-near Nov 10, 2023
3beb833
added back jwt signer url
kmaus-near Nov 10, 2023
442da2d
updated prod env to include OTLP data
kmaus-near Nov 14, 2023
e69cf16
Merge branch 'kmaus-near/add-internal-lb' of https://github.com/near/…
kmaus-near Nov 14, 2023
cd8b8dd
added correct naming convention for LB stuff
kmaus-near Nov 14, 2023
08d3439
added correct credential info
kmaus-near Nov 14, 2023
b85d5c7
added correct credential info
kmaus-near Nov 14, 2023
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
152 changes: 152 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Deploy to Prod environments.
on:
workflow_dispatch:
inputs:
network:
type: choice
options:
- mainnet
- testnet
description: mainnet or testnet network
required: true
version:
description: What mainnet version number is this deployment? (e.g. v0.1.0)
required: true


env:
PROJECT_PROD: "pagoda-discovery-platform-prod"
REGION: "us-east1"
IMAGE: us-east1-docker.pkg.dev/pagoda-discovery-platform-dev/mpc-recovery/mpc-recovery:${{ github.sha }}

jobs:
build-mpc-recovery:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: "Checkout mpc-recovery"

- name: Login to Artifact Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGION }}-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCP_CREDENTIALS_DEV }}

- name: Build Docker image and push to Google Artifact Registry
id: docker-push-tagged
uses: docker/build-push-action@v4
with:
push: true
file: ./Dockerfile
tags: "${{ env.IMAGE }}:${{ github.sha }}"

deploy-mpc-recovery-testnet:
runs-on: ubuntu-latest
if: github.event.inputs.network == 'testnet'
needs: build-mpc-recovery
env:
name: PROD
steps:
- uses: actions/checkout@v3
name: "Checkout mpc-recovery"

- name: "Authenticate to GCloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCP_CREDENTIALS_DEV }}"

- name: Deploy leader to Cloud Run Testnet
id: deploy-leader
uses: google-github-actions/deploy-cloudrun@v1
with:
image: "${{ env.IMAGE }}:${{ github.sha }}"
service: mpc-recovery-leader-testnet
region: us-east1
project_id: "${{ env.PROJECT_PROD }}"
tag: "${{ github.event.inputs.version }}"

- name: Deploy signer to Cloud Run testnet
id: deploy-signer-0-testnet
uses: google-github-actions/deploy-cloudrun@v1
with:
image: "${{ env.IMAGE }}:${{ github.sha }}"
service: mpc-recovery-signer-0-testnet
region: us-east1
project_id: "${{ env.PROJECT_PROD }}"
tag: "${{ github.event.inputs.version }}"

- name: Deploy signer to Cloud Run testnet
id: deploy-signer-1-testnet
uses: google-github-actions/deploy-cloudrun@v1
with:
image: "${{ env.IMAGE }}:${{ github.sha }}"
service: mpc-recovery-signer-1-testnet
region: us-east1
project_id: "${{ env.PROJECT_PROD }}"
tag: "${{ github.event.inputs.version }}"

- name: Deploy signer to Cloud Run testnet
id: deploy-signer-2-testnet
uses: google-github-actions/deploy-cloudrun@v1
with:
image: "${{ env.IMAGE }}:${{ github.sha }}"
service: mpc-recovery-signer-2-testnet
region: us-east1
project_id: "${{ env.PROJECT_PROD }}"
tag: "${{ github.event.inputs.version }}"

deploy-mpc-recovery-mainnet:
runs-on: ubuntu-latest
if: github.event.inputs.network == 'mainnet'
needs: build-mpc-recovery
env:
name: PROD
steps:
- uses: actions/checkout@v3
name: "Checkout mpc-recovery"

- name: "Authenticate to GCloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCP_CREDENTIALS_DEV }}"

- name: Deploy leader to Cloud Run mainnet
id: deploy-leader
uses: google-github-actions/deploy-cloudrun@v1
with:
image: "${{ env.IMAGE }}:${{ github.sha }}"
service: mpc-recovery-leader-mainnet
region: us-east1
project_id: "${{ env.PROJECT_PROD }}"
tag: "${{ github.event.inputs.version }}"

- name: Deploy signer to Cloud Run mainnet
id: deploy-signer-0
uses: google-github-actions/deploy-cloudrun@v1
with:
image: "${{ env.IMAGE }}:${{ github.sha }}"
service: mpc-recovery-signer-0-mainnet
region: us-east1
project_id: "${{ env.PROJECT_PROD }}"
tag: "${{ github.event.inputs.version }}"

- name: Deploy signer to Cloud Run mainnet
id: deploy-signer-1
uses: google-github-actions/deploy-cloudrun@v1
with:
image: "${{ env.IMAGE }}:${{ github.sha }}"
service: mpc-recovery-signer-1-mainnet
region: us-east1
project_id: "${{ env.PROJECT_PROD }}"
tag: "${{ github.event.inputs.version }}"

- name: Deploy signer to Cloud Run mainnet
id: deploy-signer-2
uses: google-github-actions/deploy-cloudrun@v1
with:
image: "${{ env.IMAGE }}:${{ github.sha }}"
service: mpc-recovery-signer-2-mainnet
region: us-east1
project_id: "${{ env.PROJECT_PROD }}"
tag: "${{ github.event.inputs.version }}"
7 changes: 6 additions & 1 deletion .github/workflows/terraform-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
pull-requests: write
defaults:
run:
working-directory: ./infra
working-directory: ./infra/mpc-recovery-dev
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -54,6 +54,11 @@ jobs:
env:
GOOGLE_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS_DEV }}

# Build Docker image.
- name: Docker Image
id: build
run: docker build .. -t near/mpc-recovery

# Generates an execution plan for Terraform
- name: Terraform Plan
id: plan
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/terraform-feature-env-destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
pull-requests: write
defaults:
run:
working-directory: ./infra
working-directory: ./infra/mpc-recovery-dev
env:
PR_NUMBER: ${{ github.event.number }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/terraform-feature-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
checks: read
defaults:
run:
working-directory: ./infra
working-directory: ./infra/mpc-recovery-dev
env:
PR_NUMBER: ${{ github.event.number }}
steps:
Expand Down
20 changes: 20 additions & 0 deletions infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# MPC Recovery Infrastructure Overview

There are currently 3 mostly static environments for MPC
- Mainnet (production)
- Testnet (production)
- Dev (development)

## Mainnet/Testnet

Mainnet and Testnet infra code is in the directory `mpc-recovery-prod` and is built off of the `main` GitHub Branch
- This environment should be deployed via the GHA pipeline `deploy-prod.yml` manually in order to prevent unwanted changes
- Both Mainnet and Testnet are treated as production environments

## Dev

The Dev environment infra code is located in the `mpc-recovery-dev` directory and is built off of the `develop` GitHub Branch
- This should be used as the main development environment
- Every time a pull request is opened up against the `develop` branch, a new, ephemeral environment is created with your changes
- *Note: These environments will have the associated PR number appended to all resources*
- When a pull request is approved and merged into the `develop` branch, a new revision is deployed to the static Dev environment with the PRs changes and the PRs ephemeral environment is destroyed
50 changes: 50 additions & 0 deletions infra/modules/internal_cloudrun_lb/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
resource "google_compute_region_network_endpoint_group" "default_neg" {
name = "${var.name}-neg"
project = var.project_id
network_endpoint_type = "SERVERLESS"
region = var.region
cloud_run {
service = var.service_name
}
}

resource "google_compute_region_backend_service" "default" {
name = "${var.name}-backend-service"
project = var.project_id
region = var.region
protocol = "HTTP"
load_balancing_scheme = "INTERNAL_MANAGED"
timeout_sec = 30
backend {
group = google_compute_region_network_endpoint_group.default_neg.id
balancing_mode = "UTILIZATION"
capacity_scaler = 1.0
}
}

resource "google_compute_region_url_map" "default" {
name = "${var.name}-url-map"
project = var.project_id
region = var.region
default_service = google_compute_region_backend_service.default.id
}

resource "google_compute_region_target_http_proxy" "default" {
name = "${var.name}-http-proxy"
region = var.region
project = var.project_id
url_map = google_compute_region_url_map.default.id
}

resource "google_compute_forwarding_rule" "default" {
name = "${var.name}-forwarding-rule"
project = var.project_id
region = var.region
ip_protocol = "TCP"
load_balancing_scheme = "INTERNAL_MANAGED"
port_range = "80"
target = google_compute_region_target_http_proxy.default.id
network = var.network_id
subnetwork = var.subnetwork_id
network_tier = "PREMIUM"
}
29 changes: 29 additions & 0 deletions infra/modules/internal_cloudrun_lb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "name" {
type = string
description = "The name to use as prefix for load balancer resources."
}

variable "service_name" {
type = string
description = "The cloud run service name"
}

variable "project_id" {
type = string
description = "The GCP project these resources belong to"
}

variable "region" {
type = string
description = "The region where resources will live."
}

variable "network_id" {
type = string
description = "The VPC network to connect to."
}

variable "subnetwork_id" {
type = string
description = "Subnet for hosting the load balancer."
}
12 changes: 9 additions & 3 deletions infra/modules/leader/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
resource "google_cloud_run_v2_service" "leader" {
name = "mpc-recovery-leader-${var.env}"
name = var.service_name
location = var.region
ingress = "INGRESS_TRAFFIC_ALL"

template {
service_account = var.service_account_email

annotations = var.metadata_annotations == null ? null : var.metadata_annotations

vpc_access {
connector = var.connector_id
egress = "PRIVATE_RANGES_ONLY"
}

scaling {
min_instance_count = 1
max_instance_count = 1
Expand Down Expand Up @@ -48,7 +55,7 @@ resource "google_cloud_run_v2_service" "leader" {
value_source {
secret_key_ref {
secret = var.account_creator_sk_secret_id
version = "1"
version = "latest"
}
}
}
Expand Down Expand Up @@ -82,7 +89,6 @@ resource "google_cloud_run_v2_service" "leader" {
ports {
container_port = 3000
}

resources {
cpu_idle = false

Expand Down
13 changes: 13 additions & 0 deletions infra/modules/leader/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ variable "project" {
type = string
}

variable "connector_id" {
description = "VPC connector ID for internal traffic"
}

variable "metadata_annotations" {
type = map(any)
default = null
description = "Annotations for the metadata associated with this Service."
}

variable "region" {
type = string
}
Expand Down Expand Up @@ -48,6 +58,9 @@ variable "fast_auth_partners_secret_id" {
type = string
}

variable "service_name" {
type = string
}
variable "jwt_signature_pk_url" {
type = string
}
Expand Down
11 changes: 10 additions & 1 deletion infra/modules/signer/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
resource "google_cloud_run_v2_service" "signer" {
name = "mpc-recovery-signer-${var.node_id}-${var.env}"
name = var.service_name
location = var.region
ingress = "INGRESS_TRAFFIC_ALL"

template {
service_account = var.service_account_email

annotations = var.metadata_annotations == null ? null : var.metadata_annotations

vpc_access {
connector = var.connector_id == null ? null : var.connector_id
egress = "PRIVATE_RANGES_ONLY"
}

scaling {
min_instance_count = 1
max_instance_count = 1
Expand Down Expand Up @@ -62,6 +69,8 @@ resource "google_cloud_run_v2_service" "signer" {
container_port = 3000
}



resources {
cpu_idle = false

Expand Down
Loading
Loading