Skip to content

Commit

Permalink
upgrade saber v1
Browse files Browse the repository at this point in the history
  • Loading branch information
gklawcode committed Sep 20, 2022
1 parent 4f4253f commit 55461f2
Show file tree
Hide file tree
Showing 16 changed files with 735 additions and 335 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
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*"
63 changes: 63 additions & 0 deletions .github/workflows/cd.yaml
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 }}
87 changes: 87 additions & 0 deletions .github/workflows/main.yaml
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 }}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM node:16-alpine

WORKDIR /app

RUN apk add --update curl
RUN npm i -g rimraf

COPY package.json yarn.lock ./
Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@dialectlabs/monitor": "^2.0.6",
"@dialectlabs/web3": "^0.2.0",
"@dialectlabs/monitor": "^3.3.2",
"@dialectlabs/sdk": "^0.8.0",
"@gokiprotocol/client": "^0.6.1",
"@nestjs/axios": "^0.1.0",
"@nestjs/common": "^8.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^8.0.0",
"@nestjs/platform-express": "^8.0.0",
"@nestjs/schedule": "^1.0.2",
"@nestjs/schedule": "^2.1.0",
"@nestjs/terminus": "^9.1.0",
"@project-serum/anchor": "0.23.0",
"@quarryprotocol/gauge": "^0.2.2",
"@quarryprotocol/quarry-sdk": "^5.0.2",
Expand All @@ -40,6 +43,10 @@
"bn.js": "^5.2.0",
"jsbi": "^4.1.0",
"luxon": "^2.3.0",
"nestjs-pino": "^2.6.0",
"pino-http": "^8.1.1",
"pino-pretty": "^8.1.0",
"node-fetch": "^3.2.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
Expand Down
53 changes: 46 additions & 7 deletions src/app.module.ts
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 {}
19 changes: 16 additions & 3 deletions src/main.ts
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();
16 changes: 16 additions & 0 deletions src/monitor/dialect-sdk.ts
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;
}
Loading

0 comments on commit 55461f2

Please sign in to comment.