Skip to content

Commit

Permalink
Merge pull request #56 from Manik2708/CI
Browse files Browse the repository at this point in the history
some edits
  • Loading branch information
Manik2708 authored Jun 2, 2024
2 parents 20750cc + f69e0f2 commit 13aab78
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ node_modues
.git
.dockerignore
dist
test
docs
.vscode
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM node:18-alpine
RUN npm install -g @nestjs/cli
WORKDIR /usr/src/app
COPY . .
RUN sed -i 's/RUNNING_ON_DOCKER=false/RUNNING_ON_DOCKER=true/g' .env
RUN npm install
RUN npm run build
CMD ["node","dist/main.js"]
Expand Down
File renamed without changes.
30 changes: 25 additions & 5 deletions JenkinsFile
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,34 @@ pipeline{
steps{
sh 'npm run test:e2e'
}
}
}
stage('Close testing enviornment'){
steps{
dir('scripts'){
sh 'chmod +x docker_compose_down.sh'
sh './docker_compose_down.sh'
}
}
}
stage('Check for circular dependencies'){
sh 'npx madge --circular --extensions ts ./'
}
stage('Start docker compose for build'){
steps{
sh 'docker compose up -d --no-color --wait'
}
}
stage('Build server'){
steps{
sh 'chmod +rwx .env'
sh 'sed -i \'s/RUNNING_ON_DOCKER=false/RUNNING_ON_DOCKER=true/g\' .env'
sh 'npm run build'
}
}
}
post{
always{
dir('scripts'){
sh 'chmod +x docker_compose_down.sh'
sh './docker_compose_down.sh'
}
sh 'docker compose down'
}
}
}
File renamed without changes.
55 changes: 33 additions & 22 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
version: "3"
services:
web:
build:
context: .
dockerfile: Dockerfile
user: "node:node"
ports:
- "3000:3000"
depends_on:
- redis
- rabbitmq
- cassandra
redis:
redis-testing:
image: redis:alpine
container_name: client
command: ["redis-server", "--bind", "0.0.0.0", "--port", "6379"]
ports:
- "6390:6379"
command: ["redis-server", "--bind", "redis", "--port", "6379"]
healthcheck:
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
interval: 10s
timeout: 3s
retries: 3
start_period: 20s
container_name: client
rabbitmq:
image: rabbitmq
container_name: rabbit
ports:
- "5674:5762"
- "15674:15672"
- "5670:5672"
- "15673:15672"
container_name: rabbit
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 10s
timeout: 3s
retries: 3
start_period: 20s
cassandra:
image: cassandra:latest
ports:
- "7000:7000"
- "9042:9042"
restart: always
- "9000:9042"
container_name: cassandra
healthcheck:
test: ["CMD","nodetool", "status"]
interval: 15s
interval: 10s
timeout: 10s
retries: 10
start_period: 20s
mongodb:
image: mongo:latest
ports:
- "27019:27017"
container_name: mongodb
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
interval: 10s
timeout: 10s
retries: 10
container_name: cassandra
start_period: 20s
13 changes: 13 additions & 0 deletions scripts/mongo_sb_secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cd ..

touch mongo_username

touch mongo_password

grep -i "DATABASE_PASSWORD" .env | tee >> mongo_password

grep -i "DATABASE_USERNAME" .env | tee >> mongo_username

docker secret create mongo_username mongo_username

docker secret create mongo_password mongo_password
2 changes: 1 addition & 1 deletion src/Queues/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class CreateQueue {
? 'amqp://localhost:5673'
: TestingRabbitLink
: IfRunningOnDocker == 'true'
? 'amqp://rabbit:5672'
? 'amqp://localhost:5670'
: 'amqp://rabbit';
amqp.connect(
rabbitMqConnectionString,
Expand Down
7 changes: 4 additions & 3 deletions src/Services/connect_to_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ConnectToServices {

if (IfRunningOnDocker == 'true') {
client = createClient({
url: 'redis://client:6379',
url: 'redis://0.0.0.0:6390',
});
} else {
client = createClient({});
Expand All @@ -22,8 +22,9 @@ export class ConnectToServices {
let casClient: CasClient;
if (IfRunningOnDocker == 'true') {
casClient = new CasClient({
contactPoints: ['cassandra:9042'],
localDataCenter: 'datacenter1',
contactPoints: ['localhost'],
localDataCenter: 'datacenter1',
protocolOptions: { port: 9000 },
});
} else {
casClient = new CasClient({
Expand Down
9 changes: 6 additions & 3 deletions src/enviornment_variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ const parseStringToNumber = (text: string | undefined): number | undefined => {
return undefined;
}
};

export const IfRunningOnDocker = process.env.RUNNING_ON_DOCKER!;
export const DatabaseUrl: string =
'mongodb+srv://' +
process.env.DATABASE_USERNAME || process.env.DATABASE_PASSWORD ==
null||undefined||process.env.DATABASE_USERNAME!.length==0||process.env.DATABASE_PASSWORD.length==0?
IfRunningOnDocker=='true'?'mongodb://localhost:27019':
process.env.MONGO_TESTING_LINK!:
'mongodb+srv://' +
encodeURIComponent(process.env.DATABASE_USERNAME!) +
':' +
encodeURIComponent(process.env.DATABASE_PASSWORD!) +
Expand All @@ -26,7 +30,6 @@ export const NodemailerSenderEmail: string =
export const NodemailerSenderPassword: string =
process.env.NODEMAILER_SENDER_PASSWORD!;
export const NodemailerService: string = process.env.NODEMAILER_SPMTP_SERVICE!;
export const IfRunningOnDocker = process.env.RUNNING_ON_DOCKER!;
export const MongoTestingLink = 'mongodb://localhost:27018';
export const RedisTestingLink: string | undefined =
process.env.TESTING_REDIS_LINK;
Expand Down

0 comments on commit 13aab78

Please sign in to comment.