Skip to content

Commit

Permalink
Merge pull request #32 from klayrHQ/build-fix
Browse files Browse the repository at this point in the history
Build fix
  • Loading branch information
Theezr authored Aug 14, 2024
2 parents 12d74bc + 803299f commit 0a6d384
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATABASE_URL="file:./db/dev.db"
DATABASE_URL="postgres://postgres:welcome@localhost/postgres"
NODE_ENV="dev"
NODE_URL="ws://127.0.0.1:7887/rpc-ws"
PORT=9901
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
- build-fix

env:
REGISTRY: ghcr.io
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Run Tests

on:
pull_request:
branches: [main]
# branches: [main]

jobs:
test:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ pids
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

prisma/db
prisma/migrations
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ COPY package-lock.json .
RUN npm install
COPY . .
RUN npx prisma generate
RUN npx prisma migrate dev --preview-feature --name init
RUN npm run build

FROM node:18-slim
RUN apt update && apt install libssl-dev dumb-init -y --no-install-recommends
WORKDIR /usr/src/app

# probably move to cluster or github
ENV DATABASE_URL="file:./db/dev.db"
ENV NODE_ENV="dev"
# probably move to cluster
ENV NODE_ENV="prod"
ENV NODE_URL="wss://testnet.klayr.xyz/rpc-ws"
ENV PORT=9901

COPY --chown=node:node --from=build /usr/src/app/dist ./dist
COPY --chown=node:node --from=build /usr/src/app/package.json .
COPY --chown=node:node --from=build /usr/src/app/package-lock.json .
COPY --chown=node:node --from=build /usr/src/app/prisma/db/dev.db ./prisma/db/dev.db
COPY --chown=node:node --from=build /usr/src/app/prisma ./prisma

RUN npm install --omit=dev
COPY --chown=node:node --from=build /usr/src/app/node_modules/.prisma/client ./node_modules/.prisma/client

CMD ["dumb-init", "node", "dist/main"]
## TODO: hacky way to make sure the db is up before running the migration
CMD ["sh", "-c", "sleep 20; exec npm run start:migrate:prod"]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ sunset arctic describe battle negative grace fame pottery spin warm wasp arctic

# Start postgresql dev server docker image:

docker run --rm --name pg -p 5432:5432 -e POSTGRES_PASSWORD=welcome postgres:15
docker run --rm --name pg -p 5432:5432 -e POSTGRES_PASSWORD=welcome postgres:16

docker run -d -p 9901:9901 -e DATABASE_URL="postgres://postgres:welcome@host.docker.internal/postgres" gateway-test
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"start:dev": "npm run prisma && nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:migrate:prod": "prisma migrate deploy && npm run start:prod",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand All @@ -34,7 +35,7 @@
"@nestjs/schedule": "^4.0.2",
"@nestjs/swagger": "^7.3.1",
"@nestjs/websockets": "^10.3.8",
"@prisma/client": "^5.15.0",
"@prisma/client": "^5.18.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"fastq": "^1.17.1",
Expand All @@ -56,7 +57,7 @@
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"prisma": "^5.15.0",
"prisma": "^5.18.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
Expand Down
152 changes: 152 additions & 0 deletions prisma/migrations/20240814145929_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
-- CreateTable
CREATE TABLE "Account" (
"address" TEXT NOT NULL,
"publicKey" TEXT,
"name" TEXT,

CONSTRAINT "Account_pkey" PRIMARY KEY ("address")
);

-- CreateTable
CREATE TABLE "Asset" (
"id" SERIAL NOT NULL,
"height" INTEGER NOT NULL,
"module" TEXT NOT NULL,
"data" TEXT NOT NULL,

CONSTRAINT "Asset_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Block" (
"height" INTEGER NOT NULL,
"id" TEXT NOT NULL,
"version" INTEGER NOT NULL,
"timestamp" INTEGER NOT NULL,
"previousBlockID" TEXT NOT NULL,
"stateRoot" TEXT NOT NULL,
"assetRoot" TEXT NOT NULL,
"eventRoot" TEXT NOT NULL,
"transactionRoot" TEXT NOT NULL,
"validatorsHash" TEXT NOT NULL,
"generatorAddress" TEXT NOT NULL,
"maxHeightPrevoted" INTEGER NOT NULL,
"maxHeightGenerated" INTEGER NOT NULL,
"impliesMaxPrevotes" BOOLEAN NOT NULL,
"signature" TEXT NOT NULL,
"aggregateCommit" TEXT NOT NULL,
"numberOfTransactions" INTEGER NOT NULL,
"numberOfAssets" INTEGER NOT NULL,
"numberOfEvents" INTEGER NOT NULL,
"isFinal" BOOLEAN NOT NULL DEFAULT false,
"reward" TEXT NOT NULL,
"totalBurnt" BIGINT NOT NULL DEFAULT 0,
"networkFee" BIGINT NOT NULL DEFAULT 0,
"totalForged" BIGINT NOT NULL,

CONSTRAINT "Block_pkey" PRIMARY KEY ("height")
);

-- CreateTable
CREATE TABLE "ChainEvents" (
"id" SERIAL NOT NULL,
"height" INTEGER NOT NULL,
"module" TEXT NOT NULL,
"name" TEXT NOT NULL,
"data" TEXT,
"topics" TEXT,
"index" INTEGER,
"transactionID" TEXT,

CONSTRAINT "ChainEvents_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "NextBlockToSync" (
"id" INTEGER NOT NULL,
"height" INTEGER NOT NULL,

CONSTRAINT "NextBlockToSync_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Transaction" (
"id" TEXT NOT NULL,
"height" INTEGER NOT NULL,
"module" TEXT NOT NULL,
"command" TEXT NOT NULL,
"nonce" TEXT NOT NULL,
"fee" TEXT NOT NULL,
"minFee" TEXT NOT NULL,
"params" TEXT NOT NULL,
"signatures" TEXT NOT NULL,
"index" INTEGER NOT NULL,
"senderAddress" TEXT NOT NULL,
"recipientAddress" TEXT,
"executionStatus" TEXT DEFAULT 'pending',

CONSTRAINT "Transaction_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Validator" (
"address" TEXT NOT NULL,
"totalStake" BIGINT NOT NULL DEFAULT 0,
"selfStake" BIGINT NOT NULL DEFAULT 0,
"validatorWeight" BIGINT NOT NULL DEFAULT 0,
"generatedBlocks" INTEGER NOT NULL DEFAULT 0,
"rank" INTEGER,
"blsKey" TEXT,
"proofOfPossession" TEXT,
"generatorKey" TEXT,
"lastGeneratedHeight" INTEGER,
"isBanned" BOOLEAN NOT NULL DEFAULT false,
"status" TEXT,
"reportMisbehaviorHeights" TEXT,
"punishmentPeriods" TEXT,
"consecutiveMissedBlocks" INTEGER,
"commission" INTEGER,
"lastCommissionIncreaseHeight" INTEGER,
"sharingCoefficients" TEXT,

CONSTRAINT "Validator_pkey" PRIMARY KEY ("address")
);

-- CreateIndex
CREATE UNIQUE INDEX "Account_address_key" ON "Account"("address");

-- CreateIndex
CREATE UNIQUE INDEX "Account_publicKey_key" ON "Account"("publicKey");

-- CreateIndex
CREATE UNIQUE INDEX "Block_height_key" ON "Block"("height");

-- CreateIndex
CREATE UNIQUE INDEX "Block_id_key" ON "Block"("id");

-- CreateIndex
CREATE UNIQUE INDEX "NextBlockToSync_id_key" ON "NextBlockToSync"("id");

-- AddForeignKey
ALTER TABLE "Asset" ADD CONSTRAINT "Asset_height_fkey" FOREIGN KEY ("height") REFERENCES "Block"("height") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Block" ADD CONSTRAINT "Block_generatorAddress_fkey" FOREIGN KEY ("generatorAddress") REFERENCES "Account"("address") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ChainEvents" ADD CONSTRAINT "ChainEvents_height_fkey" FOREIGN KEY ("height") REFERENCES "Block"("height") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ChainEvents" ADD CONSTRAINT "ChainEvents_transactionID_fkey" FOREIGN KEY ("transactionID") REFERENCES "Transaction"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Transaction" ADD CONSTRAINT "Transaction_senderAddress_fkey" FOREIGN KEY ("senderAddress") REFERENCES "Account"("address") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Transaction" ADD CONSTRAINT "Transaction_recipientAddress_fkey" FOREIGN KEY ("recipientAddress") REFERENCES "Account"("address") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Transaction" ADD CONSTRAINT "Transaction_height_fkey" FOREIGN KEY ("height") REFERENCES "Block"("height") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Validator" ADD CONSTRAINT "Validator_address_fkey" FOREIGN KEY ("address") REFERENCES "Account"("address") ON DELETE RESTRICT ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
5 changes: 2 additions & 3 deletions prisma/schema/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ generator client {
previewFeatures = ["prismaSchemaFolder"]
}


datasource db {
provider = "postgresql"
url = "postgres://postgres:welcome@localhost/postgres"
}
url = env("DATABASE_URL")
}
2 changes: 1 addition & 1 deletion src/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class PrismaService extends PrismaClient implements OnModuleInit {

if (process.env.NODE_ENV === 'dev') {
this.logger.warn('DEV mode: clearing DB');
await this.DEVonlyClearDB();
// await this.DEVonlyClearDB();
}

PrismaService.hasBeenInitialized = true;
Expand Down

0 comments on commit 0a6d384

Please sign in to comment.