variables:
  - &app_name "portfolio"

when:
  - event: release

steps:
  build-and-push:
    image: woodpeckerci/plugin-docker-buildx
    privileged: true
    settings:
      build_args:
        APP_VERSION: ${CI_COMMIT_TAG}
      platforms: linux/amd64
      registry: git.georgew.dev
      repo: git.georgew.dev/georgew/${CI_REPO_NAME}
      tags:
        - latest
        - ${CI_COMMIT_TAG##v}
      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:/home/george
    environment:
      APP_NAME: *app_name
      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
      - mkdir -p /home/george/$APP_NAME
      - cp docker-compose.yaml /home/george/$APP_NAME/
      - docker compose -p $APP_NAME -f /home/george/$APP_NAME/docker-compose.yaml pull
      - docker compose -p $APP_NAME -f /home/george/$APP_NAME/docker-compose.yaml up -d --force-recreate --remove-orphans
