stages:
  - build
  - deploy

variables:
  NAME: "yova"
  EMAIL: "tech@freedomhost.de"
  GIT_SUBMODULE_STRATEGY: recursive
  HUGO_DOMAIN: gugelfrei.de
  HUGO_BASEURL: https://$HUGO_DOMAIN/

build:
  image: xdevbase/hugo-builder
  stage: build
  only:
    - main
  script:
    - hugo
  artifacts:
    paths:
      - public/

deploy:
  image: alpine
  stage: deploy
  environment:
    name: development
    url: $HUGO_BASEURL
  only:
    - main
  before_script:
    - apk add --no-cache lftp wipe openssh-client-default
    - mkdir -p ~/.ssh
    - echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/id_rsa
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
  script:
    - cd public
    - lftp -u $SFTP_USER, sftp://135.125.132.92:1006 -e "cd site;glob -a rm -r *;mirror -R;bye"
  after_script:
    - wipe ~/.ssh/id_rsa
