9

Low-Code Laravel Application Development - DZone Web Dev

 2 years ago
source link: https://dzone.com/articles/low-code-laravel-application-development
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

In this post, I want to show how quickly and easily Laraboot can help you create a solid starting 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

Create new project

Properties files
laraboot new laraboot-demo-app --php-version=8 && cd laraboot-demo-app

Build Tasks

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:

Properties files
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

Configure

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

Properties files
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

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

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

Build

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

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

Deploy to AWS

Next, we’re going to use AWS as a cloud provider and AWS ECR as the service registry, but you can 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.

Properties files
# create an ecr repository
aws ecr create-repository \
    --repository-name laraboot-demo-app \
    --image-scanning-configuration scanOnPush=true

This will output something like this:

Properties files
{
    "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"
        }
    }
}

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
Properties files
# 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

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK