This tutorial is about how to run a Next.js Postgress and PgAdmin in a project using bolt on virtual machine environment and we will also setup Bolt Ingress with our microservices.
Table of Contents
Objectives
Project Structure
Initialising the project using Bolt
Adding all the services as Bolt service
Adding Ingress
Running the Project
Running the Project on Virtual Machine
Listing Bolt Services
Monitoring Service Logs
Stopping Your Project
Repo Link
Objectives
Here we have created a project where we have three folder named todo-next, postgres and pgadmin which has a next app with postgres and pgadmin as services.
Our Main objectives are:
Run this project using bolt in local machine.
Run this project using bolt in docker.
Project Structure
# Below's the directory structure of our project.
next-postgres-pgadmin/
╰─➤ pgadmin/...
╰─➤ postgres/...
╰─➤ todo-next/...
╰─➤ .env
╰─➤ .env.tpl
╰─➤ bolt.nginx.conf
╰─➤ bolt.yaml
╰─➤ Readme.md
Initialising the project using Bolt
At first we have initialised the project by running bolt init command to create bolt.yaml file.
$ cd next-postgres-pgadmin
$ bolt init
It has created a bolt.yaml file in our project's root directory.
envfile: .env.tpl
project_id:"1690964884913"
project_name: next-postgres-pgadmin
services:null
ingress:null
Adding all the services as Bolt service
Now in order to add each and every services we have executed the following commands:
Bolt service:add command runs and automatically detects the type of service you are using and creates a bolt.service.yaml template init & includes the same into your bolt.yaml file.
# This is how bolt.yaml file looks after executing the above commands
envfile: .env.tpl
project_id:"1690964884913"
project_name: next-postgres-pgadmin
services:
todonext:
path: todo-next
postgres:
path: postgres
pgadmin:
path: pgadmin
ingress:null
Each services has their own bolt.service.yaml file, here we have configured it as per our requirement.
Also we have configured run.dockerfile and build.dockerfile for todonuxt, pgadmin and postgres to run them in docker.
Adding Ingress
We have added ingress configuration for our project inside bolt.yaml file to access our services from outside.
# This is how bolt.yaml file looks finally after adding ingress configuration
envfile: .env.tpl
project_id:"1690964884913"
project_name: next-postgres-pgadmin
services:
todonext:
path: todo-next
postgres:
path: postgres
pgadmin:
path: pgadmin
ingress:
-domain: nextjs.local.gluestack.app
port:8000
options:
-location: /
rewrite_key: ^/(.*)
rewrite_value: /$1
proxy_pass: http://host.docker.internal:3000
-domain: admin.local.gluestack.app
port:8001
options:
-location: /
rewrite_key: ^/(.*)
rewrite_value: /$1
proxy_pass: http://host.docker.internal:8080
Running the Project
Now, let's run our services using Bolt.
# The following command will run the service as per the configuration in bolt.yaml file
$ bolt up
Now this command will first run the services as per their configurations inside bolt.service.yaml for each service. After that, bolt will create a nginx configuration file named as bolt.nginx.conf in your project's root directory and run the Nginx server on your host machine's Docker.
Running the Project on Docker
Below's our bolt.service.yaml files for all three services configured to run on virtual machine for your reference.
# This is bolt.service.yaml file for PGAdmin
container_name: pgadmin
stateless:true
default_service_runner: docker
service_discovery_offset:
-8080
supported_service_runners:
- local
- docker
service_runners:
local:
envfile: .env
build: npm run install --workspaces --if-present && npm run dev