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.
- Docker desktop
- NodeJs
- AWS cli (for deployment only)
Install laraboot
Laraboot is installed through NPM. Check out the project here.
npm i -g @laraboot-io/cli
Create new project
laraboot new laraboot-demo-app --php-version=8 && cd laraboot-demo-app
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:
- @core/laravel-foundation-provider
- @core/laravel-config
- @core/laravel-model
- @core/laravel-starterkit-buildpack
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
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
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
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
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
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
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"
}
}
}
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
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.
Top comments (0)