-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move docker image to bluenviron/mavp2p (#37)
- Loading branch information
Showing
6 changed files
with
87 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/tmp | ||
/binaries | ||
coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,49 @@ | ||
define DOCKERFILE_RELEASE | ||
FROM $(BASE_IMAGE) | ||
BINARY_NAME = mavp2p | ||
|
||
define DOCKERFILE_BINARIES | ||
FROM $(BASE_IMAGE) AS build-base | ||
RUN apk add --no-cache zip make git tar | ||
WORKDIR /s | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
COPY . ./ | ||
RUN make binaries-nodocker | ||
endef | ||
export DOCKERFILE_RELEASE | ||
ARG VERSION | ||
ENV CGO_ENABLED 0 | ||
RUN rm -rf tmp binaries | ||
RUN mkdir tmp binaries | ||
|
||
binaries: | ||
echo "$$DOCKERFILE_RELEASE" | docker build . -f - -t temp \ | ||
&& docker run --rm -v $(PWD):/out \ | ||
temp sh -c "rm -rf /out/binaries && cp -r /s/binaries /out/" | ||
FROM build-base AS build-windows-amd64 | ||
RUN GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$$VERSION" -o tmp/$(BINARY_NAME).exe | ||
RUN cd tmp && zip -q ../binaries/$(BINARY_NAME)_$${VERSION}_windows_amd64.zip $(BINARY_NAME).exe | ||
|
||
binaries-nodocker: | ||
$(eval VERSION := $(shell git describe --tags)) | ||
$(eval GOBUILD := go build -ldflags '-X "main.version=$(VERSION)"') | ||
rm -rf binaries && mkdir binaries | ||
FROM build-base AS build-linux-amd64 | ||
RUN GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$$VERSION" -o tmp/$(BINARY_NAME) | ||
RUN tar -C tmp -czf binaries/$(BINARY_NAME)_$${VERSION}_linux_amd64.tar.gz --owner=0 --group=0 $(BINARY_NAME) | ||
|
||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o /tmp/mavp2p.exe | ||
cd /tmp && zip -q $(PWD)/binaries/mavp2p_$(VERSION)_windows_amd64.zip mavp2p.exe | ||
FROM build-base AS build-linux-armv6 | ||
RUN GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "-X main.version=$$VERSION" -o tmp/$(BINARY_NAME) | ||
RUN tar -C tmp -czf binaries/$(BINARY_NAME)_$${VERSION}_linux_armv6.tar.gz --owner=0 --group=0 $(BINARY_NAME) | ||
|
||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o /tmp/mavp2p | ||
tar -C /tmp -czf $(PWD)/binaries/mavp2p_$(VERSION)_linux_amd64.tar.gz --owner=0 --group=0 mavp2p | ||
FROM build-base AS build-linux-armv7 | ||
RUN GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-X main.version=$$VERSION" -o tmp/$(BINARY_NAME) | ||
RUN tar -C tmp -czf binaries/$(BINARY_NAME)_$${VERSION}_linux_armv7.tar.gz --owner=0 --group=0 $(BINARY_NAME) | ||
|
||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -o /tmp/mavp2p | ||
tar -C /tmp -czf $(PWD)/binaries/mavp2p_$(VERSION)_linux_arm6.tar.gz --owner=0 --group=0 mavp2p | ||
FROM build-base AS build-linux-arm64 | ||
RUN GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=$$VERSION" -o tmp/$(BINARY_NAME) | ||
RUN tar -C tmp -czf binaries/$(BINARY_NAME)_$${VERSION}_linux_arm64v8.tar.gz --owner=0 --group=0 $(BINARY_NAME) | ||
|
||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -o /tmp/mavp2p | ||
tar -C /tmp -czf $(PWD)/binaries/mavp2p_$(VERSION)_linux_arm7.tar.gz --owner=0 --group=0 mavp2p | ||
FROM $(BASE_IMAGE) | ||
COPY --from=build-windows-amd64 /s/binaries /s/binaries | ||
COPY --from=build-linux-amd64 /s/binaries /s/binaries | ||
COPY --from=build-linux-armv6 /s/binaries /s/binaries | ||
COPY --from=build-linux-armv7 /s/binaries /s/binaries | ||
COPY --from=build-linux-arm64 /s/binaries /s/binaries | ||
endef | ||
export DOCKERFILE_BINARIES | ||
|
||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GOBUILD) -o /tmp/mavp2p | ||
tar -C /tmp -czf $(PWD)/binaries/mavp2p_$(VERSION)_linux_arm64.tar.gz --owner=0 --group=0 mavp2p | ||
binaries: | ||
echo "$$DOCKERFILE_BINARIES" | DOCKER_BUILDKIT=1 docker build . -f - \ | ||
--build-arg VERSION=$$(git describe --tags) \ | ||
-t temp | ||
docker run --rm -v $(PWD):/out \ | ||
temp sh -c "rm -rf /out/binaries && cp -r /s/binaries /out/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,36 @@ | ||
define DOCKERFILE_DOCKERHUB | ||
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 /mavp2p | ||
DOCKER_REPOSITORY = bluenviron/mavp2p | ||
|
||
define DOCKERFILE_DOCKERHUB | ||
FROM scratch | ||
COPY --from=build /mavp2p / | ||
ARG TARGETPLATFORM | ||
ADD tmp/binaries/$$TARGETPLATFORM.tar.gz / | ||
ENTRYPOINT [ "/mavp2p" ] | ||
endef | ||
export DOCKERFILE_DOCKERHUB | ||
|
||
dockerhub: | ||
$(eval export DOCKER_CLI_EXPERIMENTAL=enabled) | ||
$(eval VERSION := $(shell git describe --tags)) | ||
$(eval VERSION := $(shell git describe --tags | tr -d v)) | ||
|
||
docker login -u $(DOCKER_USER) -p $(DOCKER_PASSWORD) | ||
|
||
rm -rf tmp | ||
mkdir -p tmp tmp/binaries/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 | ||
rm -rf $$HOME/.docker/manifests/* | ||
docker buildx create --name=builder --use | ||
|
||
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \ | ||
--provenance=false \ | ||
--platform=linux/amd64 \ | ||
--build-arg VERSION=$(VERSION) \ | ||
--push -t aler9/mavp2p:$(VERSION)-amd64 --build-arg OPTS="GOOS=linux GOARCH=amd64" | ||
|
||
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \ | ||
--provenance=false \ | ||
--platform=linux/arm/v6 \ | ||
--build-arg VERSION=$(VERSION) \ | ||
--push -t aler9/mavp2p:$(VERSION)-armv6 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=6" | ||
|
||
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \ | ||
--provenance=false \ | ||
--platform=linux/arm/v7 \ | ||
--build-arg VERSION=$(VERSION) \ | ||
--push -t aler9/mavp2p:$(VERSION)-armv7 --build-arg OPTS="GOOS=linux GOARCH=arm GOARM=7" | ||
|
||
echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \ | ||
--provenance=false \ | ||
--platform=linux/arm64/v8 \ | ||
--build-arg VERSION=$(VERSION) \ | ||
--push -t aler9/mavp2p:$(VERSION)-arm64v8 --build-arg OPTS="GOOS=linux GOARCH=arm64" | ||
|
||
docker manifest create aler9/mavp2p:$(VERSION) \ | ||
$(foreach ARCH,amd64 armv6 armv7 arm64v8,aler9/mavp2p:$(VERSION)-$(ARCH)) | ||
docker manifest push aler9/mavp2p:$(VERSION) | ||
|
||
docker manifest create aler9/mavp2p:latest-amd64 aler9/mavp2p:$(VERSION)-amd64 | ||
docker manifest push aler9/mavp2p:latest-amd64 | ||
|
||
docker manifest create aler9/mavp2p:latest-armv6 aler9/mavp2p:$(VERSION)-armv6 | ||
docker manifest push aler9/mavp2p:latest-armv6 | ||
|
||
docker manifest create aler9/mavp2p:latest-armv7 aler9/mavp2p:$(VERSION)-armv7 | ||
docker manifest push aler9/mavp2p:latest-armv7 | ||
|
||
docker manifest create aler9/mavp2p:latest-arm64v8 aler9/mavp2p:$(VERSION)-arm64v8 | ||
docker manifest push aler9/mavp2p:latest-arm64v8 | ||
|
||
docker manifest create aler9/mavp2p:latest \ | ||
$(foreach ARCH,amd64 armv6 armv7 arm64v8,aler9/mavp2p:$(VERSION)-$(ARCH)) | ||
docker manifest push aler9/mavp2p:latest | ||
--platform=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \ | ||
-t $(DOCKER_REPOSITORY):$(VERSION) \ | ||
-t $(DOCKER_REPOSITORY):latest \ | ||
--push | ||
|
||
docker buildx rm builder | ||
rm -rf $$HOME/.docker/manifests/* |