Merge branch 'gitlabci' into 'main'
Gitlabci See merge request sbriat/user!8
This commit is contained in:
commit
cc7aace334
|
@ -0,0 +1,24 @@
|
|||
image: docker:20.10.22
|
||||
|
||||
stages:
|
||||
- test
|
||||
|
||||
##############
|
||||
# TEST STAGE #
|
||||
##############
|
||||
|
||||
integration-test:
|
||||
stage: test
|
||||
image: docker/compose:latest
|
||||
variables:
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
services:
|
||||
- docker:dind
|
||||
script:
|
||||
- docker-compose -f docker-compose.ci.yml --env-file ci/.env.ci up -d
|
||||
- sh ci/wait-up.sh
|
||||
- docker exec -t v3-user sh -c "npm run test:integration:ci"
|
||||
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
|
||||
rules:
|
||||
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH || $CI_COMMIT_MESSAGE =~ /--check/ || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
||||
when: always
|
|
@ -0,0 +1,15 @@
|
|||
# SERVICE
|
||||
SERVICE_URL=0.0.0.0
|
||||
SERVICE_PORT=5001
|
||||
|
||||
# PRISMA
|
||||
DATABASE_URL="postgresql://user:user@db:5432/user?schema=public"
|
||||
|
||||
# RABBIT MQ
|
||||
RMQ_URI=amqp://broker:5672
|
||||
|
||||
# MESSAGE BROKER
|
||||
BROKER_IMAGE=rabbitmq:3-alpine
|
||||
|
||||
# POSTGRES
|
||||
POSTGRES_IMAGE=postgres:15.0
|
|
@ -0,0 +1,29 @@
|
|||
###################
|
||||
# BUILD FOR CI TESTING
|
||||
###################
|
||||
|
||||
FROM node:18-alpine3.16
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# A wildcard is used to ensure both package.json AND package-lock.json are copied
|
||||
COPY package*.json ./
|
||||
|
||||
# Install app dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Bundle app source
|
||||
COPY . .
|
||||
|
||||
# Generate prisma client
|
||||
RUN npx prisma generate
|
||||
|
||||
# Create a "dist" folder
|
||||
RUN npm run build
|
||||
|
||||
# Run unit tests
|
||||
RUN npm run test:unit:ci
|
||||
|
||||
# Start the server
|
||||
CMD [ "node", "dist/main.js" ]
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
testlog() {
|
||||
docker logs v3-user-db-test | grep -q "database system is ready to accept connections"
|
||||
}
|
||||
|
||||
testlog 2> /dev/null
|
||||
while [ $? -ne 0 ];
|
||||
do
|
||||
sleep 5
|
||||
echo "Waiting for Test DB to be up..."
|
||||
testlog 2> /dev/null
|
||||
done
|
|
@ -0,0 +1,41 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
api:
|
||||
container_name: v3-user
|
||||
build:
|
||||
dockerfile: ci/Dockerfile
|
||||
context: .
|
||||
env_file:
|
||||
- ci/.env.ci
|
||||
ports:
|
||||
- 5001:5001
|
||||
depends_on:
|
||||
- db
|
||||
- broker
|
||||
networks:
|
||||
- v3-network
|
||||
|
||||
db:
|
||||
container_name: v3-user-db-test
|
||||
image: ${POSTGRES_IMAGE}
|
||||
environment:
|
||||
POSTGRES_DB: user
|
||||
POSTGRES_USER: user
|
||||
POSTGRES_PASSWORD: user
|
||||
ports:
|
||||
- 5601:5432
|
||||
networks:
|
||||
- v3-network
|
||||
|
||||
broker:
|
||||
container_name: v3-broker
|
||||
image: ${BROKER_IMAGE}
|
||||
ports:
|
||||
- 5672:5672
|
||||
networks:
|
||||
- v3-network
|
||||
|
||||
networks:
|
||||
v3-network:
|
||||
name: v3-network
|
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
|
@ -2,7 +2,7 @@
|
|||
"name": "mobicoop-v3-user",
|
||||
"version": "0.0.1",
|
||||
"description": "Mobicoop V3 User Service",
|
||||
"author": "Mobicoop",
|
||||
"author": "sbriat",
|
||||
"private": true,
|
||||
"license": "AGPL",
|
||||
"scripts": {
|
||||
|
@ -14,13 +14,16 @@
|
|||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "npm run migrate-test && dotenv -e .env.test jest",
|
||||
"test:unit": "jest --testPathIgnorePatterns 'integration' --verbose",
|
||||
"test:integration": "npm run migrate-test && dotenv -e .env.test -- jest --testPathPattern 'integration' --verbose",
|
||||
"test:cov": "npm run migrate-test && dotenv -e .env.test -- jest --coverage",
|
||||
"test": "npm run migrate:test && dotenv -e .env.test jest",
|
||||
"test:unit": "jest --testPathPattern 'tests/unit/' --verbose",
|
||||
"test:unit:ci": "jest --testPathPattern 'tests/unit/' --coverage",
|
||||
"test:integration": "npm run migrate:test && dotenv -e .env.test -- jest --testPathPattern 'tests/integration/' --verbose",
|
||||
"test:integration:ci": "npm run migrate:test:ci && dotenv -e ci/.env.ci -- jest --testPathPattern 'tests/integration/'",
|
||||
"test:cov": "npm run migrate:test && dotenv -e .env.test -- jest --coverage",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"migrate": "docker exec v3-auth sh -c 'npx prisma migrate dev'",
|
||||
"migrate-test": "dotenv -e .env.test -- npx prisma migrate dev --name postgres-init"
|
||||
"migrate": "docker exec v3-user sh -c 'npx prisma migrate dev'",
|
||||
"migrate:test": "dotenv -e .env.test -- npx prisma migrate deploy",
|
||||
"migrate:test:ci": "dotenv -e ci/.env.ci -- npx prisma migrate deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
"@automapper/classes": "^8.7.7",
|
||||
|
@ -35,11 +38,18 @@
|
|||
"@nestjs/cqrs": "^9.0.1",
|
||||
"@nestjs/microservices": "^9.2.1",
|
||||
"@nestjs/platform-express": "^9.0.0",
|
||||
"@types/node": "^16.0.0",
|
||||
"@prisma/client": "^4.7.1",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^5.0.0",
|
||||
"dotenv-cli": "^6.0.0",
|
||||
"dotenv-cli": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^9.0.0",
|
||||
"@nestjs/schematics": "^9.0.0",
|
||||
"@nestjs/testing": "^9.0.0",
|
||||
"@types/jest": "^29.2.5",
|
||||
"@types/node": "^18.11.18",
|
||||
"eslint": "^8.0.1",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
|
@ -50,9 +60,9 @@
|
|||
"supertest": "^6.1.3",
|
||||
"ts-jest": "28.0.8",
|
||||
"ts-loader": "^9.2.3",
|
||||
"ts-node": "^10.0.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "4.1.0",
|
||||
"typescript": "^4.7.4"
|
||||
"typescript": "^4.9.4"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
|
|
|
@ -32,6 +32,7 @@ import { UserProfile } from './mappers/user.profile';
|
|||
},
|
||||
],
|
||||
uri: configService.get<string>('RMQ_URI'),
|
||||
connectionInitOptions: { wait: false },
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue