Skip to content

Commit

Permalink
feat(search-service): add search service, with a sandbox example (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshatdubeysf authored Oct 24, 2021
1 parent 70d5285 commit 501513c
Show file tree
Hide file tree
Showing 118 changed files with 36,875 additions and 3 deletions.
1 change: 1 addition & 0 deletions .czferc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const scopes = [
{ name: 'video-conferencing-service' },
{ name: 'audit-service' },
{ name: 'bpmn-service' },
{ name: 'search-service' },
{ name: 'sandbox' },
{ name: 'search-client'},
{name: 'chat-service'},
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ node_modules
.env
lerna-debug.log
**/*.bak
**/.DS_Store
**/.DS_Store
1 change: 1 addition & 0 deletions sandbox/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ docker push ${REGISTRY}/audit-ms-example
docker push ${REGISTRY}/scheduler-example
docker push ${REGISTRY}/video-conferencing-ms-example
docker push ${REGISTRY}/in-mail-example
docket push ${REGISTRY}/search-ms-example
docker push ${REGISTRY}/chat-notification-pubnub-example
3 changes: 3 additions & 0 deletions sandbox/ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local_docker_push() {
docker push ${LOCAL_REGISTRY}/scheduler-example
docker push ${LOCAL_REGISTRY}/video-conferencing-ms-example
docker push ${LOCAL_REGISTRY}/in-mail-example
docker push ${LOCAL_REGISTRY}/search-ms-example
docker push ${LOCAL_REGISTRY}/chat-notification-pubnub-example
}

Expand All @@ -43,6 +44,7 @@ docker_push() {
docker tag ${LOCAL_REGISTRY}/scheduler-example ${DOCKER_USERNAME}/scheduler-example
docker tag ${LOCAL_REGISTRY}/video-conferencing-ms-example ${DOCKER_USERNAME}/video-conferencing-ms-example
docker tag ${LOCAL_REGISTRY}/in-mail-example ${DOCKER_USERNAME}/in-mail-example
docker tag ${LOCAL_REGISTRY}/search-ms-example ${DOCKER_USERNAME}/search-ms-example
docker tag ${LOCAL_REGISTRY}/chat-notification-pubnub-example ${DOCKER_USERNAME}/chat-notification-pubnub-example

docker push ${DOCKER_USERNAME}/auth-multitenant-example
Expand All @@ -52,6 +54,7 @@ docker_push() {
docker push ${DOCKER_USERNAME}/scheduler-example
docker push ${DOCKER_USERNAME}/video-conferencing-ms-example
docker push ${DOCKER_USERNAME}/in-mail-example
docker push ${DOCKER_USERNAME}/search-ms-example
docker push ${DOCKER_USERNAME}/chat-notification-pubnub-example

# TODO: should we clean up after build? Since agent is ephemeral, some caching may be helpful after an initial run
Expand Down
42 changes: 41 additions & 1 deletion sandbox/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ x-in-mail-variables: &in-mail-variables
JWT_SECRET: i_am_a_strong_secret
JWT_ISSUER: https://loopback4-microservice-catalog

x-search-ms-variables: &search-ms-variables
NODE_ENV: dev
LOG_LEVEL: debug
DB_HOST: postgres
DB_PORT: 5432
DB_USER: ${POSTGRES_USER:-postgres}
DB_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
DB_DATABASE: search_db
DB_SCHEMA: main
x-chat-notif-facade-variables: &chat-notif-facade-variables
NODE_ENV: dev
LOG_LEVEL: debug
Expand Down Expand Up @@ -357,6 +366,36 @@ services:
- audit-ms-migration
restart: on-failure

search-ms-example:
image: ${REGISTRY:-localhost:32000}/search-ms-example
build:
context: ./search-ms-example
dockerfile: Dockerfile
ports:
- '3037:3000'
networks:
- sandbox
environment: *search-ms-variables
depends_on:
- postgres
- postgres_orchestrator
- search-ms-migration
restart: on-failure

search-ms-migration:
image: ${REGISTRY:-localhost:32000}/search-ms-example
command: sh -c "sleep 60 && npm run db:migrate"
build:
context: ./search-ms-example
dockerfile: Dockerfile
environment: *search-ms-variables
depends_on:
- postgres
- postgres_orchestrator
networks:
- sandbox
restart: on-failure

audit-ms-migration:
image: ${REGISTRY:-localhost:32000}/audit-ms-example
command: sh -c "sleep 60 && npm run db:migrate"
Expand Down Expand Up @@ -514,7 +553,8 @@ services:
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database pubnub_db' &&
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database scheduler_db' &&
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database in_mail_db'&&
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database video_db' &&
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database search_db'&&
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database video_db'"
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database chat_notif_facade_db' &&
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database chatdb' &&
psql -U ${POSTGRES_USER:-postgres} -d postgres -h postgres -c 'create database notifdb'"
Expand Down
2 changes: 1 addition & 1 deletion sandbox/pubnub-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Check out https://hub.docker.com/_/node to select a new base image
FROM node:10-slim
FROM node:14-slim

# Set to a non-root built-in user `node`
USER node
Expand Down
5 changes: 5 additions & 0 deletions sandbox/search-ms-example/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
npm-debug.log
/dist
# Cache used by TypeScript's incremental build
*.tsbuildinfo
5 changes: 5 additions & 0 deletions sandbox/search-ms-example/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_HOST=
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_DATABASE=
5 changes: 5 additions & 0 deletions sandbox/search-ms-example/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
dist/
coverage/
migrations/
.eslintrc.js
3 changes: 3 additions & 0 deletions sandbox/search-ms-example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: '@loopback/eslint-config',
};
64 changes: 64 additions & 0 deletions sandbox/search-ms-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Transpiled JavaScript files from Typescript
/dist

# Cache used by TypeScript's incremental build
*.tsbuildinfo
5 changes: 5 additions & 0 deletions sandbox/search-ms-example/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exit": true,
"recursive": true,
"require": "source-map-support/register"
}
2 changes: 2 additions & 0 deletions sandbox/search-ms-example/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
*.json
7 changes: 7 additions & 0 deletions sandbox/search-ms-example/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"bracketSpacing": false,
"singleQuote": true,
"printWidth": 80,
"trailingComma": "all",
"arrowParens": "avoid"
}
38 changes: 38 additions & 0 deletions sandbox/search-ms-example/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/dist/index.js",
},
{
"type": "node",
"request": "launch",
"name": "Run Mocha tests",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"runtimeArgs": [
"-r",
"${workspaceRoot}/node_modules/source-map-support/register"
],
"cwd": "${workspaceRoot}",
"autoAttachChildProcesses": true,
"args": [
"--config",
"${workspaceRoot}/.mocharc.json",
"${workspaceRoot}/dist/__tests__/**/*.js",
"-t",
"0"
]
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858
}
]
}
32 changes: 32 additions & 0 deletions sandbox/search-ms-example/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"editor.rulers": [80],
"editor.tabCompletion": "on",
"editor.tabSize": 2,
"editor.trimAutoWhitespace": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll.eslint": true
},

"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,
"**/.hg": true,
"**/.svn": true,
"**/CVS": true,
"dist": true,
},
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,

"typescript.tsdk": "./node_modules/typescript/lib",
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
"typescript.preferences.quoteStyle": "single",
"eslint.run": "onSave",
"eslint.nodePath": "./node_modules",
"eslint.validate": [
"javascript",
"typescript"
]
}
29 changes: 29 additions & 0 deletions sandbox/search-ms-example/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Watch and Compile Project",
"type": "shell",
"command": "npm",
"args": ["--silent", "run", "build:watch"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$tsc-watch"
},
{
"label": "Build, Test and Lint",
"type": "shell",
"command": "npm",
"args": ["--silent", "run", "test:dev"],
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": ["$tsc", "$eslint-compact", "$eslint-stylish"]
}
]
}
6 changes: 6 additions & 0 deletions sandbox/search-ms-example/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@loopback/cli": {
"packageManager": "npm",
"version": "2.21.2"
}
}
36 changes: 36 additions & 0 deletions sandbox/search-ms-example/DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Developer's Guide

We use Visual Studio Code for developing LoopBack and recommend the same to our
users.

## VSCode setup

Install the following extensions:

- [eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
- [prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)

## Development workflow

### Visual Studio Code

1. Start the build task (Cmd+Shift+B) to run TypeScript compiler in the
background, watching and recompiling files as you change them. Compilation
errors will be shown in the VSCode's "PROBLEMS" window.

2. Execute "Run Rest Task" from the Command Palette (Cmd+Shift+P) to re-run the
test suite and lint the code for both programming and style errors. Linting
errors will be shown in VSCode's "PROBLEMS" window. Failed tests are printed
to terminal output only.

### Other editors/IDEs

1. Open a new terminal window/tab and start the continuous build process via
`npm run build:watch`. It will run TypeScript compiler in watch mode,
recompiling files as you change them. Any compilation errors will be printed
to the terminal.

2. In your main terminal window/tab, run `npm run test:dev` to re-run the test
suite and lint the code for both programming and style errors. You should run
this command manually whenever you have new changes to test. Test failures
and linter errors will be printed to the terminal.
28 changes: 28 additions & 0 deletions sandbox/search-ms-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Check out https://hub.docker.com/_/node to select a new base image
FROM node:14-slim

# Set to a non-root built-in user `node`
USER node

# Create app directory (with user `node`)
RUN mkdir -p /home/node/app

WORKDIR /home/node/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY --chown=node package*.json ./

RUN npm install

# Bundle app source code
COPY --chown=node . .

RUN npm run build

# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0 PORT=3000

EXPOSE ${PORT}
CMD [ "node", "." ]
Loading

0 comments on commit 501513c

Please sign in to comment.