kind: pipeline
name: default
steps:

  - name: fetch-npm-deps
    image: node
    commands:
      - npm install

  - name: fetch-clojure-deps
    pull: always
    image: clojure:tools-deps
    volumes:
      - name: cache
        path: /drone/cache/
    commands:
      - ls -la /drone/cache/.m2
      - clojure -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository"}' -P -M:shadow-cljs-run

  - name: build-clojure
    pull: always
    image: clojure:tools-deps
    volumes:
      - name: cache
        path: /drone/cache/
    commands:
      - ls -la /drone/cache/.m2
      - clj  -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository"}' -Mshadow-cljs-run release app --debug

  - name: deploy-site
    pull: True
    image: appleboy/drone-scp
    depends_on:
      - build-clojure
    settings:
      host: blog.digitaloctave.com
      port: 22
      username:
        from_secret: ssh_user
      key:
        from_secret: ssh_key
      target: /var/www/portfolio/frontend/${DRONE_COMMIT_SHA:0:10}/
      source: /drone/src/development/resources/public/*
      strip_components: 4

  - name: promote-deployed-site
    pull: True
    image: appleboy/drone-ssh
    depends_on:
      - deploy-site
    settings:
      host: blog.digitaloctave.com
      port: 22
      username:
        from_secret: SSH_USER
      key:
        from_secret: SSH_KEY
      port: 22
      command_timeout: 5m
      script:
        - cd /var/www/portfolio/
        - rm /var/www/portfolio/promoted
        - ln -s /var/www/portfolio/${DRONE_COMMIT_SHA:0:10} /var/www/portfolio/promoted
    depends_on:
    - deploy-site

volumes:
  - name: cache
    host:
      path: /tmp/drone/cache/
