[Docker-compose] Makefile -> Docker-compose 전환기

루나·2022년 7월 26일
0

rtps-simple-server라는 라이브러리를 사용하게 되었는데 개발 환경 문제로 프로젝트가 제대로 설치되지 않았다.
이 프로젝트에서는 Makefile을 이용해 도커 파일을 실행시키는 것으로 보였는데 최근 docker-compose를 배운 김에 연습겸 Makefile을 해석해 compose 파일로 빼내기로 했다.

rtps-simple-server의 Makefile :

define DOCKERFILE_RUN
FROM $(BASE_IMAGE)
RUN apk add --no-cache ffmpeg
WORKDIR /s
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN go build -o /out .
WORKDIR /
ARG CONFIG_RUN
RUN echo "$$CONFIG_RUN" > rtsp-simple-server.yml
endef
export DOCKERFILE_RUN

define CONFIG_RUN
#rtspAddress: :8555
#rtpAddress: :8002
#rtcpAddress: :8003
#metrics: yes
#pprof: yes

paths:
  all:
    runOnDemand: ffmpeg -re -stream_loop -1 -i ./public/WS.mp4 -c copy -f rtsp rtsp://localhost:8554/mystream

#  proxied:
#    source: rtsp://192.168.2.198:554/stream
#    sourceProtocol: tcp
#    sourceOnDemand: yes
#    runOnDemand: ffmpeg -i rtsp://192.168.2.198:554/stream -c copy -f rtsp rtsp://localhost:$$RTSP_PORT/proxied2

#  original:
#    runOnReady: ffmpeg -i rtsp://localhost:554/original -b:a 64k -c:v libx264 -preset ultrafast -b:v 500k -max_muxing_queue_size 1024 -f rtsp rtsp://localhost:8554/compressed

endef
export CONFIG_RUN

run:
	echo "$$DOCKERFILE_RUN" | docker build -q . -f - -t temp \
	--build-arg CONFIG_RUN="$$CONFIG_RUN"
	docker run --rm -it \
	--network=host \
	-v /home/ec2-user/rtsp-simple-server/public:/public \
	temp \
	sh -c "/out"

DOCKERFILE_RUN 에서 Dockerfile 추출 :
RUN echo "$$CONFIG_RUN" > rtsp-simple-server.yml을 쉽게 하기위해
CONFIG_RUN 부분을 따로 rtsp-simple-server-temp.yml로 분리한다

FROM golang:1.18-alpine3.15

RUN apk add --no-cache ffmpeg

WORKDIR /s

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

RUN go build -o /out .

WORKDIR /

COPY ./rtsp-simple-server-temp.yml ./rtsp-simple-server.yml

CMD ["sh", "-c", "/out"]

docker-compose.yaml

version: "3.8"
services:
  rtsp-simple-server:
    build: .
    volumes:
      - ./public:/public
    ports:
      - "8554:8554"

public 폴더에 재생시킬 동영상 넣기.

profile
백엔드 개발자

0개의 댓글