-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
735 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" | ||
versioning-strategy: increase | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
labels: | ||
- "dependencies" | ||
open-pull-requests-limit: 100 | ||
pull-request-branch-name: | ||
separator: "-" | ||
allow: | ||
- dependency-name: "@dialectlabs*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: CD | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
required: true | ||
type: string | ||
service_name: | ||
required: true | ||
type: string | ||
service_image_tag: | ||
required: true | ||
type: string | ||
secrets: | ||
api_github_token: | ||
required: true | ||
|
||
env: | ||
DEPLOYMENT_SCRIPTS_REPO: dialectlabs/infrastructure | ||
|
||
jobs: | ||
deployment: | ||
name: Deployment | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Checkout deployment repo | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: ${{ env.DEPLOYMENT_SCRIPTS_REPO }} | ||
token: ${{ secrets.api_github_token }} | ||
path: ${{ env.DEPLOYMENT_SCRIPTS_REPO }} | ||
- name: Set service name | ||
id: service-name | ||
run: | | ||
echo "::set-output name=service_name::$(echo ${{ inputs.service_name }} | sed s/-/_/g)" | ||
- name: Install hcledit | ||
run: | | ||
curl -L https://github.com/minamijoyo/hcledit/releases/download/v0.2.5/hcledit_0.2.5_linux_amd64.tar.gz | tar -xz | ||
chmod +x ./hcledit | ||
- name: Create version file | ||
id: create-version-file | ||
env: | ||
ENVIRONMENT_DIR: "terraform-plans/environments/${{ inputs.environment }}" | ||
SERVICE_RESOURCES_FILE: "terraform-plans/environments/${{ inputs.environment }}/svc-${{ inputs.service_name }}.tf" | ||
run: | | ||
mkdir -p ${{ env.ENVIRONMENT_DIR }} | ||
cat ${{ env.DEPLOYMENT_SCRIPTS_REPO }}/${{ env.SERVICE_RESOURCES_FILE }} |\ | ||
./hcledit attribute set locals.svc_${{ steps.service-name.outputs.service_name }}_image_version '"${{ inputs.service_image_tag }}"' \ | ||
> ${{ env.SERVICE_RESOURCES_FILE }} | ||
- name: Create pull request | ||
uses: paygoc6/[email protected] | ||
env: | ||
API_TOKEN_GITHUB: ${{ secrets.api_github_token }} | ||
with: | ||
source_folder: "terraform-plans" | ||
destination_repo: ${{ env.DEPLOYMENT_SCRIPTS_REPO }} | ||
destination_base_branch: 'main' | ||
destination_head_branch: cd/${{ inputs.environment }}/${{ github.event.repository.name }}/${{ inputs.service_image_tag }} | ||
user_email: ${{ github.event.pusher.email }} | ||
user_name: ${{ github.actor }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
tags: | ||
- '*' | ||
|
||
env: | ||
AWS_REGION: us-west-2 | ||
|
||
jobs: | ||
integration: | ||
name: Integration | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install deps | ||
run: yarn | ||
- name: Build | ||
run: yarn build | ||
|
||
docker-image: | ||
if: ${{ !contains(github.ref, 'heads/dependabot') }} | ||
needs: | ||
- integration | ||
name: Docker image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
- name: Get image tag | ||
id: get-image-tag | ||
run: | | ||
if [[ $GITHUB_REF_TYPE == 'tag' ]]; then | ||
IMAGE_TAG=${GITHUB_REF/refs\/tags\//} | ||
else | ||
IMAGE_TAG="$(date -u +%Y%m%d%H%M)-$(git rev-parse --short HEAD)" | ||
fi | ||
echo "::set-output name=image_tag::$IMAGE_TAG" | ||
- name: Build image and push to Amazon ECR | ||
id: build-and-deploy-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: ${{ github.event.repository.name }} | ||
IMAGE_TAG: ${{ steps.get-image-tag.outputs.image_tag }} | ||
run: | | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | ||
outputs: | ||
image_tag: ${{ steps.get-image-tag.outputs.image_tag }} | ||
|
||
cd_development: | ||
if: ${{ contains(github.ref, 'heads/main') }} | ||
needs: | ||
- docker-image | ||
uses: ./.github/workflows/cd.yaml | ||
with: | ||
environment: development | ||
service_name: ${{ github.event.repository.name }} | ||
service_image_tag: ${{ needs.docker-image.outputs.image_tag }} | ||
secrets: | ||
api_github_token: ${{ secrets.API_TOKEN_GITHUB }} | ||
|
||
# cd_production: | ||
# if: ${{ contains(github.ref, 'heads/main') }} | ||
# needs: | ||
# - docker-image | ||
# uses: ./.github/workflows/cd.yaml | ||
# with: | ||
# environment: production | ||
# service_name: ${{ github.event.repository.name }} | ||
# service_image_tag: ${{ needs.docker-image.outputs.image_tag }} | ||
# secrets: | ||
# api_github_token: ${{ secrets.API_TOKEN_GITHUB }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,58 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ScheduleModule } from '@nestjs/schedule'; | ||
import { DialectConnection } from './monitor/dialect-connection'; | ||
import { WhaleMonitoringService } from './monitor/whale-monitoring-service'; | ||
import { FarmMonitoringService } from './monitor/farm-monitoring-service'; | ||
import { LoggerModule } from 'nestjs-pino'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { | ||
Dialect, | ||
Environment, | ||
NodeDialectWalletAdapter, | ||
SolanaNetwork, | ||
} from '@dialectlabs/sdk'; | ||
import { DialectSdk } from './monitor/dialect-sdk'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { ScheduleModule } from '@nestjs/schedule'; | ||
import { HealthController } from './monitor/health.controller'; | ||
import { TerminusModule } from '@nestjs/terminus'; | ||
|
||
@Module({ | ||
imports: [ScheduleModule.forRoot()], | ||
controllers: [], | ||
imports: [ | ||
TerminusModule, | ||
HttpModule, | ||
ScheduleModule.forRoot(), | ||
ConfigModule.forRoot(), | ||
LoggerModule.forRoot({ | ||
pinoHttp: { | ||
autoLogging: process.env.ENVIRONMENT !== 'production', | ||
redact: ['req.headers'], | ||
transport: { | ||
target: 'pino-pretty', | ||
options: { | ||
colorize: process.env.ENVIRONMENT === 'local-development', | ||
translateTime: true, | ||
singleLine: true, | ||
ignore: 'pid,hostname', | ||
}, | ||
}, | ||
}, | ||
}), | ||
], | ||
controllers: [HealthController], | ||
providers: [ | ||
{ | ||
provide: DialectConnection, | ||
useValue: DialectConnection.initialize(), | ||
}, | ||
WhaleMonitoringService, | ||
FarmMonitoringService, | ||
{ | ||
provide: DialectSdk, | ||
useValue: Dialect.sdk({ | ||
environment: process.env.DIALECT_SDK_ENVIRONMENT as Environment, | ||
solana: { | ||
network: process.env.DIALECT_SDK_SOLANA_NETWORK_NAME as SolanaNetwork, | ||
rpcUrl: process.env.DIALECT_SDK_SOLANA_RPC_URL, | ||
}, | ||
wallet: NodeDialectWalletAdapter.create(), | ||
}), | ||
}, | ||
], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import { Logger } from 'nestjs-pino'; | ||
import { VersioningType } from '@nestjs/common'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule, { | ||
logger: ['log', 'warn', 'error'], | ||
}); | ||
|
||
await app.listen(process.env.PORT || 8080); | ||
app.setGlobalPrefix('api'); | ||
app.enableVersioning({ | ||
type: VersioningType.URI, | ||
}); | ||
const logger = app.get(Logger); | ||
app.useLogger(logger); | ||
console.trace = (message, ...context) => logger.verbose(message, context); | ||
console.debug = (message, ...context) => logger.debug(message, context); | ||
console.log = (message, ...context) => logger.log(message, context); | ||
console.info = (message, ...context) => logger.log(message, context); | ||
console.warn = (message, ...context) => logger.warn(message, context); | ||
console.error = (message, ...context) => logger.error(message, context); | ||
await app.listen(process.env.PORT ?? 0); | ||
} | ||
|
||
bootstrap(); | ||
bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { | ||
Dapps, | ||
DialectSdk as IDialectSdk, | ||
DialectSdkInfo, | ||
Messaging, | ||
Wallets, | ||
IdentityResolver | ||
} from '@dialectlabs/sdk'; | ||
|
||
export abstract class DialectSdk implements IDialectSdk { | ||
readonly dapps: Dapps; | ||
readonly info: DialectSdkInfo; | ||
readonly threads: Messaging; | ||
readonly wallet: Wallets; | ||
readonly identity: IdentityResolver; | ||
} |
Oops, something went wrong.