This project uses Fastify, Prisma, and Docker. This guide will help you set up and run the application using Docker.
For API usage you can go this link: API Usage
Make sure you have the following installed on your machine:
- Docker
- Docker Compose
git clone https://github.com/hafidhsajid/be-assignment.git
cd be-assignemt
Create a .env file in the root of the project with the following content:
DATABASE_URL=postgresql://postgres:password@db:5432/mydb
JWT_SECRET=SecretJWT
Run the following command to build the Docker images and start the containers:
docker-compose up --build
This command will:
- Build the Docker image for the Fastify application using the Dockerfile.
- Start the PostgreSQL database and Fastify application services.
- Apply Prisma migrations and seed the database.
If you need to manually apply migrations and seed data (e.g., after modifying the database schema), you can run:
docker-compose run --rm app npm run migrate
docker-compose run --rm app npm run seed
npm run migrate will apply any pending Prisma migrations. npm run seed will seed the database with initial data. ###4. Access the Application Once the containers are running, you can access the Fastify application at
http://localhost:3000
To stop the application and remove the containers, run:
docker-compose down
Check Logs: If you encounter issues, check the logs for more information:
docker-compose logs
Restart Services: To restart the services, you can use:
docker-compose restart
Additional Commands Rebuild and Start: To rebuild the Docker image and start the application:
docker-compose up --build
Remove Volumes: To remove Docker volumes, which might be useful for cleaning up:
docker-compose down -v
This `README.md` provides comprehensive instructions for setting up and running your Dockerized Fastify application, including how to build, run, and manage Docker containers, apply migrations, and handle troubleshooting. Adjust the commands and instructions as needed for your specific project details and requirements.