mediamtx/Makefile

172 lines
6.0 KiB
Makefile
Raw Normal View History

2019-12-28 21:07:03 +00:00
.PHONY: $(shell ls)
2020-06-21 19:07:04 +00:00
BASE_IMAGE = golang:1.14-alpine3.11
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-06-08 19:36:42 +00:00
@echo " test run available tests"
2020-01-03 21:39:55 +00:00
@echo " run ARGS=args run app"
@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-01-20 11:53:06 +00:00
sh -c "apk add git && cd /s && GOPROXY=direct go get && GOPROXY=direct 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-05-10 19:32:40 +00:00
RUN apk add --no-cache make docker-cli git
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
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
temp \
make test-nodocker
test-nodocker:
2020-06-21 19:07:04 +00:00
$(eval export CGO_ENABLED=0)
2020-05-10 19:32:40 +00:00
$(foreach IMG,$(shell echo test-images/*/ | xargs -n1 basename), \
docker build -q test-images/$(IMG) -t rtsp-simple-server-test-$(IMG)$(NL))
go test -v .
2020-06-08 19:36:42 +00:00
define DOCKERFILE_RUN
2020-06-21 19:07:04 +00:00
FROM amd64/$(BASE_IMAGE)
2020-06-08 19:36:42 +00:00
RUN apk add --no-cache git
WORKDIR /s
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN GOPROXY=direct go build -o /out .
endef
export DOCKERFILE_RUN
run:
echo "$$DOCKERFILE_RUN" | docker build -q . -f - -t temp
docker run --rm -it \
--network=host \
2020-06-08 19:36:42 +00:00
temp \
/out $(ARGS)
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 \
&& docker run --rm -it -v $(PWD):/out \
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-06-21 19:07:04 +00:00
$(eval GOBUILD := go build -ldflags '-X main.Version=$(VERSION)')
2019-12-28 21:07:03 +00:00
rm -rf release && mkdir release
2020-06-21 19:07:04 +00:00
GOOS=windows GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server.exe
2019-12-28 21:07:03 +00:00
cd /tmp && zip -q $(PWD)/release/rtsp-simple-server_$(VERSION)_windows_amd64.zip rtsp-simple-server.exe
2020-06-21 19:07:04 +00:00
GOOS=linux GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server
2019-12-28 21:07:03 +00:00
tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_amd64.tar.gz --owner=0 --group=0 rtsp-simple-server
2020-06-21 19:07:04 +00:00
GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -o /tmp/rtsp-simple-server
2019-12-28 21:07:03 +00:00
tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm6.tar.gz --owner=0 --group=0 rtsp-simple-server
2020-06-21 19:07:04 +00:00
GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -o /tmp/rtsp-simple-server
2019-12-28 21:07:03 +00:00
tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm7.tar.gz --owner=0 --group=0 rtsp-simple-server
2020-06-21 19:07:04 +00:00
GOOS=linux GOARCH=arm64 $(GOBUILD) -o /tmp/rtsp-simple-server
2019-12-28 21:07:03 +00:00
tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm64.tar.gz --owner=0 --group=0 rtsp-simple-server
2019-12-28 21:23:52 +00:00
2020-06-21 19:07:04 +00:00
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server
tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_darwin_amd64.tar.gz --owner=0 --group=0 rtsp-simple-server
2020-06-21 19:07:04 +00:00
define DOCKERFILE_IMAGE
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} \
&& go build -ldflags "-X main.Version=$$VERSION" -o /rtsp-simple-server
FROM scratch
COPY --from=build /rtsp-simple-server /rtsp-simple-server
ENTRYPOINT [ "/rtsp-simple-server"]
2020-04-18 17:12:52 +00:00
endef
2020-06-21 19:07:04 +00:00
export DOCKERFILE_IMAGE
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))
docker buildx rm test 2>/dev/null || true
docker buildx create --name=builder --use
echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
--push -t aler9/rtsp-simple-server:$(VERSION)-amd64 --build-arg OPTS="GOOS=linux GOARCH=amd64" --platform=linux/amd64
echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
--push -t aler9/rtsp-simple-server:$(VERSION)-armv6 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=6" --platform=linux/arm/v6
echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
--push -t aler9/rtsp-simple-server:$(VERSION)-armv7 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=7" --platform=linux/arm/v7
echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
--push -t aler9/rtsp-simple-server:$(VERSION)-arm64 --build-arg OPTS="GOOS=linux GOARCH=arm64" --platform=linux/arm64/v8
docker manifest create --amend aler9/rtsp-simple-server:$(VERSION) \
$(foreach ARCH,amd64 armv6 armv7 arm64,aler9/rtsp-simple-server:$(VERSION)-$(ARCH))
docker manifest push aler9/rtsp-simple-server:$(VERSION)
echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
--push -t aler9/rtsp-simple-server:latest-amd64 --build-arg OPTS="GOOS=linux GOARCH=amd64" --platform=linux/amd64
echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
--push -t aler9/rtsp-simple-server:latest-armv6 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=6" --platform=linux/arm/v6
echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
--push -t aler9/rtsp-simple-server:latest-armv7 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=7" --platform=linux/arm/v7
echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
--push -t aler9/rtsp-simple-server:latest-arm64 --build-arg OPTS="GOOS=linux GOARCH=arm64" --platform=linux/arm64/v8
docker manifest create --amend aler9/rtsp-simple-server:latest \
$(foreach ARCH,amd64 armv6 armv7 arm64,aler9/rtsp-simple-server:latest-$(ARCH))
docker manifest push aler9/rtsp-simple-server:latest
docker buildx rm builder