We live in an increasingly noisy world. When we’re on the move, the phones in our pockets buzz, beep and ring, at work our computers play melodies when we turn them on and off, and even at home our…
I had been working on my online portfolio recently and it bothered me that I would have to log into my production server, pull changes and build manually every single time. If you’re working on a small-scale business project or side project, this guide will explain how to automate the process.
I didn’t want to be overkill and set up a whole Jenkins or CircleCI pipeline yet I still wanted to automate this task in the simplest way possible. This is where Github Actions comes in.
Prior to using this, my process was:
2. Push changes to Github
3. Connect to my production server
4. Navigate to my project’s directory
5. Pull changes from Github
6. Compile new production build
Considering the time it takes between each command, your typing speed, mediocre Aussie internet, it adds up. Everything after step 2 can easily be automated in at most 10 minutes.
Prerequisites
The first thing you’ll need is a self-hosted runner. This is essentially a listener which sits on your production server and awaits instructions from Github. From your repo, head to Settings > Actions > Add Runner. You’ll see a set of instructions that you’ll need to run on your VPS.
These instructions must be run outside of superuser mode so you’ll need to create another user on your instance. Run these commands and then follow the instructions on Github.
Once the listener is successfully running, there’s one more step to go. Head over to Actions > Set up a workflow yourself. Below is a basic template of what your workflow should look like. This specific example is for a Node project. If you’re using anything else, have a look at the Marketplace on the side which has plugins and documentation to support many other environments.
To interpret this, the file is a workflow named CD. On every push to master, it will run a job named build on self-hosted (your production server). The job will sequentially execute the listed steps which will build the changes on your server.
After you commit and push this file, the workflow will activate. You can follow its progress in the Actions tab. Every time you push your latest changes to master, your production server will automatically reflect those changes.
That’s literally all you need to do to automate builds on your production instance and now you can focus completely on development.
This is my first article! If you liked it, then please consider subscribing.
Dit artikel volgt op Coronavirus: waarom je nu in actie moet komen, een artikel dat meer dan 40 miljoen keer bekeken is, en vertaald is in meer dan 20 talen, waarin de urgentie van het Coronavirus…
In late May I lost my best and oldest friend to suicide and this week I lost my mum to Alzheimer’s. This is an elegy for my beloved grandfather, Pte Jack Prince, and for those two much loved people…
Got no money in my pocket got no dime in the bank Just the sight from the sockets words of wisdom to spend Of the lies said by Jonah may it swallow me whole In embrace of a panda in a life that’s so…