deploy:demo:
  image: gitlab.wpdesk.dev:5050/wpdesk/docker-tests/amazon-svn-deploy:24.09
  variables:
    DEPLOY_TARGETS:
      value: "demo.wpdesk.org,demo.wpdesk.pl"
      description: "Override this variable in project's .gitlab-ci.yml to support other servers. List supported targets separated by `,`. You may also use short name for deploy target, like \"wpdesk,octolize\" to support both wpdesk and both octolize targets. Currently supported targets: demo.wpdesk.org, demo.wpdesk.pl, demo.octolize.com, stage.demo.octolize.com, demo.flexibleinvoices."
  environment:
    name: $DEPLOY_SERVER
    url: https://$DEPLOY_SERVER
  stage: deploy
  tags:
    - deploy
  needs:
    - build to deploy
  retry: 2
  parallel:
    matrix:
      - DEPLOY_SERVER:
          - demo.wpdesk.org
          - demo.wpdesk.pl
          - demo.octolize.com
          - stage.demo.octolize.com
          - demo.flexibleinvoices.com
  rules:
    - if: $IS_LIBRARY || $IS_NPM_LIBRARY
      when: never
    # Run only for tagged deployments
    - if: $CI_COMMIT_TAG == null
      when: never
    # Omit if server is not in deploy targets
    - if: $DEPLOY_SERVER !~ $DEPLOY_TARGETS
      when: never
    # Specific server overrides
    ## demo.wpdesk.pl
    - if: $DEPLOY_SERVER == 'demo.wpdesk.pl'
      variables:
        SSH_DSN: serwer296287@serwer296287.lh.pl:/home/platne/serwer296287/public_html/demo.wpdesk.pl/wp-content/plugins
        SSH_PORT: 40022
    ## demo.wpdesk.org
    - if: $DEPLOY_SERVER == 'demo.wpdesk.org'
      variables:
        SSH_DSN: serwer296287@serwer296287.lh.pl:/home/platne/serwer296287/public_html/demo.wpdesk.org/wp-content/plugins
        SSH_PORT: 40022
    ## demo.octolize.com
    - if: $DEPLOY_SERVER == 'demo.octolize.com'
      variables:
        SSH_DSN: wlgmnfabmq@s125.cyber-folks.pl:/home/wlgmnfabmq/domains/demo.octolize.com/public_html/wp-content/plugins
        SSH_PORT: 222
        GLOBAL_SSH_PRIV_KEY: $DEMO_FS_SSH_KEY
    ## stage.demo.octolize.com
    - if: $DEPLOY_SERVER == 'stage.demo.octolize.com'
      variables:
        SSH_DSN: wlgmnfabmq@s125.cyber-folks.pl:/home/wlgmnfabmq/domains/stage.demo.octolize.com/public_html/wp-content/plugins
        SSH_PORT: 222
        GLOBAL_SSH_PRIV_KEY: $DEMO_FS_SSH_KEY
    ## demo.flexibleinvoices.com
    - if: $DEPLOY_SERVER == 'demo.flexibleinvoices.com'
      variables:
        SSH_DSN: serwer296287@serwer296287.lh.pl:/home/platne/serwer296287/public_html/demo.flexibleinvoices.com/wp-content/plugins
        SSH_PORT: 40022
  before_script:
    - eval "$(ssh-agent -s)"
    - chmod 600 "$GLOBAL_SSH_PRIV_KEY"
    - ssh-add "$GLOBAL_SSH_PRIV_KEY"
    - echo "$SSH_KNOWN_HOSTS" | tr -d '\r' > ~/.ssh/known_hosts
  script:
    - rsync -rlDe "ssh -p $SSH_PORT" --delete "$CI_PROJECT_DIR/release/$CI_PROJECT_NAME" $SSH_DSN
    - 'curl -X POST --data-urlencode "payload={\"text\": \"Projekt <${CI_PROJECT_URL}|${CI_PROJECT_NAME}> zdeployowany do <${CI_ENVIRONMENT_URL}|${CI_ENVIRONMENT_NAME}> w wersji ${CI_COMMIT_REF_NAME}\", }" https://hooks.slack.com/services/${SLACK_AUTH}'

# deploy to demo octolize:
#   before_script:
#     - echo "$DEMO_FS_SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa_demo_fs
#     - chmod 0600 ~/.ssh/id_rsa_demo_fs
#     - echo "$SSH_KNOWN_HOSTS" | tr -d '\r' > ~/.ssh/known_hosts
