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

Fix/indexer #4022

Merged
merged 8 commits into from
Aug 14, 2024
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
29 changes: 29 additions & 0 deletions configs/nats.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Client port of 4222 on all interfaces
port: 4222

# HTTP monitoring port
monitor_port: 8222

# This is for clustering multiple servers together.
cluster {
# It is recommended to set a cluster name
name: "my_cluster"

# Route connections to be received on any interface on port 6222
port: 6222

# Routes are protected, so need to use them with --routes flag
# e.g. --routes=nats-route://ruser:T0pS3cr3t@otherdockerhost:6222
authorization {
user: ruser
password: T0pS3cr3t
timeout: 2
}

# Routes are actively solicited and connected to from this server.
# This Docker image has none by default, but you can pass a
# flag to the nats-server docker image to create one to an existing server.
routes = []
}

max_payload: 64MB
24 changes: 13 additions & 11 deletions docker-compose-indexer.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: "3.8"
services:
mongo:
image: mongo:6.0.13
image: mongo:6.0.16
command: "--setParameter allowDiskUseByDefault=true"
restart: always
expose:
Expand All @@ -19,15 +18,17 @@ services:
- mongo

ipfs-node:
image: ipfs/kubo:latest
image: ipfs/kubo:v0.29.0

message-broker:
image: nats:2.9.24
image: nats:2.9.25
expose:
- 4222
ports:
- '8222:8222'
command: '--http_port 8222'
command: '-c /etc/nats/nats.conf --http_port 8222'
volumes:
- ./configs/nats.conf:/etc/nats/nats.conf

indexer-worker-service:
env_file:
Expand All @@ -39,15 +40,16 @@ services:
depends_on:
- mongo
- message-broker
- indexer-service
environment:
- GUARDIAN_ENV=${GUARDIAN_ENV}
expose:
- 6555
volumes:
- ./indexer-worker-service/tls:/usr/local/indexer-worker-service/tls:ro
- ./indexer-worker-service/configs:/usr/local/indexer-worker-service/configs:ro
- ./indexer-worker-service/tls:/usr/local/app/tls:ro
- ./indexer-worker-service/configs:/usr/local/app/configs:ro
deploy:
replicas: 5
replicas: 3

indexer-api-gateway:
env_file:
Expand All @@ -66,7 +68,7 @@ services:
environment:
- GUARDIAN_ENV=${GUARDIAN_ENV}
volumes:
- ./indexer-api-gateway/configs:/usr/local/indexer-api-gateway/configs:ro
- ./indexer-api-gateway/configs:/usr/local/app/configs:ro

indexer-service:
env_file:
Expand All @@ -76,8 +78,8 @@ services:
dockerfile: ./indexer-service/Dockerfile
init: true
volumes:
- ./indexer-service/tls:/usr/local/indexer-service/tls:ro
- ./indexer-service/configs:/usr/local/indexer-service/configs:ro
- ./indexer-service/tls:/usr/local/app/tls:ro
- ./indexer-service/configs:/usr/local/app/configs:ro
depends_on:
- mongo
- message-broker
Expand Down
4 changes: 3 additions & 1 deletion docker-compose-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ services:
- 4222
ports:
- '8222:8222'
command: '--http_port 8222'
command: '-c /etc/nats/nats.conf --http_port 8222'
volumes:
- ./configs/nats.conf:/etc/nats/nats.conf

vault:
image: hashicorp/vault:1.12.11
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ services:
- 4222
ports:
- '8222:8222'
command: '--http_port 8222'
command: '-c /etc/nats/nats.conf --http_port 8222'
volumes:
- ./configs/nats.conf:/etc/nats/nats.conf

vault:
image: hashicorp/vault:1.12.11
Expand Down
108 changes: 55 additions & 53 deletions indexer-api-gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
FROM node:20 AS interfacesModuleBuilder
WORKDIR /usr/local/indexer-interfaces
COPY ./indexer-interfaces/package.json ./
COPY ./indexer-interfaces/tsconfig*.json ./
COPY ./yarn.lock ./
COPY ./package-lock.json ./
ADD ./indexer-interfaces/src ./src/.
RUN yarn install
RUN yarn pack

FROM node:20 AS commonModuleBuilder
WORKDIR /usr/local/indexer-common
COPY --from=interfacesModuleBuilder /usr/local/indexer-interfaces/indexer-interfaces-*.tgz /tmp/indexer-interfaces.tgz
COPY ./indexer-common/package.json ./
COPY ./indexer-common/tsconfig*.json ./
COPY ./yarn.lock ./
COPY ./package-lock.json ./
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@indexer/interfaces']='file:/tmp/indexer-interfaces.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN yarn install
ADD ./indexer-common/src ./src/.
RUN yarn pack

FROM node:20 AS apiGatewayBuilder
WORKDIR /usr/local/indexer-api-gateway
COPY --from=interfacesModuleBuilder /usr/local/indexer-interfaces/indexer-interfaces-*.tgz /tmp/indexer-interfaces.tgz
COPY --from=commonModuleBuilder /usr/local/indexer-common/indexer-common-*.tgz /tmp/indexer-common.tgz
COPY ./indexer-api-gateway/package.json ./
COPY ./indexer-api-gateway/tsconfig*.json ./
COPY ./indexer-api-gateway/Gulpfile.mjs ./
COPY ./yarn.lock ./
COPY ./package-lock.json ./
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@indexer/interfaces']='file:/tmp/indexer-interfaces.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@indexer/common']='file:/tmp/indexer-common.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN yarn install
ADD ./indexer-api-gateway/environments ./environments/.
ADD ./indexer-api-gateway/src ./src/.
RUN yarn run build:prod

FROM node:20
ENV PLATFORM="docker"
ENV NODE_ENV="production"
WORKDIR /usr/local/indexer-api-gateway
COPY --from=interfacesModuleBuilder /usr/local/indexer-interfaces/indexer-interfaces-*.tgz /tmp/indexer-interfaces.tgz
COPY --from=commonModuleBuilder /usr/local/indexer-common/indexer-common-*.tgz /tmp/indexer-common.tgz
COPY --from=apiGatewayBuilder /usr/local/indexer-api-gateway/yarn.lock ./
COPY ./indexer-api-gateway/package.json ./
COPY ./yarn.lock ./
COPY ./package-lock.json ./
# syntax=docker/dockerfile:1
# Stage 0: Use node image for base image for all stages
ARG NODE_VERSION=20.16-alpine
FROM node:${NODE_VERSION} as base
WORKDIR /usr/local/app
# Define an argument `YARN_CACHE_FOLDER` for the Yarn cache directory
ARG YARN_CACHE_FOLDER=/root/.yarn

# Stage 1: Build interfaces module
FROM base as interfaces
COPY --link indexer-interfaces/package.json indexer-interfaces/tsconfig*.json yarn.lock ./
COPY --link indexer-interfaces/src src/
# Here and after. Leverage a cache mount to /root/.yarn to speed up subsequent builds
RUN --mount=type=cache,target=/root/.yarn \
yarn install --immutable && yarn pack

# Stage 2: Build common module
FROM base as common
COPY --link --from=interfaces /usr/local/app/indexer-interfaces-*.tgz /tmp/indexer-interfaces.tgz
COPY --link indexer-common/package.json indexer-common/tsconfig*.json yarn.lock ./
COPY --link indexer-common/src src/
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@indexer/interfaces']='file:/tmp/indexer-interfaces.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@indexer/common']='file:/tmp/indexer-common.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN yarn install
COPY --from=apiGatewayBuilder /usr/local/indexer-api-gateway/dist ./dist
RUN rm /tmp/indexer-interfaces.tgz /tmp/indexer-common.tgz
RUN --mount=type=cache,target=/root/.yarn \
yarn install --immutable && yarn pack

# Stage 3: Installing production dependecies
FROM base as deps
COPY --link --from=interfaces /usr/local/app/indexer-interfaces-*.tgz /tmp/indexer-interfaces.tgz
COPY --link --from=common /usr/local/app/indexer-common-*.tgz /tmp/indexer-common.tgz
COPY --link indexer-api-gateway/package.json indexer-api-gateway/tsconfig*.json indexer-api-gateway/Gulpfile.mjs yarn.lock ./
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@indexer/interfaces']='file:/tmp/indexer-interfaces.tgz'; input.dependencies['@indexer/common']='file:/tmp/indexer-common.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN --mount=type=cache,target=/root/.yarn,sharing=private \
yarn install --immutable --prod

# Stage 4: Build service
FROM base as build
COPY --link --from=interfaces /usr/local/app/indexer-interfaces-*.tgz /tmp/indexer-interfaces.tgz
COPY --link --from=common /usr/local/app/indexer-common-*.tgz /tmp/indexer-common.tgz
COPY --link --from=deps /usr/local/app/package.json /usr/local/app/tsconfig*.json /usr/local/app/Gulpfile.mjs /usr/local/app/yarn.lock ./
COPY --link indexer-api-gateway/environments environments/
COPY --link indexer-api-gateway/src src/
RUN --mount=type=cache,target=/root/.yarn \
yarn install --immutable && yarn run build:prod

# Stage 5: Create the final image
FROM base as image
ENV NODE_ENV production

# Copy the production dependencies from the deps stage and the built application from the build stage into the image
COPY --link --from=deps /usr/local/app/node_modules node_modules/
COPY --link --from=deps /usr/local/app/package.json ./
COPY --link --from=build /usr/local/app/dist dist/

# Change the user to node
USER node

CMD npm start
CMD [ "node", "dist/index.js" ]
16 changes: 14 additions & 2 deletions indexer-api-gateway/src/api/services/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller, HttpCode, HttpStatus, Get, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiQuery, ApiInternalServerErrorResponse } from '@nestjs/swagger';
import { IndexerMessageAPI } from '@indexer/common';
import { ApiClient } from '../api-client.js';
import { ApiPaginatedResponse } from '../../decorators/api-paginated-response.js';
import { ApiPaginatedResponse } from '#decorators';
import { InternalServerErrorDTO, SearchItemDTO } from '#dto';

@Controller('search')
Expand All @@ -22,9 +22,19 @@ export class SearchApi extends ApiClient {
name: 'pageIndex',
description: 'Page index',
example: 0,
required: false,
required: true,
type: 'number',
})
@ApiQuery({
name: 'pageSize',
description: 'Page size',
example: 10,
required: true,
schema: {
type: 'number',
maximum: 100
}
})
@ApiQuery({
name: 'search',
description: 'Search phrase',
Expand All @@ -33,11 +43,13 @@ export class SearchApi extends ApiClient {
@HttpCode(HttpStatus.OK)
async search(
@Query('pageIndex') pageIndex: number,
@Query('pageSize') pageSize: number,
@Query('search') search?: string
): Promise<SearchItemDTO[]> {
return await this.send(IndexerMessageAPI.GET_SEARCH_API, {
search,
pageIndex,
pageSize
});
}
}
Loading