11
22.PHONY : $(shell ls)
33
4- BASE_IMAGE = amd64/ golang:1.14-alpine3.11
4+ BASE_IMAGE = golang:1.14-alpine3.11
55
66help :
77 @echo " usage: make [action]"
1313 @echo " test run available tests"
1414 @echo " run ARGS=args run app"
1515 @echo " release build release assets"
16- @echo " travis-setup setup travis CI "
16+ @echo " dockerhub build and push docker hub images "
1717 @echo " "
1818
1919blank :=
@@ -23,15 +23,15 @@ $(blank)
2323endef
2424
2525mod-tidy :
26- docker run --rm -it -v $(PWD ) :/s $(BASE_IMAGE ) \
26+ docker run --rm -it -v $(PWD ) :/s amd64/ $(BASE_IMAGE ) \
2727 sh -c " apk add git && cd /s && GOPROXY=direct go get && GOPROXY=direct go mod tidy"
2828
2929format :
30- docker run --rm -it -v $(PWD ) :/s $(BASE_IMAGE ) \
30+ docker run --rm -it -v $(PWD ) :/s amd64/ $(BASE_IMAGE ) \
3131 sh -c " cd /s && find . -type f -name '*.go' | xargs gofmt -l -w -s"
3232
3333define DOCKERFILE_TEST
34- FROM $(BASE_IMAGE )
34+ FROM amd64/ $(BASE_IMAGE )
3535RUN apk add --no-cache make docker-cli git
3636WORKDIR /s
3737COPY go.mod go.sum ./
@@ -48,13 +48,13 @@ test:
4848 make test-nodocker
4949
5050test-nodocker :
51+ $(eval export CGO_ENABLED=0)
5152 $(foreach IMG,$(shell echo test-images/* / | xargs -n1 basename) , \
5253 docker build -q test-images/$(IMG ) -t rtsp-simple-server-test-$(IMG )$(NL ) )
53- $(eval export CGO_ENABLED = 0)
5454 go test -v .
5555
5656define DOCKERFILE_RUN
57- FROM $(BASE_IMAGE )
57+ FROM amd64/ $(BASE_IMAGE )
5858RUN apk add --no-cache git
5959WORKDIR /s
6060COPY go.mod go.sum ./
7272 /out $(ARGS )
7373
7474define DOCKERFILE_RELEASE
75- FROM $(BASE_IMAGE )
75+ FROM amd64/ $(BASE_IMAGE )
7676RUN apk add --no-cache zip make git tar
7777WORKDIR /s
7878COPY go.mod go.sum ./
@@ -88,39 +88,84 @@ release:
8888 temp sh -c " rm -rf /out/release && cp -r /s/release /out/"
8989
9090release-nodocker :
91+ $(eval export CGO_ENABLED=0)
9192 $(eval VERSION := $(shell git describe --tags) )
92- $(eval GOBUILD := go build -ldflags '-X " main.Version=$(VERSION ) " ')
93+ $(eval GOBUILD := go build -ldflags '-X main.Version=$(VERSION ) ')
9394 rm -rf release && mkdir release
9495
95- CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server.exe
96+ GOOS=windows GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server.exe
9697 cd /tmp && zip -q $(PWD)/release/rtsp-simple-server_$(VERSION)_windows_amd64.zip rtsp-simple-server.exe
9798
98- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server
99+ GOOS=linux GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server
99100 tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_amd64.tar.gz --owner=0 --group=0 rtsp-simple-server
100101
101- CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -o /tmp/rtsp-simple-server
102+ GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -o /tmp/rtsp-simple-server
102103 tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm6.tar.gz --owner=0 --group=0 rtsp-simple-server
103104
104- CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -o /tmp/rtsp-simple-server
105+ GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -o /tmp/rtsp-simple-server
105106 tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm7.tar.gz --owner=0 --group=0 rtsp-simple-server
106107
107- CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GOBUILD) -o /tmp/rtsp-simple-server
108+ GOOS=linux GOARCH=arm64 $(GOBUILD) -o /tmp/rtsp-simple-server
108109 tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_linux_arm64.tar.gz --owner=0 --group=0 rtsp-simple-server
109110
110- CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server
111+ GOOS=darwin GOARCH=amd64 $(GOBUILD) -o /tmp/rtsp-simple-server
111112 tar -C /tmp -czf $(PWD)/release/rtsp-simple-server_$(VERSION)_darwin_amd64.tar.gz --owner=0 --group=0 rtsp-simple-server
112113
113- define DOCKERFILE_TRAVIS
114- FROM ruby:alpine
115- RUN apk add --no-cache build-base git
116- RUN gem install travis
114+ define DOCKERFILE_IMAGE
115+ FROM --platform=linux/amd64 $(BASE_IMAGE ) AS build
116+ RUN apk add --no-cache git
117+ WORKDIR /s
118+ COPY go.mod go.sum ./
119+ RUN go mod download
120+ COPY . ./
121+ ARG VERSION
122+ ARG OPTS
123+ RUN export CGO_ENABLED=0 $${OPTS} \
124+ && go build -ldflags "-X main.Version=$$VERSION" -o /rtsp-simple-server
125+
126+ FROM scratch
127+ COPY --from=build /rtsp-simple-server /rtsp-simple-server
128+ ENTRYPOINT [ "/rtsp-simple-server"]
117129endef
118- export DOCKERFILE_TRAVIS
130+ export DOCKERFILE_IMAGE
119131
120- travis-setup :
121- echo " $$ DOCKERFILE_TRAVIS" | docker build - -t temp
122- docker run --rm -it \
123- -v $(PWD ) :/s \
124- temp \
125- sh -c " cd /s \
126- && travis setup releases --force"
132+ dockerhub :
133+ $(eval export DOCKER_CLI_EXPERIMENTAL=enabled)
134+ $(eval VERSION := $(shell git describe --tags) )
135+
136+ docker buildx rm test 2>/dev/null || true
137+ docker buildx create --name=builder --use
138+
139+ echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
140+ --push -t aler9/rtsp-simple-server:$(VERSION)-amd64 --build-arg OPTS="GOOS=linux GOARCH=amd64" --platform=linux/amd64
141+
142+ echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
143+ --push -t aler9/rtsp-simple-server:$(VERSION)-armv6 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=6" --platform=linux/arm/v6
144+
145+ echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
146+ --push -t aler9/rtsp-simple-server:$(VERSION)-armv7 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=7" --platform=linux/arm/v7
147+
148+ echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
149+ --push -t aler9/rtsp-simple-server:$(VERSION)-arm64 --build-arg OPTS="GOOS=linux GOARCH=arm64" --platform=linux/arm64/v8
150+
151+ docker manifest create --amend aler9/rtsp-simple-server:$(VERSION) \
152+ $(foreach ARCH,amd64 armv6 armv7 arm64,aler9/rtsp-simple-server:$(VERSION)-$(ARCH))
153+ docker manifest push aler9/rtsp-simple-server:$(VERSION)
154+
155+ echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
156+ --push -t aler9/rtsp-simple-server:latest-amd64 --build-arg OPTS="GOOS=linux GOARCH=amd64" --platform=linux/amd64
157+
158+ echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
159+ --push -t aler9/rtsp-simple-server:latest-armv6 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=6" --platform=linux/arm/v6
160+
161+ echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
162+ --push -t aler9/rtsp-simple-server:latest-armv7 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=7" --platform=linux/arm/v7
163+
164+ echo "$$DOCKERFILE_IMAGE" | docker buildx build . -f - --build-arg VERSION=$(VERSION) \
165+ --push -t aler9/rtsp-simple-server:latest-arm64 --build-arg OPTS="GOOS=linux GOARCH=arm64" --platform=linux/arm64/v8
166+
167+ docker manifest create --amend aler9/rtsp-simple-server:latest \
168+ $(foreach ARCH,amd64 armv6 armv7 arm64,aler9/rtsp-simple-server:latest-$(ARCH))
169+ docker manifest push aler9/rtsp-simple-server:latest
170+
171+ docker buildx rm builder
0 commit comments