Creating and maintaining a site with git

In this post, I will show you how to manage a simple static website with a git repository. I will mention but you can apply this approach on any other server.

The root

If you're already running your own server (with nginx, apache, lighthttpd...) you may dismiss this step.

With Yunohost, if you don't want to get your hands too dirty with nginx configuration, we'll have to install a "sandbox", an empty app that will become the root of our site.

When I first installed Yunohost, this app was available from the interface but now have to copy and paste this link in the "Install custom app" form at the bottom of the installation page.

https://github.com/YunoHost-Apps/multi_webapp_ynh

Gitea

Unless you already have a gitea server running, you will need to install one.

In order to create hooks on server side, you'll have to add a line to /opt/gitea/custom/conf/app.ini :

[security]

DISABLE_GIT_HOOKS = false

(complete list of options)

Remember to restart gitea:

$ yunohost service restart gitea

You'll then be able to create a post-receive hook on your repository. (on the repo got to Settings -> Git Hooks)

#!/bin/sh

TARGET=/var/www/webapp_user/domain.tld_/

git --work-tree=$TARGET clean -fd

git --work-tree=$TARGET checkout --force

Finally, don't forget to give acces to gitea on the server:

$ chown gitea:gitea /var/www/webapp_user/domain.tld_/

Now everytime you'll run a git push on your client to the repository, git will take cade of updating your site.

Size issue

If you need big files (audio/video) or if you're pushing a lot of files at once, you might be limited by some default settings.

You can fix that by increasing git's postBuffer size:

$ git config --global http.postBuffer 400000000

This will raise it to 50MB (versus 1MB by default).

(documentation)

If you encounter the following error:

error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413

You can increase the limit by adding the following line in /etc/nginx/conf.d/git.domain.tld.d/gitea.conf (on the server this time)

client_max_body_size 50M;

Then restart nginx:

$ yunohost service restart nginx

(documentation)

Autoindex / basic file server

If you want to be able to browse the whole file system of your domain from any web browser, you can edit /etc/nginx/conf.d/domain.tld.d/webapp_domain.tld_.conf

location / {
	autoindex on;
	alias /path/to/root/ ;
}

Be careful though as everybody will be able to access it.

The only issue that comes to mind, regarding this visibility, would be if you were to store "hard-coded" passwords in text file, but it's a very bad practice that you should avoid anyway.

I use the autoindex to easily find font files or some javascript libraries.