---
- name: Install Woodpecker CI
  hosts: ulna

  tasks:
  - name: Ensure docker-compose is installed
    ansible.builtin.apt:
      name: docker-compose
      state: present
    become: true

  - name: Start woodpecker with docker-compose
    community.docker.docker_compose:
      project_name: woodpecker
      pull: true
      definition:
        version: "3"
        services:
          woodpecker-server:
            image: woodpeckerci/woodpecker-server:next
            ports:
              - "{{ woodpecker_port }}:8000"
            volumes:
              - woodpecker-server-data:/var/lib/woodpecker/
            environment:
              - WOODPECKER_OPEN=false
              - WOODPECKER_HOST=https://{{ woodpecker_host }}
              - WOODPECKER_AGENT_SECRET={{ woodpecker_agent_secret }}
              - WOODPECKER_GITEA=true
              - WOODPECKER_GITEA_URL=https://{{ gitea_host }}
              - WOODPECKER_GITEA_CLIENT={{ woodpecker_client_id }}
              - WOODPECKER_GITEA_SECRET={{ woodpecker_client_secret }}

          woodpecker-agent:
            image: woodpeckerci/woodpecker-agent:next
            command: agent
            restart: always
            depends_on:
              - woodpecker-server
            volumes:
              - /var/run/docker.sock:/var/run/docker.sock
            environment:
              - WOODPECKER_SERVER=woodpecker-server:9000
              - WOODPECKER_AGENT_SECRET={{ woodpecker_agent_secret }}
        volumes:
          woodpecker-server-data:
    register: output
    become: true
