services:
  autossh:
    build: .
    container_name: autossh
    restart: always
    ports:
      - "${SSH_TUNNEL_TO:?}:${SSH_TUNNEL_TO:?}"

    environment:
      # Пароль берется из переменной SSHPASS (для sshpass)
      - SSHPASS=${SSH_PASSWORD:?}

      # Настройки AutoSSH
      - AUTOSSH_LOGFILE=/dev/stdout
      - AUTOSSH_GATETIME=30
      - AUTOSSH_POLL=60
      # Отключает мониторинг через доп. порт (использует эхо SSH)
      - AUTOSSH_PORT=0

    command: >
      -M 0
      -N
      -v
      -o StrictHostKeyChecking=no
      -o ServerAliveInterval=60
      -o ServerAliveCountMax=3
      -o ExitOnForwardFailure=yes
      -p ${SSH_PORT:-22}
      -L 0.0.0.0:${SSH_TUNNEL_TO:?}:localhost:${SSH_TUNNEL_FROM:?}
      ${SSH_USER:?}@${SSH_HOST:?}
    deploy:
      resources:
        limits:
          cpus: "0.1"
          memory: 64M
        reservations:
          memory: 32M
    networks:
      - autossh_network

networks:
  autossh_network:
    name: autossh_network
    driver: bridge
