Skip to content

Commit

Permalink
Merge pull request #5 from SamagraX-Stencil/fix/refactor
Browse files Browse the repository at this point in the history
Fix/refactor
  • Loading branch information
sooraj1002 authored Jan 4, 2024
2 parents 19df114 + e836a4c commit 11e42e3
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 34 deletions.
3 changes: 0 additions & 3 deletions src/lib/application/application.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,10 @@ function generate(options: ApplicationOptions, path: string): Source {

function createEnvFile(path): Rule {
return (tree: Tree, context: SchematicContext) => {
console.info('this is path', path);
const envFilePath = `${path}/env-example`;

tree.create(envFilePath, content);

context.logger.info(`File "${envFilePath}" created successfully.`);

return tree;
};
}
94 changes: 89 additions & 5 deletions src/lib/application/content.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
// export const content = `NODE_ENV=development
// APP_PORT=3000
// APP_NAME="NestJS API"
// API_PREFIX=api
// APP_FALLBACK_LANGUAGE=en
// APP_HEADER_LANGUAGE=x-custom-lang
// FRONTEND_DOMAIN=http://localhost:3000
// BACKEND_DOMAIN=http://localhost:3000

// DATABASE_TYPE=postgres
// DATABASE_HOST=postgres
// DATABASE_PORT=5432
// DATABASE_USERNAME=root
// DATABASE_PASSWORD=secret
// DATABASE_NAME=api
// DATABASE_SYNCHRONIZE=false
// DATABASE_MAX_CONNECTIONS=100
// DATABASE_SSL_ENABLED=false
// DATABASE_REJECT_UNAUTHORIZED=false
// DATABASE_CA=
// DATABASE_KEY=
// DATABASE_CERT=

// SHADOW_DATABASE_PORT=5431
// SHADOW_DATABASE_USERNAME=root
// SHADOW_DATABASE_PASSWORD=secret
// SHADOW_DATABASE_NAME=shadow

// # Support "local", "s3"
// FILE_DRIVER=local
// ACCESS_KEY_ID=
// SECRET_ACCESS_KEY=
// AWS_S3_REGION=
// AWS_DEFAULT_S3_BUCKET=

// MAIL_HOST=maildev
// MAIL_PORT=1025
// MAIL_USER=
// MAIL_PASSWORD=
// MAIL_IGNORE_TLS=true
// MAIL_SECURE=false
// MAIL_REQUIRE_TLS=false
// [email protected]
// MAIL_DEFAULT_NAME=Api
// MAIL_CLIENT_PORT=1080

// AUTH_JWT_SECRET=secret
// AUTH_JWT_TOKEN_EXPIRES_IN=15m
// AUTH_REFRESH_SECRET=secret_for_refresh
// AUTH_REFRESH_TOKEN_EXPIRES_IN=3650d

// FACEBOOK_APP_ID=
// FACEBOOK_APP_SECRET=

// GOOGLE_CLIENT_ID=
// GOOGLE_CLIENT_SECRET=

// APPLE_APP_AUDIENCE=[]

// TWITTER_CONSUMER_KEY=
// TWITTER_CONSUMER_SECRET=

// WORKER_HOST=redis://redis:6379/1

// DATABASE_URL="postgresql://root:secret@postgres:5432/api"
// SHADOW_DATABASE_URL="postgresql://root:secret@shadow-postgres:5432/shadow"`;

export const content = `NODE_ENV=development
APP_PORT=3000
APP_NAME="NestJS API"
Expand All @@ -7,9 +74,11 @@ APP_HEADER_LANGUAGE=x-custom-lang
FRONTEND_DOMAIN=http://localhost:3000
BACKEND_DOMAIN=http://localhost:3000
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
DATABASE_TYPE=postgres
DATABASE_HOST=postgres
DATABASE_PORT=5432
DATABASE_PORT=7000
DATABASE_USERNAME=root
DATABASE_PASSWORD=secret
DATABASE_NAME=api
Expand All @@ -21,11 +90,11 @@ DATABASE_CA=
DATABASE_KEY=
DATABASE_CERT=
SHADOW_DATABASE_PORT=5431
SHADOW_DATABASE_PORT=7001
SHADOW_DATABASE_USERNAME=root
SHADOW_DATABASE_PASSWORD=secret
SHADOW_DATABASE_NAME=shadow
SHADOW_DATABASE_HOST=localhost
# Support "local", "s3"
FILE_DRIVER=local
Expand Down Expand Up @@ -63,5 +132,20 @@ TWITTER_CONSUMER_SECRET=
WORKER_HOST=redis://redis:6379/1
DATABASE_URL="postgresql://root:secret@postgres:5432/api"
SHADOW_DATABASE_URL="postgresql://root:secret@shadow-postgres:5432/shadow"`;
DATABASE_URL="postgresql://root:secret@localhost:5432/api"
SHADOW_DATABASE_URL="postgresql://root:secret@localhost:5432/shadow"
FUSIONAUTH_APPLICATION_ID="f0ddb3f6-091b-45e4-8c0f-889f89d4f5da"
FUSIONAUTH_SAMARTH_HP_APPLICATION_ID=f18c3f6f-45b8-4928-b978-a9906fd03f22
FUSIONAUTH_HP_ADMIN_CONSOLE_APPLICATION_ID=
FUSIONAUTH_BASE_URL="http://localhost:9011"
FUSIONAUTH_API_KEY="bla"
ENCRYPTION_KEY="bla"
FUSIONAUTH_ADMIN_SEARCH_APPLICATION_IDS=["1","2"]
FUSIONAUTH_APP_MEMORY=
FUSIONAUTH_APP_RUNTIME_MODE=development
# Redis
REDIS_HOST=localhost
CACHE_PORT=8000`;
44 changes: 44 additions & 0 deletions src/lib/application/files/ts/docker-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

if [ -f ".env" ]; then
mv .env .env.bak
fi

## move env-example to .env
cp env-example .env
docker compose up -d

LOGGING_DIR="./services/logging"

if [ -d "$LOGGING_DIR" ]; then

cd "$LOGGING_DIR"

docker compose up -d

cd ../..

fi

MONITOR_DIR="./services/monitor"

if [ -d "$MONITOR_DIR" ]; then
cd "$MONITOR_DIR"

docker compose up -d

cd ../..

fi

TEMPORAL_DIR="./services/temporal"

if [ -d "$TEMPORAL_DIR" ]; then

cd "$TEMPORAL_DIR"

docker compose up -d

cd ../..

fi
9 changes: 5 additions & 4 deletions src/lib/application/files/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"start:docker": "chmod +x docker-start.sh && ./docker-start.sh"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.3.0",
"@samagra-x/stencil": "^0.0.5",
"@samagra-x/stencil": "^0.0.6",
"@types/multer": "^1.4.11",
"fastify": "^4.25.2",
"fastify-multer": "^2.0.3",
Expand All @@ -36,8 +37,8 @@
"rxjs": "^7.8.1"
},
"devDependencies": {
"@samagra-x/stencil-cli": "0.0.3",
"@samagra-x/schematics": "0.0.3",
"@samagra-x/stencil-cli": "0.0.4",
"@samagra-x/schematics": "0.0.4",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fixtures/files/ts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:18.16.1-alpine

RUN apk add --no-cache bash
RUN npm i -g @nestjs/cli typescript ts-node
RUN npm i -g @nestjs/cli @samagra-x/stencil-cli typescript ts-node

COPY package*.json /tmp/app/
RUN cd /tmp/app && npm install
Expand Down
20 changes: 15 additions & 5 deletions src/lib/fixtures/files/ts/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ services:
POSTGRES_PASSWORD: ${SHADOW_DATABASE_PASSWORD}
POSTGRES_DB: ${SHADOW_DATABASE_NAME}

api:
build:
context: .
dockerfile: Dockerfile
cache:
image: redis:6.2-alpine
restart: always
ports:
- 4000:4000
- '${CACHE_PORT}:6379'
command: redis-server --save 20 1
volumes:
- cache:/data

# api:
# build:
# context: .
# dockerfile: Dockerfile
# ports:
# - 3000:3000
volumes:
fa-config:
cache:
networks:
default:
7 changes: 7 additions & 0 deletions src/lib/logging/env-content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const content = `DATABASE_PORT=7003
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=postgres
DATABASE_NAME=postgres
ELASTIC_VERSION=8.11.3
CACHE_PORT=8001
`;
128 changes: 128 additions & 0 deletions src/lib/logging/files/ts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
services:
postgres:
image: postgres:15.3-alpine
ports:
- ${DATABASE_PORT}:5432
volumes:
- ./.data/db:/var/lib/postgresql/data
environment:
POSTGRES_USER: ${DATABASE_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres']
interval: 5s
timeout: 5s
retries: 5

setup:
profiles:
- setup
build:
context: ./setup
args:
ELASTIC_VERSION: ${ELASTIC_VERSION}
init: true
volumes:
- ./setup/entrypoint.sh:/entrypoint.sh:ro,Z
- ./setup/lib.sh:/lib.sh:ro,Z
- ./setup/roles:/roles:ro,Z
environment:
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD:-}
LOGSTASH_INTERNAL_PASSWORD: ${LOGSTASH_INTERNAL_PASSWORD:-}
KIBANA_SYSTEM_PASSWORD: ${KIBANA_SYSTEM_PASSWORD:-}
METRICBEAT_INTERNAL_PASSWORD: ${METRICBEAT_INTERNAL_PASSWORD:-}
FILEBEAT_INTERNAL_PASSWORD: ${FILEBEAT_INTERNAL_PASSWORD:-}
HEARTBEAT_INTERNAL_PASSWORD: ${HEARTBEAT_INTERNAL_PASSWORD:-}
MONITORING_INTERNAL_PASSWORD: ${MONITORING_INTERNAL_PASSWORD:-}
BEATS_SYSTEM_PASSWORD: ${BEATS_SYSTEM_PASSWORD:-}
networks:
- elk
depends_on:
- elasticsearch

elasticsearch:
build:
context: ./elasticsearch
args:
ELASTIC_VERSION: ${ELASTIC_VERSION}
volumes:
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro,Z
- elasticsearch:/usr/share/elasticsearch/data:Z
ports:
- 9200:9200
- 9300:9300
environment:
node.name: elasticsearch
ES_JAVA_OPTS: -Xms512m -Xmx512m
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD:-}
discovery.type: single-node
networks:
- elk
restart: unless-stopped

logstash:
build:
context: ./logstash
args:
ELASTIC_VERSION: ${ELASTIC_VERSION}
volumes:
- ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro,Z
- ./logstash/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf:ro,Z
ports:
- 5044:5044
- 50000:50000/tcp
- 50000:50000/udp
- 9600:9600
environment:
LS_JAVA_OPTS: -Xms256m -Xmx256m
LOGSTASH_INTERNAL_PASSWORD: ${LOGSTASH_INTERNAL_PASSWORD:-}
networks:
- elk
depends_on:
- elasticsearch
restart: unless-stopped

kibana:
build:
context: ./kibana
args:
ELASTIC_VERSION: ${ELASTIC_VERSION}
volumes:
- ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml:ro,Z
ports:
- 5601:5601
environment:
KIBANA_SYSTEM_PASSWORD: ${KIBANA_SYSTEM_PASSWORD:-}
networks:
- elk
depends_on:
- elasticsearch
restart: unless-stopped

logstash-axiom:
image: opensearchproject/logstash-oss-with-opensearch-output-plugin:7.16.2
ports:
- '12201:12201/udp'
volumes:
- ./logstash/pipeline/axiom.conf:/usr/share/logstash/pipeline/logstash.conf
command: logstash -f /usr/share/logstash/pipeline/

cache:
image: redis:6.2-alpine
restart: always
ports:
- '${CACHE_PORT}:6379'
command: redis-server --save 20 1
volumes:
- cache:/data

networks:
elk:
driver: bridge
default:

volumes:
elasticsearch:
cache:
driver: local
Loading

0 comments on commit 11e42e3

Please sign in to comment.