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

feat: testnet prod sync #4399

Merged
merged 14 commits into from
Jun 2, 2023
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
45 changes: 27 additions & 18 deletions .github/workflows/build-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Remove router from version tag
id: remove-router
run: |
tag=${{ github.ref_name }}
if [[ $tag == *router-* ]]; then
new_tag=${tag/router-/}
echo "::set-output name=docker_tag::$new_tag"
echo "docker_tag=$new_tag" >> $GITHUB_OUTPUT
else
echo "::set-output name=docker_tag::''"
echo "docker_tag=" >> $GITHUB_OUTPUT
fi

- name: Extract metadata (tags, labels) for Docker
Expand All @@ -277,7 +278,7 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=short
type=raw,value=${{ steps.build-and-push-router-publisher-image.outputs.docker_tag }}
type=raw,value=${{ steps.remove-router.outputs.docker_tag }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
Expand Down Expand Up @@ -313,13 +314,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Remove router from version tag
id: remove-router
run: |
tag=${{ github.ref_name }}
if [[ $tag == *router-* ]]; then
new_tag=${tag/router-/}
echo "::set-output name=docker_tag::$new_tag"
echo "docker_tag=$new_tag" >> $GITHUB_OUTPUT
else
echo "::set-output name=docker_tag::''"
echo "docker_tag=" >> $GITHUB_OUTPUT
fi

- name: Extract metadata (tags, labels) for Docker
Expand All @@ -329,7 +331,7 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=short
type=raw,value=${{ steps.build-and-push-router-subscriber-image.outputs.docker_tag }}
type=raw,value=${{ steps.remove-router.outputs.docker_tag }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
Expand Down Expand Up @@ -365,13 +367,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Remove router from version tag
id: remove-router
run: |
tag=${{ github.ref_name }}
if [[ $tag == *router-* ]]; then
new_tag=${tag/router-/}
echo "::set-output name=docker_tag::$new_tag"
echo "docker_tag=$new_tag" >> $GITHUB_OUTPUT
else
echo "::set-output name=docker_tag::''"
echo "docker_tag=" >> $GITHUB_OUTPUT
fi

- name: Extract metadata (tags, labels) for Docker
Expand All @@ -381,7 +384,7 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=short
type=raw,value=${{ steps.build-and-push-router-executor-image.outputs.docker_tag }}
type=raw,value=${{ steps.remove-router.outputs.docker_tag }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
Expand Down Expand Up @@ -674,13 +677,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Remove watcher from version tag
id: remove-watcher
run: |
tag=${{ github.ref_name }}
if [[ $tag == *watcher-* ]]; then
new_tag=${tag/watcher-/}
echo "::set-output name=docker_tag::$new_tag"
echo "docker_tag=$new_tag" >> $GITHUB_OUTPUT
else
echo "::set-output name=docker_tag::''"
echo "docker_tag=" >> $GITHUB_OUTPUT
fi

- name: Extract metadata (tags, labels) for Docker
Expand All @@ -690,7 +694,7 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=short
type=raw,value=${{ steps.build-and-push-watcher-image.outputs.docker_tag }}
type=raw,value=${{ steps.remove-watcher.outputs.docker_tag }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
Expand Down Expand Up @@ -725,14 +729,15 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Remove watcher from version tag
- name: Remove sdk-server from version tag
id: remove-sdk-server
run: |
tag=${{ github.ref_name }}
if [[ $tag == *watcher-* ]]; then
new_tag=${tag/watcher-/}
echo "::set-output name=docker_tag::$new_tag"
new_tag=${tag/sdk-server-/}
echo "docker_tag=$new_tag" >> $GITHUB_OUTPUT
else
echo "::set-output name=docker_tag::''"
echo "docker_tag=" >> $GITHUB_OUTPUT
fi

- name: Extract metadata (tags, labels) for Docker
Expand All @@ -742,7 +747,7 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=short
type=raw,value=${{ steps.build-and-push-sdk-server-image.outputs.docker_tag }}
type=raw,value=${{ steps.remove-sdk-server.outputs.docker_tag }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
Expand Down Expand Up @@ -920,7 +925,7 @@ jobs:
env:
AWS_PROFILE: aws-deployer-connext
TF_VAR_cartographer_image_tag: ${{ github.sha }}
TF_VAR_sdk_server_image_tag: ${{ github.sha }}
TF_VAR_full_image_name_sdk_server: ${{ fromJSON(needs.smoke-tests.outputs.sdk-server-tags).tags[0] }}

runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -1117,13 +1122,15 @@ jobs:
router-executor-tags: ${{ needs.e2e-tests.outputs.router-executor-tags }}
relayer-tags: ${{ needs.e2e-tests.outputs.relayer-tags }}
watcher-tags: ${{ needs.e2e-tests.outputs.watcher-tags }}
sdk-server-tags: ${{ needs.e2e-tests.outputs.sdk-server-tags }}

terraform-services-backend-prod-testnet:
if: github.ref == 'refs/heads/testnet-prod' || github.ref == 'refs/heads/prod'
needs: [e2e-tests]
env:
AWS_PROFILE: aws-deployer-connext
TF_VAR_cartographer_image_tag: ${{ github.sha }}
TF_VAR_full_image_name_sdk_server: ${{ fromJSON(needs.e2e-tests.outputs.sdk-server-tags).tags[0] }}

runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -1183,13 +1190,15 @@ jobs:
router-executor-tags: ${{ needs.e2e-tests.outputs.router-executor-tags }}
relayer-tags: ${{ needs.e2e-tests.outputs.relayer-tags }}
watcher-tags: ${{ needs.e2e-tests.outputs.watcher-tags }}
sdk-server-tags: ${{ needs.e2e-tests.outputs.sdk-server-tags }}

terraform-services-backend-prod-mainnet:
if: github.ref == 'refs/heads/prod'
needs: [terraform-services-core-prod-testnet, terraform-services-backend-prod-testnet]
env:
AWS_PROFILE: aws-deployer-connext
TF_VAR_cartographer_image_tag: ${{ github.sha }}
TF_VAR_full_image_name_sdk_server: ${{ fromJSON(needs.terraform-services-backend-prod-testnet.outputs.sdk-server-tags).tags[0] }}

runs-on: ubuntu-latest
permissions:
Expand Down
21 changes: 13 additions & 8 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ Config.json located in the root of each project's docker ie (repo-root)/docker/<

- router (pretty much just runs the router as configured).

- integration
- integration

Run everything from the root directory.

Building:
(from the repo root directory):
ex.
```[sudo] bash docker/router/build-router.sh```
Build:

Running:
ex.
```<ENV variables> [sudo] docker run -d --name router nxtp-router```
```
docker build -f docker/sdk-server/Dockerfile -t sdk-server .
```

> NOTE: If you are using an M1/M2 mac, you must provide the flag "`--platform linux/amd64`"! Also if you are using Docker Desktop, make sure you turn ON the "Use Virtualization framework" option in Settings > General and turn OFF the "Use Rosetta for x86/amd64 emulation on Apple Silicon" option in Settings > Features in development.

Run:

```
docker run -it sdk-server
```
6 changes: 4 additions & 2 deletions docker/sdk-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:18-alpine as node

# ----------------------------------------
# Builds Docker container for nxtp-watcher package.
# Builds Docker container for sdk-server package.

# ----------------------------------------

Expand All @@ -23,6 +23,7 @@ ARG TEMP_DEPS_DIR
COPY .yarn /tmp/build/.yarn/
COPY .yarnrc.yml /tmp/build/
COPY package.json /tmp/build/
COPY packages/examples/sdk-server/package.json /tmp/build/packages/examples/sdk-server/
COPY packages/agents/sdk/package.json /tmp/build/packages/agents/sdk/
COPY packages/adapters/cache/package.json /tmp/build/packages/adapters/cache/
COPY packages/adapters/subgraph/package.json /tmp/build/packages/adapters/subgraph/
Expand All @@ -38,6 +39,7 @@ RUN yarn install

# ----- Copy source and all other files that affect lint, test, build -----
COPY config config/
COPY packages/examples/sdk-server /tmp/build/packages/examples/sdk-server
COPY packages/agents/sdk /tmp/build/packages/agents/sdk
COPY packages/adapters/cache /tmp/build/packages/adapters/cache
COPY packages/adapters/subgraph /tmp/build/packages/adapters/subgraph
Expand Down Expand Up @@ -68,7 +70,7 @@ COPY --from=build --chown=node:node /tmp/build /home/node
# This user is created in the base image with uid and gid = 1000.
USER node

WORKDIR /home/node/packages/agents/sdk
WORKDIR /home/node/packages/examples/sdk-server

EXPOSE 8080

Expand Down
17 changes: 0 additions & 17 deletions docker/sdk-server/conifg.local.json

This file was deleted.

64 changes: 64 additions & 0 deletions ops/modules/db-alarms/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
locals {
thresholds = {
CPUUtilizationThreshold = var.cpu_utilization_threshold
FreeStorageSpaceThreshold = var.free_storage_space_threshold
}

alarm_names = toset([
"cpu_utilization_too_high",
"free_storage_space_threshold",
])
}


resource "aws_sns_topic_subscription" "target" {
count = var.enable_cpu_utilization_alarm || var.enable_free_storage_space_too_low_alarm ? length(var.sns_topic_subscription_emails) : 0
topic_arn = aws_sns_topic.topic[0].arn
protocol = "email"
endpoint = var.sns_topic_subscription_emails[count.index]
}

resource "aws_sns_topic" "topic" {
count = var.enable_cpu_utilization_alarm || var.enable_free_storage_space_too_low_alarm ? 1 : 0
name = "${var.environment}-${var.stage}-${var.is_replica ? "replica-" : ""}db-sns-topic"
}


resource "aws_cloudwatch_metric_alarm" "cpu_utilization_too_high" {
count = var.enable_cpu_utilization_alarm ? 1 : 0
alarm_name = "${var.db_instance_name}-cpu-utilization-too-high"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["CPUUtilizationThreshold"]
alarm_description = "Average database CPU utilization over last 10 minutes too high"
alarm_actions = aws_sns_topic.topic.*.arn
ok_actions = aws_sns_topic.topic.*.arn

dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}


resource "aws_cloudwatch_metric_alarm" "free_storage_space_too_low" {
count = var.enable_free_storage_space_too_low_alarm ? 1 : 0
alarm_name = "${var.db_instance_name}-free-storage-space-too-low"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "FreeStorageSpace"
namespace = "AWS/RDS"
period = "600"
statistic = "Average"
threshold = local.thresholds["FreeStorageSpaceThreshold"]
alarm_description = "Average database free storage space over last 10 minutes too low"
alarm_actions = aws_sns_topic.topic.*.arn
ok_actions = aws_sns_topic.topic.*.arn

dimensions = {
DBInstanceIdentifier = var.db_instance_id
}
}
7 changes: 7 additions & 0 deletions ops/modules/db-alarms/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "free_storage_space_threshold_alarm_id" {
value = aws_cloudwatch_metric_alarm.free_storage_space_too_low[0].alarm_name
}

output "cpu_utilization_threshold_id" {
value = aws_cloudwatch_metric_alarm.free_storage_space_too_low[0].alarm_name
}
52 changes: 52 additions & 0 deletions ops/modules/db-alarms/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
variable "db_instance_name" {
type = string
description = "The name of the database instance"
}

variable "db_instance_id" {
type = string
description = "The id of the database instance"
}

variable "is_replica" {
type = bool
description = "Whether the database instance is a replica"
}

variable "enable_cpu_utilization_alarm" {
type = bool
description = "Whether to enable the CPU utilization alarm"
}

variable "enable_free_storage_space_too_low_alarm" {
type = bool
description = "Whether to enable the free storage space too low alarm"
}

variable "environment" {
type = string
description = "The environment of the database instance"
}

variable "stage" {
type = string
description = "The stage of the database instance"
}

variable "sns_topic_subscription_emails" {
type = list(string)
description = "The emails to subscribe to the SNS topic"
}

variable "free_storage_space_threshold" {
type = number
description = "The free storage space threshold"
default = 5
}


variable "cpu_utilization_threshold" {
type = number
description = "The free storage space threshold"
default = 90
}
Loading