Tutorial: Laravel App

This tutorial is about how to run a Laravel app 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 myapp which is a laravel 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.
laravel-app/
╰─➤ service/
╰─➤ ...laravel files
╰─➤ bolt.service.yaml
╰─➤ build.Dockerfile
╰─➤ .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 laravel-app
$ bolt init --name laravel-app
It has created a bolt.yaml file in our project's root directory.
envfile: .env.tpl
project_id: "1690964916850"
project_name: laravel-app
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 laravelservice service/
Creating app in service
Scanning source code
Detected Laravel app
Installed myapp service in service
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 as a service
envfile: .env.tpl
project_id: "1690964916850"
project_name: laravel-app
services:
laravelservice:
path: service
ingress: null
# This is how service/bolt.service.yaml looks
container_name: laravelservice
stateless: true
default_service_runner: local
service_discovery_offset:
- 9000
supported_service_runners:
- local
- docker
service_runners:
local:
envfile: .env
build: composer install && php artisan serve --port=${ASSIGNED_PORT}
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
docker:
envfile: .env
build: ./run.Dockerfile
ports:
- ${ASSIGNED_PORT}:9000

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.
You can now access service at http://localhost:9000.

Running the Project on Docker

Inorder to run the service in docker when you run bolt up command you need to change the default_service_runner in bolt.service.yaml file to docker.
# This is how bolt.service.yaml file should look like if you want to run the service in docker
container_name: laravelservice
stateless: true
default_service_runner: docker
service_discovery_offset:
- 9000
supported_service_runners:
- local
- docker
service_runners:
local:
envfile: .env
build: composer install && php artisan serve --port=${ASSIGNED_PORT}
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
docker:
envfile: .env
build: ./run.Dockerfile
ports:
- ${ASSIGNED_PORT}:9000
Now if you run bolt up command it will run the service in docker.

Running the Project on Local

Inorder to run the service in local when you run bolt up command you need to change the default_service_runner in bolt.service.yaml file to local.
# This is how bolt.service.yaml file should look like if you want to run the service on local
container_name: laravelservice
stateless: true
default_service_runner: local
service_discovery_offset:
- 9000
supported_service_runners:
- local
- docker
service_runners:
local:
envfile: .env
build: composer install && php artisan serve --port=${ASSIGNED_PORT}
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
docker:
envfile: .env
build: ./run.Dockerfile
ports:
- ${ASSIGNED_PORT}:9000
Now if you run bolt up command it will run the service on local.

Listing Bolt Services

You can also see the list of services in your bolt project and their statuses using the service:list command.
$ bolt service:list
╔═══╤════════════════╤════════╤════════════════╤══════╤═══════════╗
# │ Service Name │ Status │ Service Runner │ Port │ ProcessId ║
╟───┼────────────────┼────────┼────────────────┼──────┼───────────╢
1 │ laravelservice │ up │ local900023923
╚═══╧════════════════╧════════╧════════════════╧══════╧═══════════╝

Monitoring Service Logs

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

Stopping Your Project

To stop your project, you can run the following command:
$ bolt down
>> Stopping laravel...
"myapp" is down from local platform

Repo Link

To clone the project you can use bolt-framework-tutorial-apps/examples/laravel-app