DEV Community

Cover image for 10 minute tutorial - Create and deploy a Laravel application using a low-code approach
Oscar Nevárez
Oscar Nevárez

Posted on

10 minute tutorial - Create and deploy a Laravel application using a low-code approach

Getting started

In this post, I want to show how quickly and easily Laraboot can help you create a solid start point for your next Laravel application including models, CRUD routes, and Jetstream integration. Best of all, we won't have to write any code.

Once we got the application ready we will use AWS ECR to deploy it.

Initialize and configure

Prerequisites

Make sure your system has the following requirements beforehand.

Install laraboot

Laraboot is installed through NPM. Check out the project here.

npm i -g @laraboot-io/cli
Enter fullscreen mode Exit fullscreen mode

Create new project

laraboot new laraboot-demo-app --php-version=8 && cd laraboot-demo-app
Enter fullscreen mode Exit fullscreen mode

Buildtasks

Build tasks are just custom buildpacks that create or modify a Laraboot project.

In this post, we're going to use several build tasks. If you feel adventurous, you can dive into the build task directory

The ones we require are:

We add them using laraboot cli like this

laraboot task add @core/laravel-foundation-provider --format=file
laraboot task add @core/laravel-config --format=file
laraboot task add @core/laravel-model --format=file
laraboot task add @core/laravel-starterkit-buildpack --format=file
Enter fullscreen mode Exit fullscreen mode

Configure

Let's first create our data model. For the purpose of this post let's imagine we have 2 models. Post and Comment. We'll create them using the model command like this:

laraboot model add Post
√ Would you like to define your model now? (y/N) · true
√ Field name? · content
√ Field type? · varchar
√ Is this field unique? (y/N) · false
√ Is this field primary key? (y/N) · false
√ Would you like to add a new field? (y/N) · false
Model Post was added
laraboot model add Comment
√ Would you like to define your model now? (y/N) · true
√ Field name? · content
√ Field type? · varchar
√ Is this field unique? (y/N) · false
√ Is this field primary key? (y/N) · false
√ Would you like to add a new field? (y/N) · false
Model Comment was added

Enter fullscreen mode Exit fullscreen mode

Then configure Jetstream. Add the following piece of content to the end of your buildpack.yml file

# buildpack.yml
laravel-starterkit:
  # Jetstream configuration
  jetstream:
    enabled: true
    teams: true
    stack: livewire
  # Breeze configuration
  breeze:
    enabled: false
    stack: inertia

Enter fullscreen mode Exit fullscreen mode

Build

Once configured, kick the build process. Mind that the build time depends on your system capabilities and whether if this is the first time you build a laraboot project. Subsequent builds are significantly faster.

laraboot build
Enter fullscreen mode Exit fullscreen mode

If everything goes as planned you should end up with an OCI-compliant image named laraboot-demo-app.

Preview

Let's see how everything looks like by running our application locally

laraboot run --port=9000
Enter fullscreen mode Exit fullscreen mode

image.png

Awesomeness.

Deploy to AWS

Next, we're going to use AWS as a cloud provider and AWS ECR as the service registry but you can as well deploy to the CR of your preference.

Create an ECR repository using AWS cli

You can skip this part if you already have an AWS ECR repository.

There are two ways ( maybe more ) to create an ECR repository, in this post we'll use aws-cli.

# create an ecr repository
aws ecr create-repository \
    --repository-name laraboot-demo-app \
    --image-scanning-configuration scanOnPush=true
Enter fullscreen mode Exit fullscreen mode

This will output something like this

{
    "repository": {
        "repositoryArn": "arn:aws:ecr:us-east-1:xxxxxxxxxxxx:repository/laraboot-demo-app",
        "registryId": "xxxxxxxxxxxx",
        "repositoryName": "laraboot-demo-app",
        "repositoryUri": "xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/laraboot-demo-app",
        "createdAt": "2021-10-13T10:45:53-05:00",
        "imageTagMutability": "MUTABLE",
        "imageScanningConfiguration": {
            "scanOnPush": true
        },
        "encryptionConfiguration": {
            "encryptionType": "AES256"
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Create an ECR repository through the AWS ECR console

You can achieve the same by signing into the AWS console and heading to the ECR service console management.

  • Click on Create repository
  • Fill out the blanks in the General settings panel
  • Click on Create repository

Deploy

The steps to deploy our image are the following

  • Sign in to the AWS ECR
  • Tag our image
  • Deploy

# replace xxxxxxxxxxxx with your AWS account id
# replace region if it's not us-east-1

# sign in to the ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com

## tag our image
docker tag laraboot-demo-app:latest xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/laraboot-demo-app:latest

## push
docker push xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/laraboot-demo-app:latest

Enter fullscreen mode Exit fullscreen mode

Conclusion

On this occasion, we use Laraboot to set up a new Laravel application without having to write any line of code. This application has been containerized and deployed to AWS ECR in a matter of minutes.

Discussion (0)