cache:
  paths:
    - output/ # le répertoire où se trouve le HTML statique généré

.pre:
  image: node:latest
  stage: .pre
  script:
    - cd /srv/blog/content/slides && yarn

build:
  image: docker.isima.fr/vimazeno/pelican_perso_python:35046e8
  stage: build
  script:
    - git submodule init
    - git submodule update --recursive --remote
    - PATH=/root/.local/bin:$PATH pelican
  
deploy:
  image: docker.isima.fr/vimazeno/pelican_perso_kerberos:35046e8
  stage: deploy
  script:
    # récupération du KEYTAB en hexa 
    - echo "$KEYTAB" > my.keytab.hex
    # conversion du KEYTAB en hexa en binaire
    - sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' my.keytab.hex | xargs printf > my.keytab
    # génération du ticket kerberos
    - kinit -k -t my.keytab vimazeno@LOCAL.ISIMA.FR
    # préparation du répertoire servi par apache
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "mkdir -p ~/public_html/"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo 'Options +FollowSymLinks' >  ~/public_html/.htaccess"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo 'RewriteEngine on' >>  ~/public_html/.htaccess"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo 'RewriteCond %{HTTP_HOST} ^perso.isima.fr$' >>  ~/public_html/.htaccess"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo 'RewriteRule (.*) https://perso.limos.fr%{REQUEST_URI} [R=301,L]' >>  ~/public_html/.htaccess"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "mkdir -p ~/public_html/_"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo '<FilesMatch "\.phar">' >  ~/public_html/_/.htaccess"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo '   php_flag engine off' >>  ~/public_html/_/.htaccess"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo '   ForceType application/octet-stream' >>  ~/public_html/_/.htaccess"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo '   Header set Content-Disposition attachment' >>  ~/public_html/_/.htaccess"
    - ssh -o StrictHostKeyChecking=no -K vimazeno@perso.local.isima.fr "echo '</FilesMatch>' >>  ~/public_html/_/.htaccess"
    # rsync du HTML statique généré
    - rsync -az --exclude '_' -e "ssh -o StrictHostKeyChecking=no -K" output/ vimazeno@perso.local.isima.fr:~/public_html/