2019-12-28 21:07:03 +00:00
|
|
|
|
2020-10-28 22:03:44 +00:00
|
|
|
BASE_IMAGE = golang:1.15-alpine3.12
|
2020-12-30 16:15:00 +00:00
|
|
|
GO_LINT_IMAGE = golangci/golangci-lint:v1.33.0
|
2019-12-28 21:07:03 +00:00
|
|
|
|
2020-08-07 10:02:02 +00:00
|
|
|
.PHONY: $(shell ls)
|
|
|
|
|
2019-12-28 21:07:03 +00:00
|
|
|
help:
|
|
|
|
@echo "usage: make [action]"
|
|
|
|
@echo ""
|
|
|
|
@echo "available actions:"
|
|
|
|
@echo ""
|
2020-01-03 21:39:55 +00:00
|
|
|
@echo " mod-tidy run go mod tidy"
|
|
|
|
@echo " format format source files"
|
2020-12-05 19:42:59 +00:00
|
|
|
@echo " test run tests"
|
|
|
|
@echo " lint run linters"
|
2021-01-06 22:24:05 +00:00
|
|
|
@echo " bench NAME=n run bench environment"
|
2020-07-09 20:57:43 +00:00
|
|
|
@echo " run run app"
|
2020-01-03 21:39:55 +00:00
|
|
|
@echo " release build release assets"
|
2020-06-21 19:07:04 +00:00
|
|
|
@echo " dockerhub build and push docker hub images"
|
2019-12-28 21:07:03 +00:00
|
|
|
@echo ""
|
|
|
|
|
2020-05-10 19:32:40 +00:00
|
|
|
blank :=
|
|
|
|
define NL
|
|
|
|
|
|
|
|
$(blank)
|
|
|
|
endef
|
|
|
|
|
2019-12-28 21:07:03 +00:00
|
|
|
mod-tidy:
|
2020-06-21 19:07:04 +00:00
|
|
|
docker run --rm -it -v $(PWD):/s amd64/$(BASE_IMAGE) \
|
2020-07-27 13:23:40 +00:00
|
|
|
sh -c "apk add git && cd /s && GOPROXY=direct go get && go mod tidy"
|
2019-12-28 21:07:03 +00:00
|
|
|
|
|
|
|
format:
|
2020-06-21 19:07:04 +00:00
|
|
|
docker run --rm -it -v $(PWD):/s amd64/$(BASE_IMAGE) \
|
2019-12-28 21:07:03 +00:00
|
|
|
sh -c "cd /s && find . -type f -name '*.go' | xargs gofmt -l -w -s"
|
|
|
|
|
2020-05-10 19:32:40 +00:00
|
|
|
define DOCKERFILE_TEST
|
2020-06-21 19:07:04 +00:00
|
|
|
FROM amd64/$(BASE_IMAGE)
|
2020-09-03 14:31:58 +00:00
|
|
|
RUN apk add --no-cache make docker-cli git ffmpeg gcc musl-dev
|
2020-05-10 19:32:40 +00:00
|
|
|
WORKDIR /s
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
COPY . ./
|
|
|
|
endef
|
|
|
|
export DOCKERFILE_TEST
|
|
|
|
|
|
|
|
test:
|
|
|
|
echo "$$DOCKERFILE_TEST" | docker build -q . -f - -t temp
|
2020-12-04 22:22:39 +00:00
|
|
|
docker run --rm \
|
2020-05-10 19:32:40 +00:00
|
|
|
-v /var/run/docker.sock:/var/run/docker.sock:ro \
|
|
|
|
temp \
|
|
|
|
make test-nodocker
|
|
|
|
|
|
|
|
test-nodocker:
|
2020-09-20 08:21:37 +00:00
|
|
|
$(foreach IMG,$(shell echo testimages/*/ | xargs -n1 basename), \
|
|
|
|
docker build -q testimages/$(IMG) -t rtsp-simple-server-test-$(IMG)$(NL))
|
2021-01-28 19:25:43 +00:00
|
|
|
go test -race -v ./internal/...
|
2020-09-03 14:31:58 +00:00
|
|
|
go test -race -v .
|
2020-05-10 19:32:40 +00:00
|
|
|
|
2020-12-05 19:42:59 +00:00
|
|
|
lint:
|
|
|
|
docker run --rm -v $(PWD):/app -w /app \
|
2020-12-30 16:15:00 +00:00
|
|
|
$(GO_LINT_IMAGE) \
|
2020-12-06 11:22:00 +00:00
|
|
|
golangci-lint run -v
|
2020-12-05 19:42:59 +00:00
|
|
|
|
2021-01-06 22:24:05 +00:00
|
|
|
bench:
|
|
|
|
docker build -q . -f bench/$(NAME)/Dockerfile -t temp
|
2020-12-16 12:23:42 +00:00
|
|
|
docker run --rm -it -p 9999:9999 temp
|
2020-09-18 17:59:07 +00:00
|
|
|
|
2020-06-08 19:36:42 +00:00
|
|
|
define DOCKERFILE_RUN
|
2020-06-21 19:07:04 +00:00
|
|
|
FROM amd64/$(BASE_IMAGE)
|
2020-07-13 09:51:17 +00:00
|
|
|
RUN apk add --no-cache git ffmpeg
|
2020-06-08 19:36:42 +00:00
|
|
|
WORKDIR /s
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
COPY . ./
|
2020-07-27 13:23:40 +00:00
|
|
|
RUN go build -o /out .
|
2020-10-16 20:49:49 +00:00
|
|
|
WORKDIR /
|
|
|
|
ARG CONFIG_RUN
|
|
|
|
RUN echo "$$CONFIG_RUN" > rtsp-simple-server.yml
|
2020-06-08 19:36:42 +00:00
|
|
|
endef
|
|
|
|
export DOCKERFILE_RUN
|
|
|
|
|
2020-07-09 20:57:43 +00:00
|
|
|
define CONFIG_RUN
|
2020-07-12 10:34:35 +00:00
|
|
|
#rtspPort: 8555
|
|
|
|
#rtpPort: 8002
|
|
|
|
#rtcpPort: 8003
|
2020-07-30 17:21:36 +00:00
|
|
|
#metrics: yes
|
2020-09-18 17:59:07 +00:00
|
|
|
#pprof: yes
|
2020-07-12 10:34:35 +00:00
|
|
|
|
2020-07-09 20:57:43 +00:00
|
|
|
paths:
|
|
|
|
all:
|
2020-11-01 16:33:06 +00:00
|
|
|
# runOnPublish: ffmpeg -i rtsp://localhost:$$RTSP_PORT/$$RTSP_PATH -c copy -f mpegts myfile_$$RTSP_PATH.ts
|
2020-07-13 09:51:17 +00:00
|
|
|
# readUser: test
|
|
|
|
# readPass: tast
|
2020-11-01 16:33:06 +00:00
|
|
|
# runOnDemand: ffmpeg -re -stream_loop -1 -i testimages/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:$$RTSP_PORT/$$RTSP_PATH
|
2020-07-13 09:51:17 +00:00
|
|
|
|
2020-08-15 20:43:57 +00:00
|
|
|
# proxied:
|
2020-11-01 16:33:06 +00:00
|
|
|
# source: rtsp://192.168.2.198:554/stream
|
2020-07-30 11:31:18 +00:00
|
|
|
# sourceProtocol: tcp
|
|
|
|
# sourceOnDemand: yes
|
2020-11-01 16:33:06 +00:00
|
|
|
# runOnDemand: ffmpeg -i rtsp://192.168.2.198:554/stream -c copy -f rtsp rtsp://localhost:$$RTSP_PORT/proxied2
|
2020-07-13 09:51:17 +00:00
|
|
|
|
2020-07-19 20:39:38 +00:00
|
|
|
# original:
|
2020-11-01 16:33:06 +00:00
|
|
|
# runOnPublish: 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
|
2020-07-12 10:34:35 +00:00
|
|
|
|
2020-07-09 20:57:43 +00:00
|
|
|
endef
|
|
|
|
export CONFIG_RUN
|
|
|
|
|
2020-06-08 19:36:42 +00:00
|
|
|
run:
|
2020-10-16 20:49:49 +00:00
|
|
|
echo "$$DOCKERFILE_RUN" | docker build -q . -f - -t temp \
|
|
|
|
--build-arg CONFIG_RUN="$$CONFIG_RUN"
|
2020-06-08 19:36:42 +00:00
|
|
|
docker run --rm -it \
|
2020-06-14 15:46:27 +00:00
|
|
|
--network=host \
|
2020-06-08 19:36:42 +00:00
|
|
|
temp \
|
2020-10-16 20:49:49 +00:00
|
|
|
sh -c "/out"
|
2020-06-08 19:36:42 +00:00
|
|
|
|
2019-12-28 21:07:03 +00:00
|
|
|
define DOCKERFILE_RELEASE
|
2020-06-21 19:07:04 +00:00
|
|
|
FROM amd64/$(BASE_IMAGE)
|
2019-12-28 21:07:03 +00:00
|
|
|
RUN apk add --no-cache zip make git tar
|
|
|
|
WORKDIR /s
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
COPY . ./
|
|
|
|
RUN make release-nodocker
|
|
|
|
endef
|
|
|
|
export DOCKERFILE_RELEASE
|
|
|
|
|
|
|
|
release:
|
|
|
|
echo "$$DOCKERFILE_RELEASE" | docker build . -f - -t temp \
|
2020-12-15 12:38:23 +00:00
|
|
|
&& docker run --rm -v $(PWD):/out \
|
2019-12-28 21:07:03 +00:00
|
|
|
temp sh -c "rm -rf /out/release && cp -r /s/release /out/"
|
|
|
|
|
|
|
|
release-nodocker:
|
2020-06-21 19:07:04 +00:00
|
|
|
$(eval export CGO_ENABLED=0)
|
2019-12-28 21:07:03 +00:00
|
|
|
$(eval VERSION := $(shell git describe --tags))
|
2020-11-24 20:45:44 +00:00
|
|
|
$(eval GOBUILD := go build -ldflags '-X main.version=$(VERSION)')
|
2020-06-30 13:12:39 +00:00
|
|
|
rm -rf tmp && mkdir tmp
|
2019-12-28 21:07:03 +00:00
|
|
|
rm -rf release && mkdir release
|
2020-07-13 15:27:04 +00:00
|
|
|
cp rtsp-simple-server.yml tmp/
|
2019-12-28 21:07:03 +00:00
|
|
|
|
2020-06-30 13:12:39 +00:00
|
|
|
GOOS=windows GOARCH=amd64 $(GOBUILD) -o tmp/rtsp-simple-server.exe
|
2020-07-13 15:27:04 +00:00
|
|
|
cd tmp && zip -q $(PWD)/release/rtsp-simple-server_$(VERSION)_windows_amd64.zip rtsp-simple-server.exe rtsp-simple-server.yml
|
2019-12-28 21:07:03 +00:00
|
|
|
|
2020-06-30 13:12:39 +00:00
|
|
|
GOOS=linux GOARCH=amd64 $(GOBUILD) -o tmp/rtsp-simple-server
|
2020-07-13 15:27:04 +00:00
|
|
|
tar -C tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_amd64.tar.gz --owner=0 --group=0 rtsp-simple-server rtsp-simple-server.yml
|
2019-12-28 21:07:03 +00:00
|
|
|
|
2020-06-30 13:12:39 +00:00
|
|
|
GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -o tmp/rtsp-simple-server
|
2020-07-13 15:27:04 +00:00
|
|
|
tar -C tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm6.tar.gz --owner=0 --group=0 rtsp-simple-server rtsp-simple-server.yml
|
2019-12-28 21:07:03 +00:00
|
|
|
|
2020-06-30 13:12:39 +00:00
|
|
|
GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -o tmp/rtsp-simple-server
|
2020-07-13 15:27:04 +00:00
|
|
|
tar -C tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm7.tar.gz --owner=0 --group=0 rtsp-simple-server rtsp-simple-server.yml
|
2019-12-28 21:07:03 +00:00
|
|
|
|
2020-06-30 13:12:39 +00:00
|
|
|
GOOS=linux GOARCH=arm64 $(GOBUILD) -o tmp/rtsp-simple-server
|
2020-07-21 21:41:59 +00:00
|
|
|
tar -C tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm64v8.tar.gz --owner=0 --group=0 rtsp-simple-server rtsp-simple-server.yml
|
2019-12-28 21:23:52 +00:00
|
|
|
|
2020-06-30 13:12:39 +00:00
|
|
|
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o tmp/rtsp-simple-server
|
2020-07-13 15:27:04 +00:00
|
|
|
tar -C tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_darwin_amd64.tar.gz --owner=0 --group=0 rtsp-simple-server rtsp-simple-server.yml
|
2020-04-16 02:39:51 +00:00
|
|
|
|
2020-07-27 13:23:40 +00:00
|
|
|
define DOCKERFILE_DOCKERHUB
|
2020-06-21 19:07:04 +00:00
|
|
|
FROM --platform=linux/amd64 $(BASE_IMAGE) AS build
|
|
|
|
RUN apk add --no-cache git
|
|
|
|
WORKDIR /s
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
COPY . ./
|
|
|
|
ARG VERSION
|
|
|
|
ARG OPTS
|
|
|
|
RUN export CGO_ENABLED=0 $${OPTS} \
|
2020-11-24 20:45:44 +00:00
|
|
|
&& go build -ldflags "-X main.version=$$VERSION" -o /rtsp-simple-server
|
2020-06-21 19:07:04 +00:00
|
|
|
|
|
|
|
FROM scratch
|
2020-11-01 19:36:50 +00:00
|
|
|
COPY --from=build /rtsp-simple-server /
|
|
|
|
COPY --from=build /s/rtsp-simple-server.yml /
|
2020-06-30 13:12:39 +00:00
|
|
|
ENTRYPOINT [ "/rtsp-simple-server" ]
|
2020-04-18 17:12:52 +00:00
|
|
|
endef
|
2020-07-27 13:23:40 +00:00
|
|
|
export DOCKERFILE_DOCKERHUB
|
2020-04-18 17:12:52 +00:00
|
|
|
|
2020-06-21 19:07:04 +00:00
|
|
|
dockerhub:
|
|
|
|
$(eval export DOCKER_CLI_EXPERIMENTAL=enabled)
|
|
|
|
$(eval VERSION := $(shell git describe --tags))
|
|
|
|
|
2020-12-15 12:38:23 +00:00
|
|
|
docker login -u $(DOCKER_USER) -p $(DOCKER_PASSWORD)
|
|
|
|
|
2020-07-20 12:35:00 +00:00
|
|
|
docker buildx rm builder 2>/dev/null || true
|
2020-07-20 13:53:01 +00:00
|
|
|
rm -rf $$HOME/.docker/manifests/*
|
2020-06-21 19:07:04 +00:00
|
|
|
docker buildx create --name=builder --use
|
|
|
|
|
2020-07-27 13:23:40 +00:00
|
|
|
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
|
2020-06-21 19:07:04 +00:00
|
|
|
--push -t aler9/rtsp-simple-server:$(VERSION)-amd64 --build-arg OPTS="GOOS=linux GOARCH=amd64" --platform=linux/amd64
|
|
|
|
|
2020-07-27 13:23:40 +00:00
|
|
|
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
|
2020-06-21 19:07:04 +00:00
|
|
|
--push -t aler9/rtsp-simple-server:$(VERSION)-armv6 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=6" --platform=linux/arm/v6
|
|
|
|
|
2020-07-27 13:23:40 +00:00
|
|
|
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
|
2020-06-21 19:07:04 +00:00
|
|
|
--push -t aler9/rtsp-simple-server:$(VERSION)-armv7 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=7" --platform=linux/arm/v7
|
|
|
|
|
2020-07-27 13:23:40 +00:00
|
|
|
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
|
2020-07-20 12:35:00 +00:00
|
|
|
--push -t aler9/rtsp-simple-server:$(VERSION)-arm64v8 --build-arg OPTS="GOOS=linux GOARCH=arm64" --platform=linux/arm64/v8
|
2020-06-21 19:07:04 +00:00
|
|
|
|
2020-07-20 13:53:01 +00:00
|
|
|
docker manifest create aler9/rtsp-simple-server:$(VERSION) \
|
2020-07-20 12:35:00 +00:00
|
|
|
$(foreach ARCH,amd64 armv6 armv7 arm64v8,aler9/rtsp-simple-server:$(VERSION)-$(ARCH))
|
2020-06-21 19:07:04 +00:00
|
|
|
docker manifest push aler9/rtsp-simple-server:$(VERSION)
|
|
|
|
|
2020-07-20 13:53:01 +00:00
|
|
|
docker manifest create aler9/rtsp-simple-server:latest-amd64 aler9/rtsp-simple-server:$(VERSION)-amd64
|
2020-07-20 12:35:00 +00:00
|
|
|
docker manifest push aler9/rtsp-simple-server:latest-amd64
|
2020-06-21 19:07:04 +00:00
|
|
|
|
2020-07-20 13:53:01 +00:00
|
|
|
docker manifest create aler9/rtsp-simple-server:latest-armv6 aler9/rtsp-simple-server:$(VERSION)-armv6
|
2020-07-20 12:35:00 +00:00
|
|
|
docker manifest push aler9/rtsp-simple-server:latest-armv6
|
2020-06-21 19:07:04 +00:00
|
|
|
|
2020-07-20 13:53:01 +00:00
|
|
|
docker manifest create aler9/rtsp-simple-server:latest-armv7 aler9/rtsp-simple-server:$(VERSION)-armv7
|
2020-07-20 12:35:00 +00:00
|
|
|
docker manifest push aler9/rtsp-simple-server:latest-armv7
|
2020-06-21 19:07:04 +00:00
|
|
|
|
2020-07-20 13:53:01 +00:00
|
|
|
docker manifest create aler9/rtsp-simple-server:latest-arm64v8 aler9/rtsp-simple-server:$(VERSION)-arm64v8
|
2020-07-20 12:35:00 +00:00
|
|
|
docker manifest push aler9/rtsp-simple-server:latest-arm64v8
|
2020-06-21 19:07:04 +00:00
|
|
|
|
2020-07-20 13:53:01 +00:00
|
|
|
docker manifest create aler9/rtsp-simple-server:latest \
|
|
|
|
$(foreach ARCH,amd64 armv6 armv7 arm64v8,aler9/rtsp-simple-server:$(VERSION)-$(ARCH))
|
2020-06-21 19:07:04 +00:00
|
|
|
docker manifest push aler9/rtsp-simple-server:latest
|
|
|
|
|
|
|
|
docker buildx rm builder
|
2020-07-20 13:53:01 +00:00
|
|
|
rm -rf $$HOME/.docker/manifests/*
|