Server

tinypilot 도커 이미지로 배포 하기

하루이2222 2024. 7. 25. 22:07

TinyPilot은 LAN을 통해 외부 인터넷에서도 KVM에 접속하여 키보드, 마우스, 모니터를 사용할 수 있도록 하는 KVM 서비스임.

TinyPilot은 크게 3가지로 구성되어 있음:

  1. TinyPilot의 웹 프로그램: 사용자 인터페이스를 제공하고, 키보드 및 마우스 입력을 캡처함.
  2. uStreamer: HDMI 캡처 장치로부터 화면을 캡처하여 스트리밍함.
  3. Janus Gateway: WebRTC를 통해 uStreamer로부터 받아온 캡처 화면을 웹을 통해 스트리밍 가능하게 함.

따라서 다음과 같이 두 개의 Docker 파일로 구분하여 Compose 파일을 구성할 예정임:

  1. TinyPilot의 메인 프로그램 (Janus 포함)
  2. uStreamer 서버

구성 절차

  1. 패키지 설치: Python, Node.js, Git 등의 필요한 패키지 설치
  2. TinyPilot 소스 코드 클론: TinyPilot 소스 코드 클론
  3. 종속성 설치: Python 및 Node.js 종속성 설치
  4. TinyPilot 빌드: TinyPilot 빌드

프로젝트 디렉토리 구조

project-directory/
├── docker-compose.yml
├── images/
│   ├── tinypilot/
│   │   ├── Dockerfile
│   │   └── 프로그램 파일들 (예: app/, dev-scripts/, requirements.txt 등)
│   └── ustreamer/
│       ├── Dockerfile
│       └── 프로그램 파일들
└── nginx/
    └── kvn.conf.template

Dockerfile 예제

TinyPilot Dockerfile (images/tinypilot/Dockerfile)

FROM python:3

# 필요한 패키지 설치
RUN apt-get update && apt-get install -y curl sudo git
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs

# TinyPilot 소스 코드 복사
COPY . /opt/tinypilot

WORKDIR /opt/tinypilot

# Python 및 Node.js 종속성 설치
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN pip install -r dev_requirements.txt
RUN npm install prettier@2.0.5

# TinyPilot 빌드
RUN ./dev-scripts/build

# 포트 설정
EXPOSE 8000

# 컨테이너 진입점 설정
CMD ["python", "/opt/tinypilot/app/main.py"]

uStreamer Dockerfile (images/ustreamer/Dockerfile)

FROM ubuntu:20.04

# 필요한 패키지 설치
RUN apt update && apt -y install git build-essential libevent-dev libjpeg62-dev uuid-dev libbsd-dev make gcc libjpeg8 libjpeg-turbo8 libuuid1 libbsd0

# uStreamer 소스 코드 복사
COPY . /opt/ustreamer
WORKDIR /opt/ustreamer

# uStreamer 빌드 및 설치
RUN make && make install

# 포트 설정
EXPOSE 8080

# 컨테이너 진입점 설정
CMD ["ustreamer", "--host=0.0.0.0", "-r", "1920x1080", "--persistent", "--drop-same-frames=30", "-l"]

docker-compose.yml 파일 작성

version: '3.6'
services:
  nginx:
    image: nginx
    container_name: nginx
    restart: always
    depends_on:
      - ustreamer
      - tinypilot
    ports:
      - 10080:10080
    volumes:
      - ./nginx:/etc/nginx/templates
  ustreamer:
    build:
      context: ./images/ustreamer/
    container_name: ustreamer
    restart: always
    devices:
      - /dev/video0:/dev/video0
  tinypilot:
    build:
      context: ./images/tinypilot/
    container_name: tinypilot
    restart: always
    devices:
      - /dev/hidg0:/dev/hidg0
      - /dev/hidg1:/dev/hidg1

설정 방법

  1. 프로젝트 디렉토리 구조 생성:

    mkdir -p project-directory/images/tinypilot mkdir -p project-directory/images/ustreamer mkdir -p project-directory/nginx
  2. TinyPilot 소스 코드 클론:

    cd project-directory/images/tinypilot git clone https://github.com/mtlynch/tinypilot .
  3. uStreamer 소스 코드 클론:

    cd project-directory/images/ustreamer git clone --depth=1 https://github.com/pikvm/ustreamer .
  4. Docker 이미지 빌드:

    cd project-directory docker-compose build
  5. Docker 컨테이너 실행:

    docker-compose up