Website alexdradu.com

After several months of postponing and procrastinating, I managed to get my website in a presentable form (or at least that's what I like to think).

The admin dashboard view

The website is currently hosted on my raspberry pi (a prize from GreatUniHack 2016), and the domain registered with GoDaddy UK. It is built with Laravel, a PHP framework, and many plugins and packages. Although it would have been somewhat easy to build a static website, I decided I want it to be dynamic, so I also built an admin dashboard, where the projects can be managed. 

Although the website uses Bootstrap CSS framework, I gave it a material-design feel, by adding in a lot of custom styles.

 

Troubles of self-hosting

My raspberry pi sitting on top of the router.
My raspberry pi

I went through some troubles setting up the domain on the pi, as my ISP provides a dynamic IP. Thus, every time the IP changed, I had to manually update the DNS record in the registrar dashboard. Luckily, GoDaddy has an API that allows updating the records remotely, provided you know the API key and secret. I got the API details, then I created a quick bash script that checks if the website's IP differs from the dynamic IP and if it does, a python script that uses godaddypy is called and updates the DNS records to the new IP. Finally, I added a crontab entry to call the bash script every 12 hours. This makes the maximum possible downtime of my website to be 12 hours / month.

Continuous integration?

Another thing frustrating me was that I had to ssh into my pi and update the website (git pull, etc) every time I would make some important changes. This was not too much of a problem when I was at home, but on some connections SSH was not allowed. The solution? Continuous integration!

From the Github settings page, I created a webhook that calls a php script whenever something is pushed to the repo. The script first checks the authentication token, then if the pushed branch was 'production' and if so, it executes a pull and the other composer post-update commands. This way, I just have to push to 'production' and everything gets updated by itself.

    if($pass == $signature and $request->input('ref') == 'refs/heads/production') {
      // Update git
      chdir('../');
      ob_start();
      echo shell_exec('sudo -u pi git pull');
      echo shell_exec('php artisan clear-compiled');
      echo shell_exec('composer dump-autoload');
      echo shell_exec('php artisan optimize');
      echo ob_end_flush();
      echo "Done.";

What's next?

Hopefully, as soon as I am pleased with the website and finished with all the project posts, I will launch my blog, hosted at www,alexdradu.com/blog. It will be powered by Wordpress, but the design won't be changed, as I am almost ready with the templates. This page will then be updated.

Tags