Skip to content

Commit

Permalink
move docker image to bluenviron/mavp2p (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Aug 7, 2023
1 parent 9073111 commit 660a6b3
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 87 deletions.
33 changes: 28 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@ on:
- 'v*'

jobs:
github:
runs-on: ubuntu-20.04
binaries:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- run: make binaries

- uses: actions/upload-artifact@v3
with:
name: binaries
path: binaries

github:
needs: binaries
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: binaries
path: binaries

- uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -42,10 +59,16 @@ jobs:
}
dockerhub:
runs-on: ubuntu-20.04
needs: binaries
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: binaries
path: binaries

- run: make dockerhub
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/tmp
/binaries
coverage.txt
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BASE_IMAGE = golang:1.20-alpine3.17
BASE_IMAGE = golang:1.20-alpine3.18
LINT_IMAGE = golangci/golangci-lint:v1.53.3

.PHONY: $(shell ls)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Lint](https://github.com/bluenviron/mavp2p/workflows/lint/badge.svg)](https://github.com/bluenviron/mavp2p/actions?query=workflow:lint)
[![CodeCov](https://codecov.io/gh/bluenviron/mavp2p/branch/main/graph/badge.svg)](https://app.codecov.io/gh/bluenviron/mavp2p/branch/main)
[![Release](https://img.shields.io/github/v/release/bluenviron/mavp2p)](https://github.com/bluenviron/mavp2p/releases)
[![Docker Hub](https://img.shields.io/badge/docker-aler9/mavp2p-blue)](https://hub.docker.com/r/aler9/mavp2p)
[![Docker Hub](https://img.shields.io/badge/docker-bluenviron/mavp2p-blue)](https://hub.docker.com/r/bluenviron/mavp2p)

_mavp2p_ is a flexible and efficient Mavlink proxy / bridge / router, implemented in the form of a command-line utility. It is used primarily to link UAV flight controllers, connected through a serial port, with ground stations on a network, but can be used to build any kind of routing involving serial, TCP and UDP, allowing communication across different physical layers or transport layers.

Expand Down Expand Up @@ -44,10 +44,10 @@ Download and extract a standalone binary from the [release page](https://github.

### Docker image

There's a image available at `aler9/mavp2p`:
There's a image available at `bluenviron/mavp2p`:

```
docker run --rm -it --network=host -e COLUMNS=$COLUMNS aler9/mavp2p
docker run --rm -it --network=host bluenviron/mavp2p
```

### OpenWRT package
Expand Down
60 changes: 37 additions & 23 deletions scripts/binaries.mk
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/"
72 changes: 17 additions & 55 deletions scripts/dockerhub.mk
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/*

0 comments on commit 660a6b3

Please sign in to comment.