ed.brz9.dev/ressources/git-static-site/EN/index.php

122 lines
4.6 KiB
PHP

<?php $page_title = "edbrz9 - Creating and maintaining a site with git"; ?>
<?php include($_SERVER['DOCUMENT_ROOT']."/assets/php/header.php"); ?>
<nav>
<section id="left-nav">
<a href="/">
<span class="byl-icon-home"></span>
</a>
<a href="/ressources/EN/">
<span>/ressources</span>
</a>
</section>
<section id="right-nav">
<a href="../">FR</a> /
<a href="" class="islang">ENG</a>
</section>
</nav>
<main>
<article>
<h1>Creating and maintaining a site with git</h1>
<p>In this post, I will show you how to manage a simple static site with a git repository. I will mention <a href="https://yunohost.org/#/" target="_blank"></a> but needless to say that you can apply this approach on any other server.</p>
<h2>The root</h2>
<p>If you're already running your own server (with nginx, apache, lighthttpd...) you may dismiss this step.</p>
<p>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.</p>
<p>When I first installed Yunohost, this app was available from the interface but it seems that it is no longer the case. You will have to copy and paste this link in the "Install custom app" form at the bottom of the installation page.</p>
<a href="https://github.com/YunoHost-Apps/multi_webapp_ynh" target="_blank">https://github.com/YunoHost-Apps/multi_webapp_ynh</a>
<h2>Gitea</h2>
<p>Unless you already have a gitea server running, you will need to install one.</p>
<p>In order to create hooks on server side, you'll have to add a line to /opt/gitea/custom/conf/app.ini :</p>
<pre><code>[security]
DISABLE_GIT_HOOKS = false
</code></pre>
<p><a href="https://docs.gitea.io/en-us/config-cheat-sheet/">(complete list of options)</a></p>
<p>Remember to restart gitea</p>
<pre><code>$ yunohost service restart gitea</code></pre>
<p>Vous pourrez maintenant créer un post-receive hook sur votre dépot.</p>
<p>You'll then be able to create a post-receive hook on your repository.</p>
<pre><code>#!/bin/sh
TARGET=/var/www/webapp_user/domain.tld_/
git --work-tree=$TARGET clean -fd
git --work-tree=$TARGET checkout --force</code></pre>
<p>Finally, don't forget to give acces to gitea on the server:</p>
<pre><code>$ chown gitea:gitea /var/www/webapp_user/domain.tld_/</code></pre>
<p>Now everytime you'll run a git push on your client to the repository, git will take cade of updating your site.</p>
<h2>Size issue</h2>
<p>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.</p>
<p>You can fix that by increasing git's postBuffer size:</p>
<pre><code>$ git config --global http.postBuffer 400000000</code></pre>
<p>This will raise it to 50MB (versus 1MB by default).</p>
<p><a href="https://git-scm.com/docs/git-config#Documentation/git-config.txt-httppostBuffer">(documentation)</a></p>
<p>If you encounter the following error:</p>
<pre><code>error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413</code></pre>
<p>You can increase the limit by editing /etc/nginx/conf.d/git.domain.tld.d/gitea.conf (on the server this time)</p>
<pre><code>client_max_body_size 50M;</code></pre>
<p>Then restart nginx:</p>
<pre><code>$ yunohost service restart nginx</code></pre>
<p><a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size">(documentation)</a></p>
<h2>Autoindex / basic file server</h2>
<p>Si vous voulez pouvoir vous consulter l'arborescence de votre serveur depuis n'importe quel navigateur, vous pouvez activer l'autoindex en modifiant le fichier /etc/nginx/conf.d/domain.tld.d/webapp_domain.tld_.conf</p>
<p>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</p>
<pre><code>location / {
autoindex on;
alias /path/to/root/ ;
}</code></pre>
<p>Attention cependant, tout le monde pourra voir ce que vous avez sur votre serveur. En ce qui concerne les fichiers statiques (CSS, JS, police d'écriture...) utilisés sur les pages publiées, tout le monde peut déjà les voir, d'une manière contournée.</p>
<p>Be carfull though as everybody will be able to access it.</p>
<p>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 liabily that you should avoid in any case.</p>
<p>I use the autoindex to easily find font files or some javascript libraries.</p>
</article>
</main>
<?php include($_SERVER['DOCUMENT_ROOT']."/assets/php/footer.php"); ?>