Tutorial: Laravel Auth & MySQL

This tutorial is about how to run a Laravel app on our Local and MySQL on Docker using bolt. Below's the video showing how to run this tutorial.

Table of Contents

  • Objectives
  • Project Structure
  • Initialising the project using Bolt
  • Adding Laravel service as a Bolt Service
  • Adding MySQL service as a Bolt Service
  • Running the Project
  • Listing Bolt Services
  • Monitoring Service Logs
  • Stopping Your Project
  • Repo Link

Objectives

  • Run this project's Laravel App using Local service runner
  • Run this project's MySQL container using Docker service runner

Project Structure

The project structure of our app is as follows:
# Below's the directory structure of our project.
laravel-auth-mysql/
╰─➤ services
╰─➤ laravel
╰─➤ ...laravel files
╰─➤ bolt.service.yaml
╰─➤ build.Dockerfile
╰─➤ .env.tpl
╰─➤ run.Dockerfile
╰─➤ mysql
╰─➤ ...mysql 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-auth-mysql
$ bolt init
It has created a bolt.yaml file in our project's root directory.
envfile: .env.tpl
project_id: "1690972020931"
project_name: laravel-auth-mysql
services: null
ingress: null

Adding Laravel service as a Bolt Service

To add Laravel service, run the following command -
$ bolt service:add laravelservice services/laravel
Creating app in service
Scanning source code
Detected Laravel app
Installed laravel 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 laravel service
envfile: .env.tpl
project_id: "1690972020931"
project_name: laravel-auth-mysql
services:
laravelservice:
path: services/laravel
ingress: null
# This is how services/laravel/bolt.service.yaml looks
container_name: laravelservice
stateless: true
default_service_runner: local
service_discovery_offset:
- 8000
depends_on:
- sql
supported_service_runners:
- local
- docker
service_runners:
local:
envfile: .env
build: composer install && npm install && npm run build && php artisan serve --port ${ASSIGNED_PORT}
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
docker:
envfile: .env
build: ./run.Dockerfile
ports:
- ${ASSIGNED_PORT}:${ASSIGNED_PORT}
Also we have added depends_on key in bolt.service.yaml so that sql service will go up first.

Adding MySQL service as a Bolt Service

To add MySQL service, run the following command -
$ bolt service:add sql services/mysql
Creating app in service
Scanning source code
Detected MySQL app
Installed mysql 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 sql service
envfile: .env.tpl
project_id: "1690972020931"
project_name: laravel-auth-mysql
services:
laravelservice:
path: services/laravel
sql:
path: services/mysql
ingress: null
vm:
name: laravelauthmysql
# This is how services/mysql/bolt.service.yaml looks
# Note that volumes are not configured, we have added it manually to the service
container_name: sql
stateless: true
default_service_runner: docker
service_discovery_offset:
- 3306
supported_service_runners:
- docker
service_runners:
docker:
envfile: .env
build: ./run.Dockerfile
volumes:
- ./services/mysql/data:/var/lib/mysql
ports:
- ${ASSIGNED_PORT}:3306

Running the Project

Now, let's run the project using Bolt.
# The following command will run the service as per the configuration in bolt.yaml file
$ bolt up
"laravelservice" service is up on local platform
"sql" service is up on docker platform
You can now access service at http://localhost:8000.
Once you have run the project, you need to run some Laravel specific commands to database migrate, database seed & client app assets bundling.
You can run the following commands to get you started -
# Goto laravel service directory
$ cd examples/laravel-auth-mysql/services/laravel
# Migrate tables
$ php artisan migrate
# Seed tables
$ php artisan db:seed

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 │ local800042338
╟───┼────────────────┼────────┼────────────────┼──────┼───────────╢
2 │ sql │ up │ docker3306 │ sql ║
╚═══╧════════════════╧════════╧════════════════╧══════╧═══════════╝

Monitoring Service Logs

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

Stopping Your Project

To stop your project, you can run the following command:
$ bolt down
...
"laravelservice" is down from local platform
"sql" is down from docker platform

Repo Link