pipeline:
  build:
    image: node:22
    commands:
      - npm ci
      - npm run build
    when:
      branch: master

  deploy:
    image: appleboy/drone-scp
    settings:
      host:
        from_secret: ssh_host
      username:
        from_secret: ssh_username
      key:
        from_secret: ssh_key
      port: 2332
      target: /home/mnisyif/docker-containers/mnisyif/frontend
      source:
        - dist/
        - Dockerfile
    when:
      branch: master

  docker-build-and-run:
    image: appleboy/drone-ssh
    settings:
      host:
        from_secret: ssh_host
      username:
        from_secret: ssh_username
      key:
        from_secret: ssh_key
      port: 2332
      script:
        - cd /home/mnisyif/docker-containers/mnisyif/frontend
        - docker build -t frontend:${CI_COMMIT_SHA} .
        - docker stop frontend || true
        - docker rm frontend || true
        - docker run -d --name frontend -p 5173:80 frontend:${CI_COMMIT_SHA}
    when:
      branch: master