Add Bolt to Existing Project

Table of Contents

  • Adding Bolt to a project
  • Adding a Project Service as Bolt Service
  • Running Project via Bolt
  • Listing Services From Project
  • Monitoring Service Logs
  • Stopping Project via bolt

Adding Bolt to a Project

Go inside the project which you want to run via bolt, run bolt init command to create bolt.yaml file inside your project.
$ cd PATH_TO_YOUR_PROJECT
$ bolt init
This will create a bolt.yaml file in your project's root directory.
envfile: .env.tpl
project_id: 'SOME_PROJECT_ID'
project_name: YOUR_PROJECT_NAME
services: null
ingress: null
Let's take the below project example,
# Below's the directory structure of our project.
bolt-project/
╰─➤ service-one/
╰─➤ index.js
╰─➤ package.json
╰─➤ service-two/
╰─➤ index.js
╰─➤ package.json
Now if I do bolt init inside bolt-project directory, it will create a bolt.yaml file at root of the project which is something like this:
envfile: .env.tpl
project_id: '1687780932260'
project_name: bolt-project
services: null
ingress: null

Adding a Project Service as Bolt Service

In order to add a service to your project, you can use the bolt service:add command. This command will create a bolt.service.yaml file inside your service directory and will include the same in your bolt.yaml file.
$ bolt service:add SERVICE_INSTANCE_NAME SERVICE_PATH
Now, let's add service-one and service-two with its instance name as servicetwo and servicetwo respectively to the bolt.yaml file by running the following commands:
$ bolt service:add serviceone service-one/
Creating app in service-one
Scanning source code
Detected Node.js app
Installed serviceone service in service-one
Verifying metadata for other services..
Metadata verified
$ bolt service:add servicetwo service-two/
Creating app in service-one
Scanning source code
Detected Node.js app
Installed serviceone service in service-one
Verifying metadata for other services..
Metadata verified
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 your bolt.yaml file looks
envfile: .env.tpl
project_id: '1687780932260'
project_name: boltproject
services:
serviceone:
path: service-one/
servicetwo:
path: service-two/
ingress: null
# This is how your service-one/bolt.service.yaml looks
container_name: serviceone
stateless: true
default_service_runner: local
service_discovery_offset:
- 9000
supported_service_runners:
- local
- docker
service_runners:
local:
envfile: .env
build: npm install && node app.js
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
docker:
envfile: .env
build: ./run.Dockerfile
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
volumes:
- service-one:/app
- /app/node_modules
# This is how your service-two/bolt.service.yaml looks
container_name: servicetwo
stateless: true
default_service_runner: local
service_discovery_offset:
- 9000
supported_service_runners:
- local
- docker
service_runners:
local:
envfile: .env
build: npm install && node app.js
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
docker:
envfile: .env
build: ./run.Dockerfile
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
volumes:
- service-one:/app
- /app/node_modules
Note: • Configure these files as per your need • If you are defining port or host from ".env" variable in your project then use ASSIGNED_PORT and ASSIGNED_HOST as env variables, because bolt automatically assigns port and host to your service.

Running Project via Bolt

In order to run the project using bolt you need to run the following command:
$ bolt up
Now, if we run services shown in example above using Bolt.
$ bolt up
>> Creating Ingress bolt-project...
>> No ingress found in config. Skipping route generation...
$ bolt env:generate
$ bolt env:generate
$ bolt env:generate
$ sh -c 'npm install && npm run dev'
$ sh -c 'npm install && npm run dev'
"serviceone" service is up on local platform
"servicetwo" service is up on local platform
You can now access these services at the port mentioned in their logic.

Listing Services From Project

You can also the list of services in your bolt project and their statuses using the service:list command.
$ bolt service:list
If we run the above command for our example project, we will get the following output something like this:
$ bolt service:list
╔═══╤══════════════╤════════╤════════════════╤════════════════╤════════════╤═══════════╗
# │ Service Name │ Status │ Project Runner │ Service Runner │ Port │ ProcessId ║
╟───┼──────────────┼────────┼────────────────┼────────────────┼────────────┼───────────╢
1 │ serviceone │ up │ hostlocal90006220
╟───┼──────────────┼────────┼────────────────┼────────────────┼────────────┼───────────╢
2 │ servicetwo │ up │ hostlocal90016221
╚═══╧══════════════╧════════╧════════════════╧════════════════╧════════════╧═══════════╝

Monitoring Service Logs

To monitor logs, use the following command:
$ bolt log SERVICE_NAME
To keep monitoring logs in live mode, use the following command:
$ bolt log --follow SERVICE_NAME

Stopping Project via bolt

To stop your project, you can run the following command:
$ bolt down
If we run the above command for our example project, we will get the following output something like this:
$ bolt down
>> Stopping bolt-project...
"servicetwo" is down from local platform
"serviceone" is down from local platform
>> bolt-project is down.