image: debian:testing

variables:
  GIT_STRATEGY: clone
  GIT_SUBMODULE_STRATEGY: none
  SERVER_RSYNC_PARAMS: "--recursive --compress --checksum --force --delete --stats --itemize-changes"
  SERVER_RSYNC_HOST: "pornohardware.com"
  SERVER_RSYNC_PORT: "873"
  #SERVER_RSYNC_USER -> Passed with "Secret Variables" from Gitlab GUI
  #SERVER_RSYNC_PASSWORD -> Passed with "Secret Variables" from Gitlab GUI
  #SERVER_WEBSITE_ROOT_DIR -> Passed with "Secret Variables" from Gitlab GUI
  
stages:
  - build
  - deploy
  - notify-sites

build:
  stage: build
  script:
    - apt-get -q update && apt-get -q -y install locales
    - echo "es_ES.UTF-8 UTF-8"  > /etc/locale.gen && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen
    - apt-get -q update && apt-get -q -y install pelican python-markdown python-typogrify python-bs4 graphviz
    - cd src && pelican -s publishconf.py
  artifacts:
    name: "${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}_artifacts"
    expire_in: 1 week
    paths:
      - "src/output"
      - "conf"

deploy:
  stage: deploy
  script:
    - apt-get -q update && apt-get -q -y install rsync
    - export RSYNC_PASSWORD=${SERVER_RSYNC_PASSWORD}
    - mv src/output http
    - rsync ${SERVER_RSYNC_PARAMS} http conf rsync://${SERVER_RSYNC_USER}@${SERVER_RSYNC_HOST}:${SERVER_RSYNC_PORT}/${SERVER_RSYNC_NAME}
  only:
    - master
  dependencies:
    - build
  environment:
    name: production
    url: https://pornohardware.com

notify-sites:
  stage: notify-sites
  script:
    - apt-get -q update && apt-get -q -y install python python-requests
    - cd src && python notify_sites.py
  only:
    - master