stages:
  - build
  - deploy

build:
  image: klakegg/hugo:alpine-ci
  stage: build
  script:
    - hugo -D
  artifacts:
    paths:
      - public
    expire_in: 1 week

deploy:
  image: debian:bullseye
  stage: deploy
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
    - rsync -avz --rsh="ssh -p 17295" ./public/ janw-name@janw.name:/var/www/new.janw.name/
  only:
    - main
