Browse Source

improve Docker images (#1771) (#1909)

* add ffmpeg variant
* remove 'v' prefix from tags
pull/1923/head
Alessandro Ros 2 years ago committed by GitHub
parent
commit
ae883040fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .dockerignore
  2. 1
      Makefile
  3. 30
      README.md
  4. 8
      scripts/binaries.mk
  5. 131
      scripts/dockerhub.mk

4
.dockerignore

@ -1,5 +1,5 @@
# do not add .git, since it is needed to extract the tag # do not add .git, since it is needed to extract the tag
# do not add /binaries, since they're needed by make dockerhub # do not add /tmp, since it is needed by make dockerhub
/tmp /binaries
/coverage*.txt /coverage*.txt
/apidocs/*.html /apidocs/*.html

1
Makefile

@ -1,6 +1,7 @@
BASE_IMAGE = golang:1.20-alpine3.17 BASE_IMAGE = golang:1.20-alpine3.17
LINT_IMAGE = golangci/golangci-lint:v1.52.2 LINT_IMAGE = golangci/golangci-lint:v1.52.2
NODE_IMAGE = node:16-alpine3.17 NODE_IMAGE = node:16-alpine3.17
ALPINE_IMAGE = alpine:3.17
RPI32_IMAGE = balenalib/raspberry-pi:bullseye-run RPI32_IMAGE = balenalib/raspberry-pi:bullseye-run
RPI64_IMAGE = balenalib/raspberrypi3-64:bullseye-run RPI64_IMAGE = balenalib/raspberrypi3-64:bullseye-run

30
README.md

@ -41,7 +41,6 @@ Features:
* Reload the configuration without disconnecting existing clients (hot reloading) * Reload the configuration without disconnecting existing clients (hot reloading)
* Read Prometheus-compatible metrics * Read Prometheus-compatible metrics
* Run external commands when clients connect, disconnect, read or publish streams * Run external commands when clients connect, disconnect, read or publish streams
* Natively compatible with the Raspberry Pi Camera
* Compatible with Linux, Windows and macOS, does not require any dependency or interpreter, it's a single executable * Compatible with Linux, Windows and macOS, does not require any dependency or interpreter, it's a single executable
[![Test](https://github.com/bluenviron/mediamtx/workflows/test/badge.svg)](https://github.com/bluenviron/mediamtx/actions?query=workflow:test) [![Test](https://github.com/bluenviron/mediamtx/workflows/test/badge.svg)](https://github.com/bluenviron/mediamtx/actions?query=workflow:test)
@ -58,9 +57,9 @@ _rtsp-simple-server_ has been rebranded as _MediaMTX_. The reason is pretty obvi
## Table of contents ## Table of contents
* [Installation](#installation) * [Installation](#installation)
* [Standard](#standard) * [Standalone binary](#standalone-binary)
* [Docker](#docker) * [Docker image](#docker-image)
* [OpenWRT](#openwrt) * [OpenWRT package](#openwrt-package)
* [Basic usage](#basic-usage) * [Basic usage](#basic-usage)
* [General](#general) * [General](#general)
* [Configuration](#configuration) * [Configuration](#configuration)
@ -114,7 +113,9 @@ _rtsp-simple-server_ has been rebranded as _MediaMTX_. The reason is pretty obvi
## Installation ## Installation
### Standard There are several installation methods available: standalone binary, Docker image and OpenWRT package.
### Standalone binary
1. Download and extract a precompiled binary from the [release page](https://github.com/bluenviron/mediamtx/releases). 1. Download and extract a precompiled binary from the [release page](https://github.com/bluenviron/mediamtx/releases).
@ -124,23 +125,30 @@ _rtsp-simple-server_ has been rebranded as _MediaMTX_. The reason is pretty obvi
./mediamtx ./mediamtx
``` ```
### Docker ### Docker image
Download and launch the image: Download and launch the image:
``` ```
docker run --rm -it --network=host aler9/rtsp-simple-server docker run --rm -it --network=host aler9/rtsp-simple-server:latest
``` ```
The `--network=host` flag is mandatory since Docker can change the source port of UDP packets for routing reasons, and this doesn't allow the server to find out the author of the packets. This issue can be avoided by disabling the UDP transport protocol: Available images:
|name|FFmpeg included|RPI Camera support|
|----|---------------|------------------|
|aler9/rtsp-simple-server:latest|:x:|:x:|
|aler9/rtsp-simple-server:latest-ffmpeg|:heavy_check_mark:|:x:|
|aler9/rtsp-simple-server:latest-rpi|:x:|:heavy_check_mark:|
|aler9/rtsp-simple-server:latest-ffmpeg-rpi|:heavy_check_mark:|:heavy_check_mark:
The `--network=host` flag is mandatory since Docker can change the source port of UDP packets for routing reasons, and this doesn't allow the RTSP server to identify the senders of the packets. This issue can be avoided by disabling the UDP transport protocol:
``` ```
docker run --rm -it -e MTX_PROTOCOLS=tcp -p 8554:8554 -p 1935:1935 -p 8888:8888 -p 8889:8889 aler9/rtsp-simple-server docker run --rm -it -e MTX_PROTOCOLS=tcp -p 8554:8554 -p 1935:1935 -p 8888:8888 -p 8889:8889 aler9/rtsp-simple-server
``` ```
Please keep in mind that the Docker image doesn't include _FFmpeg_. if you need to use _FFmpeg_ for an external command or anything else, you need to build a Docker image that contains both _rtsp-simple-server_ and _FFmpeg_, by following instructions [here](https://github.com/bluenviron/mediamtx/discussions/278#discussioncomment-549104). ### OpenWRT package
### OpenWRT
1. In a x86 Linux system, download the OpenWRT SDK corresponding to the wanted OpenWRT version and target from the [OpenWRT website](https://downloads.openwrt.org/releases/) and extract it. 1. In a x86 Linux system, download the OpenWRT SDK corresponding to the wanted OpenWRT version and target from the [OpenWRT website](https://downloads.openwrt.org/releases/) and extract it.

8
scripts/binaries.mk

@ -19,9 +19,9 @@ WORKDIR /s
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
COPY . ./ COPY . ./
ENV VERSION $(shell git describe --tags) ARG VERSION
ENV CGO_ENABLED 0 ENV CGO_ENABLED 0
RUN rm -rf binaries RUN rm -rf tmp binaries
RUN mkdir tmp binaries RUN mkdir tmp binaries
RUN cp mediamtx.yml LICENSE tmp/ RUN cp mediamtx.yml LICENSE tmp/
@ -71,6 +71,8 @@ endef
export DOCKERFILE_BINARIES export DOCKERFILE_BINARIES
binaries: binaries:
echo "$$DOCKERFILE_BINARIES" | DOCKER_BUILDKIT=1 docker build . -f - -t temp echo "$$DOCKERFILE_BINARIES" | DOCKER_BUILDKIT=1 docker build . -f - \
--build-arg VERSION=$$(git describe --tags) \
-t temp
docker run --rm -v $(PWD):/out \ docker run --rm -v $(PWD):/out \
temp sh -c "rm -rf /out/binaries && cp -r /s/binaries /out/" temp sh -c "rm -rf /out/binaries && cp -r /s/binaries /out/"

131
scripts/dockerhub.mk

@ -1,110 +1,111 @@
REPOSITORY = aler9/rtsp-simple-server
define DOCKERFILE_DOCKERHUB define DOCKERFILE_DOCKERHUB
FROM scratch FROM scratch
ARG BINARY ARG TARGETPLATFORM
ADD $$BINARY / ADD tmp/binaries/$$TARGETPLATFORM.tar.gz /
ENTRYPOINT [ "/mediamtx" ] ENTRYPOINT [ "/mediamtx" ]
endef endef
export DOCKERFILE_DOCKERHUB export DOCKERFILE_DOCKERHUB
define DOCKERFILE_DOCKERHUB_RPI_32 define DOCKERFILE_DOCKERHUB_FFMPEG
FROM $(RPI32_IMAGE) AS base FROM $(ALPINE_IMAGE)
RUN apt update && apt install -y --no-install-recommends libcamera0 libfreetype6 RUN apk add --no-cache ffmpeg
ARG BINARY ARG TARGETPLATFORM
ADD $$BINARY / ADD tmp/binaries/$$TARGETPLATFORM.tar.gz /
ENTRYPOINT [ "/mediamtx" ] ENTRYPOINT [ "/mediamtx" ]
endef endef
export DOCKERFILE_DOCKERHUB_RPI_32 export DOCKERFILE_DOCKERHUB_FFMPEG
define DOCKERFILE_DOCKERHUB_RPI_BASE_32
FROM $(RPI32_IMAGE)
endef
export DOCKERFILE_DOCKERHUB_RPI_BASE_32
define DOCKERFILE_DOCKERHUB_RPI_64 define DOCKERFILE_DOCKERHUB_RPI_BASE_64
FROM $(RPI64_IMAGE) FROM $(RPI64_IMAGE)
endef
export DOCKERFILE_DOCKERHUB_RPI_BASE_64
define DOCKERFILE_DOCKERHUB_RPI
FROM scratch
ARG TARGETPLATFORM
ADD tmp/rpi_base/$$TARGETPLATFORM.tar /
RUN apt update && apt install -y --no-install-recommends libcamera0 libfreetype6 RUN apt update && apt install -y --no-install-recommends libcamera0 libfreetype6
ARG BINARY ADD tmp/binaries/$$TARGETPLATFORM.tar.gz /
ADD $$BINARY /
ENTRYPOINT [ "/mediamtx" ] ENTRYPOINT [ "/mediamtx" ]
endef endef
export DOCKERFILE_DOCKERHUB_RPI_64 export DOCKERFILE_DOCKERHUB_RPI
define DOCKERFILE_DOCKERHUB_FFMPEG_RPI
FROM scratch
ARG TARGETPLATFORM
ADD tmp/rpi_base/$$TARGETPLATFORM.tar /
RUN apt update && apt install -y --no-install-recommends libcamera0 libfreetype6 ffmpeg
ADD tmp/binaries/$$TARGETPLATFORM.tar.gz /
ENTRYPOINT [ "/mediamtx" ]
endef
export DOCKERFILE_DOCKERHUB_FFMPEG_RPI
dockerhub: dockerhub:
$(eval export DOCKER_CLI_EXPERIMENTAL=enabled) $(eval VERSION := $(shell git describe --tags | tr -d v))
$(eval VERSION := $(shell git describe --tags))
docker login -u $(DOCKER_USER) -p $(DOCKER_PASSWORD) docker login -u $(DOCKER_USER) -p $(DOCKER_PASSWORD)
rm -rf tmp
mkdir -p tmp tmp/binaries/linux/arm tmp/rpi_base/linux/arm
cp binaries/*linux_amd64.tar.gz tmp/binaries/linux/amd64.tar.gz
cp binaries/*linux_armv6.tar.gz tmp/binaries/linux/arm/v6.tar.gz
cp binaries/*linux_armv7.tar.gz tmp/binaries/linux/arm/v7.tar.gz
cp binaries/*linux_arm64v8.tar.gz tmp/binaries/linux/arm64.tar.gz
docker buildx rm builder 2>/dev/null || true docker buildx rm builder 2>/dev/null || true
rm -rf $$HOME/.docker/manifests/* rm -rf $$HOME/.docker/manifests/*
docker buildx create --name=builder --use docker buildx create --name=builder --use
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \ echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \
--provenance=false \ --provenance=false \
--platform=linux/amd64 \ --platform=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \
--build-arg BINARY="$$(echo binaries/*linux_amd64.tar.gz)" \ -t $(REPOSITORY):$(VERSION) \
-t aler9/rtsp-simple-server:$(VERSION)-amd64 \ -t $(REPOSITORY):latest \
-t aler9/rtsp-simple-server:latest-amd64 \
--push --push
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \ echo "$$DOCKERFILE_DOCKERHUB_FFMPEG" | docker buildx build . -f - \
--provenance=false \ --provenance=false \
--platform=linux/arm/v6 \ --platform=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \
--build-arg BINARY="$$(echo binaries/*linux_armv6.tar.gz)" \ -t $(REPOSITORY):$(VERSION)-ffmpeg \
-t aler9/rtsp-simple-server:$(VERSION)-armv6 \ -t $(REPOSITORY):latest-ffmpeg \
-t aler9/rtsp-simple-server:latest-armv6 \
--push --push
echo "$$DOCKERFILE_DOCKERHUB_RPI_32" | docker buildx build . -f - \ echo "$$DOCKERFILE_DOCKERHUB_RPI_BASE_32" | docker buildx build . -f - \
--provenance=false \ --provenance=false \
--platform=linux/arm/v6 \ --platform=linux/arm/v6 \
--build-arg BINARY="$$(echo binaries/*linux_armv6.tar.gz)" \ --output type=tar,dest=tmp/rpi_base/linux/arm/v6.tar
-t aler9/rtsp-simple-server:$(VERSION)-armv6-rpi \
-t aler9/rtsp-simple-server:latest-armv6-rpi \
--push
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \ echo "$$DOCKERFILE_DOCKERHUB_RPI_BASE_32" | docker buildx build . -f - \
--provenance=false \ --provenance=false \
--platform=linux/arm/v7 \ --platform=linux/arm/v7 \
--build-arg BINARY="$$(echo binaries/*linux_armv7.tar.gz)" \ --output type=tar,dest=tmp/rpi_base/linux/arm/v7.tar
-t aler9/rtsp-simple-server:$(VERSION)-armv7 \
-t aler9/rtsp-simple-server:latest-armv7 \
--push
echo "$$DOCKERFILE_DOCKERHUB_RPI_32" | docker buildx build . -f - \ echo "$$DOCKERFILE_DOCKERHUB_RPI_BASE_64" | docker buildx build . -f - \
--provenance=false \ --provenance=false \
--platform=linux/arm/v7 \ --platform=linux/arm64/v8 \
--build-arg BINARY="$$(echo binaries/*linux_armv7.tar.gz)" \ --output type=tar,dest=tmp/rpi_base/linux/arm64.tar
-t aler9/rtsp-simple-server:$(VERSION)-armv7-rpi \
-t aler9/rtsp-simple-server:latest-armv7-rpi \
--push
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \ echo "$$DOCKERFILE_DOCKERHUB_RPI" | docker buildx build . -f - \
--provenance=false \ --provenance=false \
--platform=linux/arm64/v8 \ --platform=linux/arm/v6,linux/arm/v7,linux/arm64/v8 \
--build-arg BINARY="$$(echo binaries/*linux_arm64v8.tar.gz)" \ -t $(REPOSITORY):$(VERSION)-rpi \
-t aler9/rtsp-simple-server:$(VERSION)-arm64v8 \ -t $(REPOSITORY):latest-rpi \
-t aler9/rtsp-simple-server:latest-arm64v8 \
--push --push
echo "$$DOCKERFILE_DOCKERHUB_RPI_64" | docker buildx build . -f - \ echo "$$DOCKERFILE_DOCKERHUB_FFMPEG_RPI" | docker buildx build . -f - \
--provenance=false \ --provenance=false \
--platform=linux/arm64/v8 \ --platform=linux/arm/v6,linux/arm/v7,linux/arm64/v8 \
--build-arg BINARY="$$(echo binaries/*linux_arm64v8.tar.gz)" \ -t $(REPOSITORY):$(VERSION)-ffmpeg-rpi \
-t aler9/rtsp-simple-server:$(VERSION)-arm64v8-rpi \ -t $(REPOSITORY):latest-ffmpeg-rpi \
-t aler9/rtsp-simple-server:latest-arm64v8-rpi \
--push --push
docker manifest create aler9/rtsp-simple-server:$(VERSION)-rpi \
$(foreach ARCH,armv6 armv7 arm64v8,aler9/rtsp-simple-server:$(VERSION)-$(ARCH)-rpi)
docker manifest push aler9/rtsp-simple-server:$(VERSION)-rpi
docker manifest create aler9/rtsp-simple-server:$(VERSION) \
$(foreach ARCH,amd64 armv6 armv7 arm64v8,aler9/rtsp-simple-server:$(VERSION)-$(ARCH))
docker manifest push aler9/rtsp-simple-server:$(VERSION)
docker manifest create aler9/rtsp-simple-server:latest-rpi \
$(foreach ARCH,armv6 armv7 arm64v8,aler9/rtsp-simple-server:$(VERSION)-$(ARCH)-rpi)
docker manifest push aler9/rtsp-simple-server:latest-rpi
docker manifest create aler9/rtsp-simple-server:latest \
$(foreach ARCH,amd64 armv6 armv7 arm64v8,aler9/rtsp-simple-server:$(VERSION)-$(ARCH))
docker manifest push aler9/rtsp-simple-server:latest
docker buildx rm builder docker buildx rm builder
rm -rf $$HOME/.docker/manifests/* rm -rf $$HOME/.docker/manifests/*

Loading…
Cancel
Save