Setup Node and PSQL setup using Docker Compose

ยท

2 min read

Key Features

Before diving into the setup instructions, let's highlight some of the key features of this repository:

  • One-Click Setup: Simplifies the initialization of your local development environment.

  • Comprehensive Instructions: Detailed steps ensure that even those new to SRE can follow along.

  • Automation Scripts: Utilizes scripts to automate the setup process, reducing the potential for human error.

Now let's make the local development setup quicker by using docker-compose and trigger server and DB containers using a single make command

  • First let us update the .env file with appropriate values since when we create containers using docker-compose

      NODE_ENV=development
      DB_USER=postgres
      DB_PASSWORD=postgres
      DB_HOST=db
      DB_PORT=5432
      DB_DATABASE=postgres
    
  • Please refer the compose.yaml for creating DB container first and checking the health of postgresql DB which then triggers migrations and starts the web-server.

    • Server depends on DB service:

    • Health Check on DB:

  • The following is the updated Dockerfile for applying migrations before starting the web server

      ENTRYPOINT ["sh", "-c", "npx knex migrate:latest && npm start"]
    
  • Run make start_app for starting the app (web-server + db)

  • Make a the following curl request and open http://localhost:3000/v1/students to view all students as response

curl -X POST http://localhost:3000/v1/students \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "age": 23, "department": "Arts"}'

By leveraging Docker compose and automation scripts, this one-click setup ensures that developers can get up and running quickly, focusing on what truly matters โ€“ building and testing their applications.

ย