image: node:current-alpine3.13

stages:
  - build
  - deploy

before_script:
  - apk update
  - apk add --no-cache lftp openssh
  - mkdir -p ~/.ssh
  - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
  - echo "$FRONTEND_ENV" > .env

npm build:
  stage: build
  only:
    - main
  script:
    - npm ci
    - npm run build

  artifacts:
    paths:
      - build

lftp deploy:
  stage: deploy
  only:
    - main
  script:
    - lftp -e "set net:timeout 5; set net:max-retries 3; set net:reconnect-interval-base 5; set ftp:ssl-allow no; ftp://$FTPS_USER:$FTPS_PASSWORD@$FTPS_HOST; mirror -X .* -X .*/ --reverse --verbose build/ live/; bye"
