This tutorial is about how to run a Simple HTTP Server 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-one 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 service-one which is a simple http server made using express and nodejs.
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.
simple-http-server/
╰─➤ service-one/
╰─➤ bolt.service.yaml
╰─➤ build.Dockerfile
╰─➤ index.js
╰─➤ package.json
╰─➤ package-lock.json
╰─➤ .env.tpl
╰─➤ run.Dockerfile
╰─➤ .env
╰─➤ .env.tpl
╰─➤ bolt.yaml
╰─➤ .gitignore
╰─➤ 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 simple-http-server
$ bolt init
It has created a bolt.yaml file in our project's root directory.
envfile: .env.tpl
project_id:"1690960686634"
project_name: simple-http-server
services:null
ingress:null
Adding service-one as a Bolt Service
Now, in order to add service-one as a service in bolt we have executed the following command:
$ bolt service:add myapp service-one/
Creating app in service-one
Scanning source code
Detected Node.js app
Installed myapp servicein 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 bolt.yaml file looks after adding service-one as a service
envfile: .env.tpl
project_id:"1690960686634"
project_name: simple-http-server
services:
myapp:
path: service-one
ingress:null
# This is how service-one/bolt.service.yaml looks
container_name: myapp
stateless:true
default_service_runner: docker
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
Running the Project
Now, let's run our service using Bolt.
# The following command will run the service as per the configuration in bolt.yaml file
$ bolt up
...
"myapp"service is up on local platform
By default, the configuration in bolt.yaml file is to run the project on local machine.