Skip to content

Commit

Permalink
feat: implement npm workspaces
Browse files Browse the repository at this point in the history
refs #209
  • Loading branch information
ygrishajev committed May 21, 2024
1 parent fd781cd commit 22bd5c2
Show file tree
Hide file tree
Showing 1,159 changed files with 44,775 additions and 219 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-deploy-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
with:
filters: |
deploy-web:
- 'deploy-web/**'
- 'apps/deploy-web/**'
- name: Build the Docker image
if: steps.filter.outputs.deploy-web == 'true'
run: docker build ./deploy-web/
run: docker build ./apps/deploy-web
9 changes: 4 additions & 5 deletions .github/workflows/docker-build-indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ jobs:
with:
filters: |
indexer:
- 'indexer/**'
shared:
- 'shared/**'
- 'apps/indexer/**'
- 'packages/shared/**'
- name: Build the Docker image
if: steps.filter.outputs.indexer == 'true' || steps.filter.outputs.shared == 'true'
run: docker build . --file ./indexer/Dockerfile
if: steps.filter.outputs.indexer == 'true'
run: docker build -f Dockerfile.indexer -t cloudmos-indexer .
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-landing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
with:
filters: |
landing:
- 'landing/**'
- 'apps/landing/**'
- name: Build the Docker image for LANDING
if: steps.filter.outputs.landing == 'true'
run: docker build . --file ./landing/Dockerfile
run: docker build ./apps/landing
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-provider-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
with:
filters: |
provider-proxy:
- 'provider-proxy/**'
- 'apps/provider-proxy/**'
- name: Build the Docker image
if: steps.filter.outputs.provider-proxy == 'true'
run: docker build ./provider-proxy/
run: docker build ./apps/provider-proxy
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-stats-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
with:
filters: |
stats-web:
- 'stats-web/**'
- 'apps/stats-web/**'
- name: Build the Docker image
if: steps.filter.outputs.stats-web == 'true'
run: docker build ./stats-web/
run: docker build ./apps/stats-web
54 changes: 24 additions & 30 deletions .github/workflows/validate-n-build-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,37 @@ jobs:
with:
filters: |
api:
- 'api/**'
shared:
- 'shared/**'
- 'apps/api/**'
- 'packages/shared/**'
- name: Restore node_modules cache
id: deps-cache
uses: martijnhols/actions-cache/restore@v3
- name: Setup Node.js
if: steps.filter.outputs.api == 'true'
uses: actions/setup-node@v4
with:
path: api/node_modules
key: ${{ runner.os }}-build-api-deps-cache-${{ hashFiles('api/package-lock.json') }}
node-version: 18.20.2
cache: npm
cache-dependency-path: package-lock.json

- name: Install Dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
cd api
npm install
- name: Cache node modules
if: steps.deps-cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/save@v3
- name: Setup Local Deps
if: steps.filter.outputs.api == 'true'
uses: actions/setup-node@v4
with:
path: api/node_modules
key: ${{ runner.os }}-build-api-deps-cache-${{ hashFiles('api/package-lock.json') }}
node-version: 18.20.2
cache: npm
cache-dependency-path: apps/api/package-lock.json

- name: Install dependencies
if: steps.filter.outputs.api == 'true'
run: npm ci --workspace=apps/api

- name: Run static code analysis
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.shared == 'true'
run: |
cd api
npm run lint
if: steps.filter.outputs.api == 'true'
run: npm run lint --workspace=apps/api

- name: Run unit tests
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.shared == 'true'
run: |
cd api
npm run test:unit
if: steps.filter.outputs.api == 'true'
run: npm run test:unit --workspace=apps/api

- name: Build the Docker image for API
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.shared == 'true'
run: docker build . --file ./api/Dockerfile
if: steps.filter.outputs.api == 'true'
run: docker build -f Dockerfile.api -t cloudmos-api .
35 changes: 35 additions & 0 deletions Dockerfile.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM node:18-alpine AS builder

WORKDIR /app

COPY /apps/api /app/apps/api
COPY /packages/shared /app/packages/shared
COPY package.json /app
COPY package-lock.json /app

RUN apk add --no-cache python3 make g++ libc6-compat postgresql-dev

RUN npm ci --workspace apps/api
RUN npm run build --workspace apps/api

FROM node:18-alpine

WORKDIR /app

COPY --from=builder /app/packages/shared /app/packages/shared
COPY --from=builder /app/package.json /app/package.json
COPY --from=builder /app/package-lock.json /app/package-lock.json

COPY --from=builder /app/apps/api/dist /app/apps/api/dist
COPY --from=builder /app/apps/api/package.json /app/apps/api/package.json
COPY --from=builder /app/apps/api/package-lock.json /app/apps/api/package-lock.json

RUN apk add --no-cache python3 make g++ libc6-compat postgresql-dev

RUN npm ci --workspace apps/api --omit=dev

EXPOSE 80

WORKDIR /app/apps/api

CMD ["node", "dist/server.js"]
30 changes: 30 additions & 0 deletions Dockerfile.indexer
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:18-alpine AS builder

WORKDIR /app

COPY /apps/indexer /app/apps/indexer
COPY /packages/shared /app/packages/shared
COPY package.json /app
COPY package-lock.json /app

RUN npm ci --workspace apps/indexer
RUN npm run build --workspace apps/indexer

FROM node:18-alpine

WORKDIR /app

COPY --from=builder /app/apps/indexer/dist /app/apps/indexer/dist
COPY --from=builder /app/packages/shared /app/packages/shared
COPY --from=builder /app/package.json /app/package.json
COPY --from=builder /app/package-lock.json /app/package-lock.json
COPY --from=builder /app/apps/indexer/package.json /app/apps/indexer/package.json
COPY --from=builder /app/apps/indexer/package-lock.json /app/apps/indexer/package-lock.json

RUN npm ci --workspace apps/indexer --omit=dev

EXPOSE 80

WORKDIR /app/apps/indexer

CMD ["node", "dist/server.js"]
19 changes: 0 additions & 19 deletions api/Dockerfile

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 2 additions & 7 deletions api/jest.config.js → apps/api/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const MAP_ALIASES = {
"^@src(.*)$": "<rootDir>/src/$1",
"^@test/(.*)$": "<rootDir>/test/$1",
"^@shared/(.*)$": "<rootDir>/../shared/$1"
};
const MAP_TO_SAME_SEQUELIZE_PACKAGE = {
"^sequelize(.*)$": "<rootDir>/node_modules/sequelize$1"
"^@test/(.*)$": "<rootDir>/test/$1"
};

const common = {
Expand All @@ -13,8 +9,7 @@ const common = {
},
rootDir: ".",
moduleNameMapper: {
...MAP_ALIASES,
...MAP_TO_SAME_SEQUELIZE_PACKAGE
...MAP_ALIASES
},
setupFiles: ["./test/setup.ts"]
};
Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions api/package.json → apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@akashnetwork/akash-api": "^1.3.0",
"@akashnetwork/cloudmos-shared": "*",
"@chain-registry/assets": "^0.7.1",
"@cosmjs/crypto": "^0.28.11",
"@cosmjs/encoding": "^0.28.11",
Expand All @@ -38,7 +39,7 @@
"@octokit/rest": "^18.12.0",
"@sentry/node": "^7.55.2",
"axios": "^0.27.2",
"cloudmos-shared": "file:../shared/",
"bufferutil": "^4.0.8",
"cosmjs-types": "^0.5.0",
"date-fns": "^2.29.2",
"date-fns-tz": "^1.3.6",
Expand All @@ -50,13 +51,16 @@
"markdown-to-txt": "^2.0.1",
"memory-cache": "^0.2.0",
"node-fetch": "^2.6.1",
"pg": "^8.7.3",
"pg": "^8.11.5",
"pg-hstore": "^2.3.4",
"pg-native": "^3.0.1",
"protobufjs": "^6.11.2",
"semver": "^7.3.8",
"sequelize": "^6.21.3",
"sequelize-typescript": "^2.1.5",
"stripe": "^10.14.0",
"utf-8-validate": "^5.0.10",
"uuid": "^9.0.1",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions api/src/app.ts → apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { Hono } from "hono";
import { cors } from "hono/cors";
import { serve } from "@hono/node-server";
import { legacyRouter } from "./routers/legacyRouter";
// TODO: find out how to properly import this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import { sentry } from "@hono/sentry";
import { internalRouter } from "./routers/internalRouter";

Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions api/src/db/dbConnection.ts → apps/api/src/db/dbConnection.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defaults as pgDefaults } from "pg";
import pg from "pg";
import { env } from "@src/utils/env";
import { Transaction as DbTransaction } from "sequelize";
import { Sequelize } from "sequelize-typescript";
import { chainModels, getChainModels, userModels } from "@shared/dbSchemas";
import { Template, TemplateFavorite, UserAddressName, UserSetting } from "@shared/dbSchemas/user";
import { chainDefinitions } from "@shared/chainDefinitions";
import { chainModels, getChainModels, userModels } from "@akashnetwork/cloudmos-shared/dbSchemas";
import { Template, TemplateFavorite, UserAddressName, UserSetting } from "@akashnetwork/cloudmos-shared/dbSchemas/user";
import { chainDefinitions } from "@akashnetwork/cloudmos-shared/chainDefinitions";

function isValidNetwork(network: string): network is keyof typeof csMap {
return network in csMap;
Expand All @@ -24,9 +24,9 @@ if (!csMap[env.Network]) {
throw new Error(`Missing connection string for network: ${env.Network}`);
}

pgDefaults.parseInt8 = true;
pg.defaults.parseInt8 = true;
export const chainDb = new Sequelize(csMap[env.Network], {
dialect: "postgres",
dialectModule: pg,
logging: false,
transactionType: DbTransaction.TYPES.IMMEDIATE,
define: {
Expand All @@ -42,7 +42,7 @@ export const chainDbs: { [key: string]: Sequelize } = Object.keys(chainDefinitio
(obj, chain) => ({
...obj,
[chain]: new Sequelize(chainDefinitions[chain].connectionString, {
dialect: "postgres",
dialectModule: pg,
logging: false,
repositoryMode: true,
transactionType: DbTransaction.TYPES.IMMEDIATE,
Expand All @@ -57,7 +57,7 @@ export const chainDbs: { [key: string]: Sequelize } = Object.keys(chainDefinitio
);

export const userDb = new Sequelize(env.UserDatabaseCS, {
dialect: "postgres",
dialectModule: pg,
logging: false,
transactionType: DbTransaction.TYPES.IMMEDIATE,
define: {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Template, UserSetting } from "@shared/dbSchemas/user";
import { Template, UserSetting } from "@akashnetwork/cloudmos-shared/dbSchemas/user";
import { privateMiddleware } from "@src/middlewares/privateMiddleware";
import { Hono } from "hono";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { Block } from "@shared/dbSchemas";
import { AkashMessage, Deployment, DeploymentGroup, DeploymentGroupResource } from "@shared/dbSchemas/akash";
import { Day, Transaction } from "@shared/dbSchemas/base";
import { Block } from "@akashnetwork/cloudmos-shared/dbSchemas";
import { AkashMessage, Deployment, DeploymentGroup, DeploymentGroupResource } from "@akashnetwork/cloudmos-shared/dbSchemas/akash";
import { Day, Transaction } from "@akashnetwork/cloudmos-shared/dbSchemas/base";
import { cacheResponse } from "@src/caching/helpers";
import { chainDb } from "@src/db/dbConnection";
import { MsgCreateBid } from "@akashnetwork/akash-api/akash/market/v1beta4";
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { Block } from "@shared/dbSchemas";
import { Lease } from "@shared/dbSchemas/akash";
import { Block } from "@akashnetwork/cloudmos-shared/dbSchemas";
import { Lease } from "@akashnetwork/cloudmos-shared/dbSchemas/akash";
import { openApiExampleAddress } from "@src/utils/constants";
import { differenceInSeconds } from "date-fns";
import { Op } from "sequelize";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AkashBlock as Block, AkashMessage as Message } from "@shared/dbSchemas/akash";
import { Transaction, Validator } from "@shared/dbSchemas/base";
import { AkashBlock as Block, AkashMessage as Message } from "@akashnetwork/cloudmos-shared/dbSchemas/akash";
import { Transaction, Validator } from "@akashnetwork/cloudmos-shared/dbSchemas/base";
import { addSeconds, differenceInSeconds } from "date-fns";

export async function getBlocks(limit: number) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as v1beta1 from "@akashnetwork/akash-api/deprecated/akash/market/v1beta1";
import * as v2beta2 from "@akashnetwork/akash-api/akash/market/v1beta2";
import { decodeMsg } from "@src/utils/protobuf";
import { Transaction } from "@shared/dbSchemas/base";
import { Deployment, Lease } from "@shared/dbSchemas/akash";
import { Transaction } from "@akashnetwork/cloudmos-shared/dbSchemas/base";
import { Deployment, Lease } from "@akashnetwork/cloudmos-shared/dbSchemas/akash";
import { Op, WhereOptions } from "sequelize";
import { Block, Message } from "@shared/dbSchemas";
import { Block, Message } from "@akashnetwork/cloudmos-shared/dbSchemas";

export async function getDeploymentRelatedMessages(owner: string, dseq: string) {
const deployment = await Deployment.findOne({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Op } from "sequelize";
import { Day } from "@shared/dbSchemas/base";
import { AkashBlock as Block } from "@shared/dbSchemas/akash";
import { Day } from "@akashnetwork/cloudmos-shared/dbSchemas/base";
import { AkashBlock as Block } from "@akashnetwork/cloudmos-shared/dbSchemas/akash";
import { add } from "date-fns";
import { getTodayUTC } from "@src/utils";
import { round, uaktToAKT, udenomToDenom } from "@src/utils/math";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Provider, ProviderAttribute } from "@shared/dbSchemas/akash";
import { Provider, ProviderAttribute } from "@akashnetwork/cloudmos-shared/dbSchemas/akash";
import { getProviderAttributesSchema } from "@src/services/external/githubService";

export async function getProviderRegions() {
Expand Down
Loading

0 comments on commit 22bd5c2

Please sign in to comment.