This tutorial is about how to run a Nest Postgres PgAdmin on docker and Expo on our local using bolt. Below's the video showing how to run this tutorial.
Table of Contents
Objectives
Project Structure
Initialising the project using Bolt
Adding service as a Bolt Service
Running the Project
Running the Project on Docker
Running the Project on Local
Listing Bolt Services
Monitoring Service Logs
Stopping Your Project
Repo Link
Objectives
Here we have created a project where we have one service called todofe which is a Expo app.
Our Main objectives are:
Run this project using bolt in local machine.
Run this project using bolt in docker.
Project Structure
The project structure of our app is as follows:
# Below's the directory structure of our project.
nest-expo-postgres-pgadmin/
╰─➤ services/
╰─➤ pgadmin/
╰─➤ bolt.service.yaml
╰─➤ postgres/
╰─➤ bolt.service.yaml
╰─➤ todo-backend/
╰─➤ nest-generator files...
╰─➤ bolt.service.yaml
╰─➤ TodoApp/
╰─➤ expo-generator files...
╰─➤ bolt.service.yaml
╰─➤ .boltignore
╰─➤ .env
╰─➤ .env.tpl
╰─➤ 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 nest-expo-postgres-pgadmin
$ bolt init
It has created a bolt.yaml file in our project's root directory.
envfile: .env.tpl
project_id:"1690896394872"
project_name: nest-expo-postgres-pgadmin
services:null
ingress:null
Adding service as a Bolt Service
Now, in order to add service as a service in bolt we have executed the following command:
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 adding service as a service
envfile: .env.tpl
project_id:"1690896394872"
project_name: nest-expo-postgres-pgadmin
services:
todobe:
path: services/backend
pgadmin:
path: services/pgadmin
postgres:
path: services/postgres
todofe:
path: services/webui
ingress:null
Each services has their own bolt.service.yaml file, here we have configured it as per our requirement.
We have configured run.dockerfile and build.dockerfile for PGAdmin Postgres and Nest to run them in Docker. And Expo app to run on Local.
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
# 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 each serivce. 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 four services configured to run on docker as well as local for your reference.
We have introduced a depends_on key within the webui service, establishing a dependency on the todobe service. This ensures that our todofe will only be brought up once todobe is running.
Given that both the todobe and pgadmin services rely on the postgres service, it follows that the pgadmin and todobe services will be initiated subsequent to the availability of the postgres service.
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
...
"todofe"service is up on local platform
"todobe"service is up on docker platform
"pgadmin"service is up on docker platform
"postgres"service is up on docker platform
By default, the configuration in bolt.yaml file is to run the project on local machine.
Running bolt up command make internal checks value defined against default_service_runner index in each service's bolt.service.yaml file.
Now if you run bolt up command it will run the todofe service on local & todobackend , postgres & pgadmin service on docker.
Listing Bolt Services
You can also see the list of services in your bolt project and their statuses using the service:list command.