Skip to content

Commit

Permalink
Testing automated builds on Dockerhub for multi-arch.
Browse files Browse the repository at this point in the history
  • Loading branch information
aquarat committed Apr 1, 2019
1 parent 48238d7 commit 28495c0
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM golang:1.11.1 as builder
LABEL stage=intermediate

COPY qemu-aarch64-static /usr/bin/

#compile linux only

ENV \
GOOS=linux \
VOLANTMQ_WORK_DIR=/usr/lib/volantmq \
VOLANTMQ_BUILD_FLAGS="-i" \
VOLANTMQ_PLUGINS_DIR=/usr/lib/volantmq/plugins

RUN mkdir -p $VOLANTMQ_WORK_DIR/bin
RUN mkdir -p $VOLANTMQ_WORK_DIR/conf
RUN mkdir -p $VOLANTMQ_PLUGINS_DIR

# Create environment directory
ENV PATH $VOLANTMQ_WORK_DIR/bin:$PATH

# install dep tool
RUN go get -u github.com/golang/dep/cmd/dep

# build server
RUN \
go get -v github.com/ahmetb/govvv && \
go get -v github.com/VolantMQ/vlapi/... && \
go get -v github.com/VolantMQ/volantmq && \
cd $GOPATH/src/github.com/VolantMQ/volantmq && \
govvv build $VOLANTMQ_BUILD_FLAGS -o $VOLANTMQ_WORK_DIR/bin/volantmq

# build debug plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/debug && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/debug.so

# build health plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/health && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/health.so

#build persistence plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/persistence/bbolt/plugin && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/persistence_bbolt.so

FROM ubuntu
ENV \
VOLANTMQ_WORK_DIR=/usr/lib/volantmq

COPY --from=builder $VOLANTMQ_WORK_DIR $VOLANTMQ_WORK_DIR

# Create environment directory
ENV PATH $VOLANTMQ_WORK_DIR/bin:$PATH
ENV VOLANTMQ_PLUGINS_DIR=$VOLANTMQ_WORK_DIR/plugins

# default config uses mqtt:1883
EXPOSE 1883
CMD ["volantmq"]
57 changes: 57 additions & 0 deletions Dockerfile.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM golang:1.11.1 as builder
LABEL stage=intermediate

#compile linux only

ENV \
GOOS=linux \
VOLANTMQ_WORK_DIR=/usr/lib/volantmq \
VOLANTMQ_BUILD_FLAGS="-i" \
VOLANTMQ_PLUGINS_DIR=/usr/lib/volantmq/plugins

RUN mkdir -p $VOLANTMQ_WORK_DIR/bin
RUN mkdir -p $VOLANTMQ_WORK_DIR/conf
RUN mkdir -p $VOLANTMQ_PLUGINS_DIR

# Create environment directory
ENV PATH $VOLANTMQ_WORK_DIR/bin:$PATH

# install dep tool
RUN go get -u github.com/golang/dep/cmd/dep

# build server
RUN \
go get -v github.com/ahmetb/govvv && \
go get -v github.com/VolantMQ/vlapi/... && \
go get -v github.com/VolantMQ/volantmq && \
cd $GOPATH/src/github.com/VolantMQ/volantmq && \
govvv build $VOLANTMQ_BUILD_FLAGS -o $VOLANTMQ_WORK_DIR/bin/volantmq

# build debug plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/debug && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/debug.so

# build health plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/health && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/health.so

#build persistence plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/persistence/bbolt/plugin && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/persistence_bbolt.so

FROM ubuntu
ENV \
VOLANTMQ_WORK_DIR=/usr/lib/volantmq

COPY --from=builder $VOLANTMQ_WORK_DIR $VOLANTMQ_WORK_DIR

# Create environment directory
ENV PATH $VOLANTMQ_WORK_DIR/bin:$PATH
ENV VOLANTMQ_PLUGINS_DIR=$VOLANTMQ_WORK_DIR/plugins

# default config uses mqtt:1883
EXPOSE 1883
CMD ["volantmq"]
59 changes: 59 additions & 0 deletions Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM golang:1.11.1 as builder
LABEL stage=intermediate

COPY qemu-arm-static /usr/bin/

#compile linux only

ENV \
GOOS=linux \
VOLANTMQ_WORK_DIR=/usr/lib/volantmq \
VOLANTMQ_BUILD_FLAGS="-i" \
VOLANTMQ_PLUGINS_DIR=/usr/lib/volantmq/plugins

RUN mkdir -p $VOLANTMQ_WORK_DIR/bin
RUN mkdir -p $VOLANTMQ_WORK_DIR/conf
RUN mkdir -p $VOLANTMQ_PLUGINS_DIR

# Create environment directory
ENV PATH $VOLANTMQ_WORK_DIR/bin:$PATH

# install dep tool
RUN go get -u github.com/golang/dep/cmd/dep

# build server
RUN \
go get -v github.com/ahmetb/govvv && \
go get -v github.com/VolantMQ/vlapi/... && \
go get -v github.com/VolantMQ/volantmq && \
cd $GOPATH/src/github.com/VolantMQ/volantmq && \
govvv build $VOLANTMQ_BUILD_FLAGS -o $VOLANTMQ_WORK_DIR/bin/volantmq

# build debug plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/debug && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/debug.so

# build health plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/health && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/health.so

#build persistence plugins
RUN \
cd $GOPATH/src/github.com/VolantMQ/vlapi/plugin/persistence/bbolt/plugin && \
go build $VOLANTMQ_BUILD_FLAGS -buildmode=plugin -o $VOLANTMQ_WORK_DIR/plugins/persistence_bbolt.so

FROM ubuntu
ENV \
VOLANTMQ_WORK_DIR=/usr/lib/volantmq

COPY --from=builder $VOLANTMQ_WORK_DIR $VOLANTMQ_WORK_DIR

# Create environment directory
ENV PATH $VOLANTMQ_WORK_DIR/bin:$PATH
ENV VOLANTMQ_PLUGINS_DIR=$VOLANTMQ_WORK_DIR/plugins

# default config uses mqtt:1883
EXPOSE 1883
CMD ["volantmq"]
8 changes: 8 additions & 0 deletions hooks/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# thanks https://stackoverflow.com/questions/54578066/how-to-build-a-docker-image-on-a-specific-architecture-with-docker-hub
docker build \
--file "${DOCKERFILE_PATH}" \
--build-arg BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--build-arg VCS_REF="$(git rev-parse --short HEAD)" \
--tag "$IMAGE_NAME" \
.
16 changes: 16 additions & 0 deletions hooks/post_checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

BUILD_ARCH=$(echo "${DOCKERFILE_PATH}" | cut -d '.' -f 2)
echo $BUILD_ARCH
[ "${BUILD_ARCH}" == "Dockerfile" ] && \
{ echo 'qemu-user-static: Download not required for current arch'; exit 0; }

QEMU_USER_STATIC_ARCH=$([ "${BUILD_ARCH}" == "armhf" ] && echo "${BUILD_ARCH::-2}" || echo "${BUILD_ARCH}")
QEMU_USER_STATIC_DOWNLOAD_URL="https://github.com/multiarch/qemu-user-static/releases/download"
QEMU_USER_STATIC_LATEST_TAG=$(curl -s https://api.github.com/repos/multiarch/qemu-user-static/tags \
| grep 'name.*v[0-9]' \
| head -n 1 \
| cut -d '"' -f 4)

curl -SL "${QEMU_USER_STATIC_DOWNLOAD_URL}/${QEMU_USER_STATIC_LATEST_TAG}/x86_64_qemu-${QEMU_USER_STATIC_ARCH}-static.tar.gz" \
| tar xzv
8 changes: 8 additions & 0 deletions hooks/pre-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

BUILD_ARCH=$(echo "${DOCKERFILE_PATH}" | cut -d '.' -f 2)

[ "${BUILD_ARCH}" == "Dockerfile" ] && \
{ echo 'qemu-user-static: Registration not required for current arch'; exit 0; }

docker run --rm --privileged multiarch/qemu-user-static:register --reset
Binary file added hooks/qemu-aarch64-static
Binary file not shown.
Binary file added hooks/qemu-arm-static
Binary file not shown.
7 changes: 7 additions & 0 deletions hooks/sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/qemu-arm-static /bin/sh.real

set -o errexit

cp /bin/sh.real /bin/sh
/bin/sh "$@"
cp /usr/bin/sh-shim /bin/sh

0 comments on commit 28495c0

Please sign in to comment.