when:
  event: [push]
  branch: main

steps:
  build-and-push:
    image: woodpeckerci/plugin-docker-buildx
    privileged: true
    settings:
      platforms: linux/amd64
      registry: git.georgew.dev
      repo: git.georgew.dev/georgew/datasaur
      tags:
        - ${CI_COMMIT_SHA:0:7}
      dockerfile: Dockerfile
      username:
        from_secret: FORGEJO_USER
      password:
        from_secret: FORGEJO_TOKEN

  deploy:
    image: docker:28-cli
    privileged: true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/george/datasaur:/home/george/datasaur
    environment:
      FORGEJO_USER:
        from_secret: FORGEJO_USER
      FORGEJO_TOKEN:
        from_secret: FORGEJO_TOKEN
    commands:
      - echo $FORGEJO_TOKEN | docker login git.georgew.dev -u $FORGEJO_USER --password-stdin
      - docker pull git.georgew.dev/georgew/datasaur:latest
      - docker compose -p datasaur -f /home/george/datasaur/docker-compose.yaml up -d --force-recreate