Deployment guide

Context

For the last couple of years, I have been using buddy.works for my testing and production deployments, but recently I wanted to save a couple of danish kroner and decided to downgrade my subscription. This led me to take a closer look at my deployment process. The rest of this post will give a conceptual view of that process.

I tend to work on single environment projects, where buddy handles the compile, build and deploy. Therefore, this short recipe caters mostly to that particular scenario.

Prerequisites

This first thing I do, is to build the version locally. For a typical composer I run the following commands:

composer validate
composer install --no-interaction --prefer-dist --optimize-autoloader

Now, that the project is setup for production I continue to build the version release.

In order to build the version, I create a new folder under deployments/PROJECT/VERSION. This is a local folder structure, where the PROJECT is the name of the project and VERSION is the GIT hash of the production commit.

I then, copy the relevant files from my project into this new folder. The relevant files obviously, depend on which kind of project you are building, but for a Laravel project the relevant files are:

app/            
bootstrap/     
config/    
database/ 
public/    
resources/lang/
resources/views/
routes/
storage/
vendor/
.env
artisan
composer.json
composer.lock
server.php

After the files are copied to the version folder. I compress the folder and I’m now ready to upload the compressed folder to the server.

Deployment

The version is now ready and I use the following steps to deploy it on your server:

1. Folder Structure

I maintain a clear folder structure on my server for organizing the deployments. This is the structure:

ROOT/public/current
ROOT/versions

  • The ROOT/public/current folder acts as a symbolic link pointing to the current deployed version.
  • The ROOT/versions folder stores all versions that have been deployed.

2. Unzip Uploaded Folder

On the server, I make sure that I upload the version and then navigate to the designated deployment path (e.g., ROOT/versions). Then I unzip the uploaded folder into this directory.

unzip VERSION.zip ROOT/versions

This will result in a new version in the folder: ROOT/versions/VERSION.

3. Create Symbolic Link

The last thing is to then update the symbolic link to point to the new version. Execute the following commands:

cd ROOT
rm -f public/current
ln -s versions/VERSION public/current

Replace VERSION with the actual version identifier and that’s it. This is a conceptual walk-through of my deployment process, which obliviously can be summarized in a neat little script.