Node.js microservice for user watchlist.
OpenAPI documentation available at http://localhost:3002/api.
For accessing secured endpoints add your access_token provided to you at login to the Authorization header.
npm install# development
npm run start
# watch mode
npm run start:dev
# production mode
npm run start:prodIf any changes are made to the schema.prisma file, run the following command to update the database. I creates a migration, updates the database (also seeds?), and updates the Prisma client.
npm run prisma:migrate:devIf you only want to seed the database, run the following command.
npm run prisma:seedTo update the Prisma client run the following command.
npm run prisma:client# unit tests
npm run test
# e2e tests
npm run test:e2e
# test coverage
npm run test:covTo run the app in a docker container, run the following commands.
docker network create cinepik-network
docker run -d --name cinepik-watchlist-db --env-file .env --network cinepik-network -p 5432:5432 postgres:15.5-alpine
docker build -t cinepik-watchlist .
docker run -d -t --env-file .env --network cinepik-network -p 3001:3001 cinepik-watchlistTo manually upload the image to Docker Hub, run the following commands.
docker build -t cinepik-watchlist .
docker tag cinepik-watchlist:latest <dockerhub_username>/cinepik-watchlist:latest
docker push <dockerhub_username>/cinepik-watchlist:latestYou can also setup the database and application with docker-compose.
# Run the database and application
docker-compose up --build db app
# Trigger database seeding
docker-compose up --build seed
docker-compose downCreate config map for keycloak
kubectl create configmap keycloak-config --from-literal=KEYCLOAK_BASE_URL="http://cinepik-keycloak" --from-literal=KEYCLOAK_CLIENT_ID="nest-auth" --from-literal=KEYCLOAK_PORT=8080 --from-literal=KEYCLOAK_REALM="cinepik"Create secret for keycloak
kubectl create secret generic keycloak-credentials --from-literal=KEYCLOAK_ADMIN="admin" --from-literal=KEYCLOAK_ADMIN_PASSWORD="<REPLACE_ME>" --from-literal=KEYCLOAK_CLIENT_SECRET="<REPLACE_ME>" --from-literal=KEYCLOAK_REALM_RSA_PUBLIC_KEY="<REPLACE_ME>"Create a Secret for the database url environment variable in the deployment file. Replace the value in the <> with the appropriate value.
kubectl create secret generic database-credentials --from-literal=DATABASE_URL=<db_url>Create a Secret for the movies API environment variable in the deployment file. Replace the value in the <> with the appropriate value. More info here.
kubectl create secret generic watchlist-credentials --from-literal=MOVIES_RAPID_API_KEY=<REPLACE_ME>We can create the deployment and service.
kubectl apply -f k8s/cinepik-watchlist.yml
kubectl apply -f k8s/cinepik-watchlist-svc.ymlTo manually seed the database in Kubernetes, run the following command, which create a Job that runs the seed script.
kubectl apply -f k8s/seed-job.ymlkubectl get pods
kubectl delete deployment cinepik-watchlist-deployment
kubectl delete configmap <configmap name>
kubectl rollout restart deployment/cinepik-watchlist-deployment
kubectl logs <pod-id>
kubectl describe secret <secret-name>
kubectl get secret <secret-name>
kubectl get service
kubectl describe pods