Create a Laravel image

February 20, 2020

Before you can install your Laravel application on one of your deployments, you first need to create an image. Images in Smoothy provide you with a powerful way to automatically test your code, turn your code into an executable binary, and roll out the latest version of your application to your deployments as part of a single automated workflow.

This tutorial assumes that:

  1. You established an integration between Smoothy and your code provider
  2. You understand the concept of images

Create a Laravel image #

You can create an image by navigating to the images page via the main navigation, hovering the button in the right upper corner of the images table, and clicking on Create image.

Empty images page

This will open up a form that asks you under which project you want to create your deployment.

warning

Make sure to select the same project as the one assigned to the deployment on which you want to run the application. If you select a different project, you will not be able to run your application on this deployment.

Next, you need to specify the git repository and branch that contain the source code of your application that you wish to run. As depicted in the screenshot below, to ease this process, Smoothy provides you with a list of all your git repositories from which you can select the desired one. In the same way, you can then also select the branch of your git repository.

Create Laravel image

In the subsequent step, you need to select the type of your application. Since this tutorial is focussed on Laravel applications, you should select the type Laravel.

Create Laravel image

Next, you need to specify the Laravel and PHP version in which your application code is written.

Create Laravel image

Chances are that your Laravel application contains JavaScript and CSS assets that need to be compiled before they can be used in your webpages. When this is the case, you should enable the option Compile assets. Smoothy then suggests a Node.js compilation script that interacts with Laravel Mix. However, if your application uses a different build system to compile its assets, you can provide your own Node.js script.

Besides compiling the assets of your application, you may also want to run a few (artisan) commands upon the installation of your application to prepare it for production. Examples are:

  • migrating your database: php artisan migrate
  • caching your routes: php artisan route:cache
  • creating a public symlink to the storage folder: php artisan storage:link

Based on the Laravel version of your application, Smoothy suggests a deploy script that will be executed every time your application is installed on a deployment. Make sure to verify that this script matches all the requirements of your application and if not change it accordingly.

Create Laravel image

In the next step of the creation process, you are asked whether or not your Laravel application uses the Laravel scheduler to execute periodic tasks. If this is the case, you should enable the option Run Laravel scheduler. Smoothy then configures your image to automatically run php artisan schedule:run every minute.

If your application requires some daemon processes to run, you should also specify them in this step. Examples of common Laravel-related daemon processes are:

  • running a Laravel queue worker: php artisan queue:work
  • running Laravel Horizon: php artisan horizon

Create Laravel image

The sixth step in the creation process of your application is about Laravel Nova. If your Laravel application uses Laravel Nova and installs it via Composer, you should enable the option Laravel Nova.

The "problem" with Laravel Nova is that it's source code is stored in a private Packagist registry which only customers of Nova can access using their login credentials. This means that, whenever you want to install your application on a deployment, you need to specify your login credentials in order for Composer to be able to download the Laravel Nova source code.

When you enable the Laravel Nova option for your application, Smoothy will ask you to provide the credentials of your Laravel Nova account once. After that, Smoothy will use these credentials to automatically authenticate with the private registry of Laravel Nova to download its source code upon every installation of your application.

Create Laravel image

Smoothy will turn your Laravel application into an image that includes:

These packages and extensions support the large majority of Laravel applications. However, if your application requires some additional packages to be installed, such as for example git or mysql-client, you can specify them in the last step of the creation process.

warning

Make sure that all the additional packages can be installed via the apt package manager.

Create Laravel image

When you successfully completed all the steps in the creation process, you should see your new image appear on the images page.

Images page

Where to go from here? #

Now that you have created a Laravel image that is linked to your git repository, you should trigger your first image build to actually build the source code of your application into an image. After that, you can use the image to install your Laravel application on one of your deployments.

Michiel Kempen

Michiel Kempen

A passionate cloud engineer who helps software companies adopt modern cloud technologies through an intelligent all-in-one cloud platform called Smoothy.