Skip to content

Commit

Permalink
added redis
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Mar 21, 2024
1 parent ede2e23 commit 8af569b
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 29 deletions.
6 changes: 5 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ AWS_SECRET_ACCESS_KEY=
AWS_S3_BUCKET_NAME=
AWS_REGION=
DOMAIN=https://culero.com/
PROFILES_DIRECTORY=
PROFILES_DIRECTORY=

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
7 changes: 4 additions & 3 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The backend is a NestJS based application. It uses PostgreSQL as a database and

- **Node.js** installed
- **pnpm** installed
- **PostgreSQL** up and running on your machine on port `5432`. If you change this, or you are using a different database, you will need to change the connection string in the `.env` file.
- **PostgreSQL** up and running on your machine on port `5432`. If you change this, or you are using a different database, you will need to change the connection string in the `.env` file. Alternatively, you can use the docker compose file to run the database.
- **Redis** up and running on your machine on port `6379`. If you change this, you will need to change the connection string in the `.env` file. You can also use the docker compose file to run the Redis server.
- Port `4200` should be free. This will be used by the backend to run the server.
- **AWS S3 bucket** for storing the images. This is optional, but if you want to use the image upload feature, you will need to fill in the required values in the `.env` file.
- **nest cli** installed globally. If not, you can install it by running `pnpm i -g @nestjs/cli`
Expand All @@ -34,10 +35,10 @@ The backend is a NestJS based application. It uses PostgreSQL as a database and
pnpm install
```

4. Make sure your database is running. If you would like to use docker, run the following command:
4. Make sure your database and redis server are up and running. If you don't have them installed, you can run them in a container using the following command:

```sh
docker run --name culero-psql --network host -e POSTGRES_PASSWORD=password -d postgres
docker compose up -d
```

5. For Prisma to work properly, generate the types
Expand Down
13 changes: 12 additions & 1 deletion backend/docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: '3.9'
# The containers that compose the project
services:
db:
image: postgres:13
image: postgres:14
restart: always
container_name: integration-tests-prisma
ports:
Expand All @@ -16,6 +16,17 @@ services:
networks:
- culero-test

redis:
image: redis:6
restart: always
container_name: culero-redis
environment:
REDIS_PASSWORD: password
ports:
- '6379:6379'
networks:
- culero-dev

networks:
culero-test:
driver: bridge
40 changes: 40 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Set the version of docker compose to use
version: '3.9'

# The containers that compose the project
services:
db:
image: postgres:14
restart: always
container_name: culero-psql
ports:
- '5432:5432'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: culero
networks:
- culero-dev
volumes:
- db-data:/var/lib/postgresql/data

redis:
image: redis:6
restart: always
container_name: culero-redis
ports:
- '6379:6379'
networks:
- culero-dev
volumes:
- cache-data:/data

networks:
culero-dev:
driver: bridge

volumes:
db-data:
driver: local
cache-data:
driver: local
8 changes: 7 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "pnpm run test:unit && pnpm run test:e2e",
"test:unit": "pnpm db:generate-types && pnpx jest --config=jest.config.json",
"test:e2e:prepare": "docker compose -f docker-compose-test.yml up -d && pnpm db:generate-types && NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"test:e2e:prepare": "docker compose down && docker compose -f docker-compose-test.yml up -d && pnpm db:generate-types && NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"test:e2e": "pnpm run test:e2e:prepare && NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpx jest --config=jest.e2e-config.json --run-in-band --coverage --coverageDirectory=./coverage-e2e --coverageReporters=json && pnpm run test:e2e:teardown",
"test:e2e:teardown": "docker compose -f docker-compose-test.yml down",
"db:generate-types": "pnpm dlx prisma generate --schema=src/prisma/schema.prisma",
Expand All @@ -30,6 +30,7 @@
"@arendajaelu/nestjs-passport-apple": "^2.0.2",
"@aws-sdk/client-s3": "^3.534.0",
"@aws-sdk/core": "^3.533.0",
"@nestjs/cache-manager": "^2.2.1",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.0.0",
Expand All @@ -41,23 +42,28 @@
"@prisma/client": "^5.10.2",
"aws-sdk": "^2.1577.0",
"axios": "^1.6.8",
"cache-manager": "^5.4.0",
"cache-manager-redis-store": "^2.0.0",
"cheerio": "1.0.0-rc.12",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"crypto-js": "^4.2.0",
"install": "^0.13.0",
"jest-mock-extended": "^3.0.5",
"nodemailer": "^6.9.12",
"passport-facebook": "^3.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-linkedin-oauth2": "^2.0.0",
"prisma": "^5.10.2",
"redis": "^4.6.13",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/cache-manager-redis-store": "^2.0.4",
"@types/crypto-js": "^4.2.2",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
Expand Down
Loading

0 comments on commit 8af569b

Please sign in to comment.