version: '3'

services:
  portainer:
    image: portainerci/portainer:$PORTAINER_TAG
    command: -H unix:///var/run/docker.sock --admin-password $$2y$$05$$cQ4zB2SEdP4U3kkNhUV.Gu/xPdE4wSKEo1ncBFfKeERMI6IiXbg8y
    restart: always
    ports:
      - 8999:9000
      - 8000:8000
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data

  swarm:
    image: docker:dind
    privileged: true
    restart: always
    volumes:
      - /tmp/manager_run:/var/run

  swarm-init:
    image: docker:dind
    privileged: true
    command:
      - /bin/sh
      - -c
      - |
        apk add curl
        curl -L https://raw.githubusercontent.com/eficode/wait-for/master/wait-for -o /bin/wait-for
        chmod +x /bin/wait-for
        wait-for swarm:2376 -- docker -H unix://swarm/run/docker.sock swarm init
        docker -H unix://swarm/run/docker.sock swarm init
        docker -H unix://swarm/run/docker.sock network create --driver overlay portainer_agent_network
        docker -H unix://swarm/run/docker.sock service create -q --name portainer_agent --network portainer_agent_network --publish mode=host,target=9001,published=9001 -e AGENT_CLUSTER_ADDR=tasks.portainer_agent --mode global --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock --mount type=bind,src=//var/lib/docker/volumes,dst=/var/lib/docker/volumes --mount type=bind,src=/,dst=/host portainer/agent
    depends_on:
      - swarm
    volumes:
      - /tmp/manager_run:/swarm/run

  kube:
    image: portainer/kube-tools:latest
    privileged: true
    command:
      - /bin/bash
      - -c
      - |
        service docker start
        sleep 3
        kind create cluster --config=/kind.yaml
        curl -L https://raw.githubusercontent.com/portainer/k8s/master/deploy/manifests/agent/portainer-agent-k8s-nodeport.yaml -o portainer-agent.yaml
        kubectl apply -f portainer-agent.yaml
        tail -f /dev/null
    volumes:
      - docker_data:/var/lib/docker

volumes:
  docker_data:
  portainer_data: