Many pro­to­cols are avail­able at always­da­ta for access­ing your accounts remote­ly: SSH, FTP, WebDAV, etc. However, it seems that deploy­ing an app in pro­duc­tion suf­fers from a lack of flex­i­bil­i­ty. So, we decid­ed to take care of that.

sarcastic joke GIF @Giphy

Please, alwaysdata, tell us about deployment again!

Some things are sim­pler than oth­ers for a devel­op­er. Unfortunately, deploy­ment isn’t one of those sim­ple things, being stuck between lega­cy FTP deliv­ery, file copy over SFTP, patch release remote­ly, etc. Each project has its con­straints and choic­es.

Solutions like Heroku learned ear­ly on that the one who pro­duces the code shouldn’t have to take care of the deploy­ment process­es. The one pro­duc­ing the code just has to stay focused on their job: pro­duc­ing good code. However, not every­body has a DevOp avail­able to release the last pro­duc­tion build. In this sit­u­a­tion, you only have the option of doing it your­self.

Because always­da­ta is designed by devel­op­ers, we took some time to brain­storm about the best way to deploy in pro­duc­tion. We’ve got some ideas for an inte­grat­ed tool that will allow you to deploy auto­mat­i­cal­ly, but our pri­or­i­ty goes to oth­er tech­nolo­gies like HTTP/2.

So, we want to give you a solu­tion that makes your life eas­i­er. Like you, we pre­fer to deliv­er our code in one sin­gle com­mand in our ter­mi­nal. So, we took a look at how to deploy using Git.

Git push. Period.

excited friends tv GIF @Giphy

Here is our pro­pos­al, which is based on anoth­er solu­tion that uses con­tain­ers: Simply git push your pro­duc­tion branch, and it’s done.

TL;DR: If you want to under­stand how it works (because you’re curi­ous), con­tin­ue read­ing. If you just want to use it, you can go to our GitHub repos­i­to­ry always­data/au­tode­ploy-git-hook where a short README will guide you through the con­fig­u­ra­tion process.

Let’s dive in. You will need:

  • a SSH access to set it
  • your code­base ver­sioned using Git
  • known git-hooks prin­ci­ples (but we will explain them lat­er)
  • eggs, flour, milk

On the Server-side

Let’s begin by cre­at­ing a repos­i­to­ry in your always­da­ta account (feel free to adapt paths; noth­ing here is manda­to­ry):

We cre­ate it bare fla­vor. This means it will con­tain only the con­fig and ver­sion­ing parts. We don’t need more here for deploy­ment.

Then, we will cre­ate a script for the post-receive hook. Like its name sug­gests, it will han­dle the push action to the repos­i­to­ry and will be exe­cut­ed right after by tak­ing a ref­er­ence to the pushed branch. We will use it to test the branch (name­ly a production branch) and deploy its con­tent to a direc­to­ry that con­tains the code­base served by our Apache instance. On your serv­er, cre­ate a file named ~/my-project.git/hooks/post-receive with the fol­low­ing con­tent:

We need to test whether the pushed branch is the production one and then check­out its con­tent to the ~/www/my-project direc­to­ry (the path you defined in your cockpit’s web­site set­tings sec­tion), which con­tains the code­base served by your HTTP serv­er.

Don’t for­get to make the script exe­cutable with chmod +x ~/my-project.git/hooks/post-receive.

On the Local-side

Back to your local repos­i­to­ry in your devel­op­ment device. Go to your project direc­to­ry, and add the always­da­ta deploy repos­i­to­ry:

It’s done! You now just need to push your production branch to the deploy remote, and deploy­ment will be fin­ished:

On your production branch, you just have to merge the ver­sion that you want to deploy, and push it to the deploy remote. That’s all.

Cool, but I don’t only deploy static files

You’re right. We just take a sim­ple use-case, and we know that you often need to do more things when deploy­ing.

You prob­a­bly want to restart your Apache instance to take changes into account. For this use-case, sim­ply add this instruc­tion to the post-receive script, just after the git checkout branch:

It per­forms a cURL request that will call the always­da­ta API, using your API key, your account name, and the site ID you want to per­form an action on; it also restarts the instance trans­par­ent­ly.

Here again, noth­ing more to do than push­ing your production branch.

More!

theres more cole sprouse GIF @Giphy

Want more? Alright!

You prob­a­bly need more things to auto­mate your whole release process. So we open-sourced the code for this hook to the always­data/au­tode­ploy-git-hook GitHub repos­i­to­ry. The script is con­fig­urable using shell vari­ables at the top of the file. You just have to make small changes to adapt it to your work­flow.

We are aware that this script is far from being com­plete. You prob­a­bly have some migra­tions to do on your data­bas­es or some sta­t­ic files gen­er­a­tion to per­form when you update your app. Give us some feed­back at issues or sub­mit pull-requests so we can improve it togeth­er.

helpful bill murray GIF @Giphy