Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RaymondMouthaan committed Aug 1, 2018
2 parents f0eb081 + d7f6ac0 commit cd7b053
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 466 deletions.
12 changes: 6 additions & 6 deletions .docker/Dockerfile.alpine-tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG BASE_IMAGE
FROM $BASE_IMAGE
ARG BUILD_FROM
FROM ${BUILD_FROM}

# Build arguments
ARG BUILD_DATE
Expand All @@ -8,20 +8,20 @@ ARG BUILD_REF
ARG QEMU_ARCH

# Basic build-time metadata as defined at http://label-schema.org
LABEL org.label-schema.build-date=$BUILD_DATE \
LABEL org.label-schema.build-date=${BUILD_DATE} \
org.label-schema.docker.dockerfile=".docker/Dockerfile.alpine-tmpl" \
org.label-schema.license="GNU" \
org.label-schema.name="Emqtt" \
org.label-schema.version=$BUILD_VERSION \
org.label-schema.version=${BUILD_VERSION} \
org.label-schema.description="The Massively Scalable MQTT Broker for IoT and Mobile Applications" \
org.label-schema.url="http://emqtt.io/" \
org.label-schema.vcs-ref=$BUILD_REF \
org.label-schema.vcs-ref=${BUILD_REF} \
org.label-schema.vcs-type="Git" \
org.label-schema.vcs-url="https://github.com/RaymondMouthaan/emqtt-docker" \
maintainer="Raymond M Mouthaan <[email protected]>"

USER root
COPY tmp/qemu-$QEMU_ARCH-static /usr/bin/qemu-$QEMU_ARCH-static
COPY tmp/qemu-${QEMU_ARCH}-static /usr/bin/qemu-${QEMU_ARCH}-static

COPY ./start.sh /start.sh

Expand Down
133 changes: 60 additions & 73 deletions .docker/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,52 +38,39 @@ docker_prepare() {
}

docker_build() {
echo "DOCKER BUILD: Build all docker images."
#
docker build --build-arg BUILD_REF=$TRAVIS_COMMIT --build-arg BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") --build-arg BUILD_VERSION=$EMQ_VERSION --build-arg BASE_IMAGE=amd64/alpine --build-arg QEMU_ARCH=x86_64 --file ./.docker/Dockerfile.alpine-tmpl --tag $TARGET:build-alpine-amd64 .
docker build --build-arg BUILD_REF=$TRAVIS_COMMIT --build-arg BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") --build-arg BUILD_VERSION=$EMQ_VERSION --build-arg BASE_IMAGE=arm32v6/alpine --build-arg QEMU_ARCH=arm --file ./.docker/Dockerfile.alpine-tmpl --tag $TARGET:build-alpine-arm32v6 .
docker build --build-arg BUILD_REF=$TRAVIS_COMMIT --build-arg BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") --build-arg BUILD_VERSION=$EMQ_VERSION --build-arg BASE_IMAGE=arm64v8/alpine --build-arg QEMU_ARCH=aarch64 --file ./.docker/Dockerfile.alpine-tmpl --tag $TARGET:build-alpine-arm64v8 .
# Build Docker image
echo "DOCKER BUILD: Build Docker image."
echo "DOCKER BUILD: build version - ${BUILD_VERSION}."
echo "DOCKER BUILD: build from - ${BUILD_FROM}."
echo "DOCKER BUILD: qemu arch - ${QEMU_ARCH}."
echo "DOCKER BUILD: os arch - ${OS_ARCH}."

docker build --build-arg BUILD_REF=${TRAVIS_COMMIT} --build-arg BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") --build-arg BUILD_VERSION=${BUILD_VERSION} --build-arg BUILD_FROM=${BUILD_FROM} --build-arg QEMU_ARCH=${QEMU_ARCH} --file ./.docker/Dockerfile.alpine-tmpl --tag ${TARGET}:build-${OS_ARCH} .
}

docker_test() {
echo "DOCKER TEST: Test all docker images."
docker run -d --rm --name=test-alpine-amd64 $TARGET:build-alpine-amd64
if [ $? -ne 0 ]; then
echo "DOCKER TEST: FAILED - Docker container failed to start for build-alpine-amd64."
exit 1
else
echo "DOCKER TEST: PASSED - Docker container succeeded to start for build-alpine-amd64."
fi

docker run -d --rm --name=test-alpine-arm32v6 $TARGET:build-alpine-arm32v6
if [ $? -ne 0 ]; then
echo "DOCKER TEST: FAILED - Docker container failed to start for build-alpine-arm32v6."
exit 1
else
echo "DOCKER TEST: PASSED - Docker container succeeded to start for build-alpine-arm32v6."
fi
echo "DOCKER TEST: Test Docker image."
echo "DOCKER TEST: testing image - test-${OS_ARCH}."

docker run -d --rm --name=test-alpine-arm64v8 $TARGET:build-alpine-arm64v8
docker run -d --rm --name=test-${OS_ARCH} ${TARGET}:build-${OS_ARCH}
if [ $? -ne 0 ]; then
echo "DOCKER TEST: FAILED - Docker container failed to start for build-alpine-arm64v8."
echo "DOCKER TEST: FAILED - Docker container test-${OS_ARCH} failed to start."
exit 1
else
echo "DOCKER TEST: PASSED - Docker container succeeded to start for build-alpine-arm64v8."
echo "DOCKER TEST: PASSED - Docker container test-${OS_ARCH} succeeded to start."
fi
}

docker_tag() {
echo "DOCKER TAG: Tag all docker images."
docker tag $TARGET:build-alpine-amd64 $TARGET:$EMQ_VERSION-alpine-amd64
docker tag $TARGET:build-alpine-arm32v6 $TARGET:$EMQ_VERSION-alpine-arm32v6
docker tag $TARGET:build-alpine-arm64v8 $TARGET:$EMQ_VERSION-alpine-arm64v8
echo "DOCKER TAG: Tag Docker image."
echo "DOCKER TAG: tagging image - ${TARGET}:${BUILD_VERSION}-${OS_ARCH}."
docker tag ${TARGET}:build-${OS_ARCH} ${TARGET}:${BUILD_VERSION}-${OS_ARCH}
}

docker_push() {
echo "DOCKER PUSH: Push all docker images."
docker push $TARGET:$EMQ_VERSION-alpine-amd64
docker push $TARGET:$EMQ_VERSION-alpine-arm32v6
docker push $TARGET:$EMQ_VERSION-alpine-arm64v8
echo "DOCKER PUSH: Push Docker image."
echo "DOCKER PUSH: pushing - ${TARGET}:${BUILD_VERSION}-${OS_ARCH}."
docker push ${TARGET}:${BUILD_VERSION}-${OS_ARCH}
}

docker_manifest_list() {
Expand All @@ -95,67 +82,67 @@ docker_manifest_list() {
}

docker_manifest_list_version() {
# Manifest Create EMQ_VERSION
echo "DOCKER MANIFEST: Create and Push docker manifest list - $TARGET:$EMQ_VERSION."
docker manifest create $TARGET:$EMQ_VERSION \
$TARGET:$EMQ_VERSION-alpine-amd64 \
$TARGET:$EMQ_VERSION-alpine-arm32v6 \
$TARGET:$EMQ_VERSION-alpine-arm64v8

# Manifest Annotate EMQ_VERSION
docker manifest annotate $TARGET:$EMQ_VERSION $TARGET:$EMQ_VERSION-alpine-arm32v6 --os=linux --arch=arm --variant=v6
docker manifest annotate $TARGET:$EMQ_VERSION $TARGET:$EMQ_VERSION-alpine-arm64v8 --os=linux --arch=arm64 --variant=v8

# Manifest Push EMQ_VERSION
docker manifest push $TARGET:$EMQ_VERSION
# Manifest Create BUILD_VERSION
echo "DOCKER MANIFEST: Create and Push docker manifest list - ${TARGET}:${BUILD_VERSION}."
docker manifest create ${TARGET}:${BUILD_VERSION} \
${TARGET}:${BUILD_VERSION}-alpine-amd64 \
${TARGET}:${BUILD_VERSION}-alpine-arm32v6 \
${TARGET}:${BUILD_VERSION}-alpine-arm64v8

# Manifest Annotate BUILD_VERSION
docker manifest annotate ${TARGET}:${BUILD_VERSION} ${TARGET}:${BUILD_VERSION}-alpine-arm32v6 --os=linux --arch=arm --variant=v6
docker manifest annotate ${TARGET}:${BUILD_VERSION} ${TARGET}:${BUILD_VERSION}-alpine-arm64v8 --os=linux --arch=arm64 --variant=v8

# Manifest Push BUILD_VERSION
docker manifest push ${TARGET}:${BUILD_VERSION}
}

docker_manifest_list_latest() {
# Manifest Create latest
echo "DOCKER MANIFEST: Create and Push docker manifest list - $TARGET:latest."
docker manifest create $TARGET:latest \
$TARGET:$EMQ_VERSION-alpine-amd64 \
$TARGET:$EMQ_VERSION-alpine-arm32v6 \
$TARGET:$EMQ_VERSION-alpine-arm64v8

# Manifest Annotate EMQ_VERSION
docker manifest annotate $TARGET:latest $TARGET:$EMQ_VERSION-alpine-arm32v6 --os=linux --arch=arm --variant=v6
docker manifest annotate $TARGET:latest $TARGET:$EMQ_VERSION-alpine-arm64v8 --os=linux --arch=arm64 --variant=v8

# Manifest Push EMQ_VERSION
docker manifest push $TARGET:latest
echo "DOCKER MANIFEST: Create and Push docker manifest list - ${TARGET}:latest."
docker manifest create ${TARGET}:latest \
${TARGET}:${BUILD_VERSION}-alpine-amd64 \
${TARGET}:${BUILD_VERSION}-alpine-arm32v6 \
${TARGET}:${BUILD_VERSION}-alpine-arm64v8

# Manifest Annotate BUILD_VERSION
docker manifest annotate ${TARGET}:latest ${TARGET}:${BUILD_VERSION}-alpine-arm32v6 --os=linux --arch=arm --variant=v6
docker manifest annotate ${TARGET}:latest ${TARGET}:${BUILD_VERSION}-alpine-arm64v8 --os=linux --arch=arm64 --variant=v8

# Manifest Push BUILD_VERSION
docker manifest push ${TARGET}:latest
}

docker_manifest_list_version_os_arch() {
# Manifest Create alpine-amd64
echo "DOCKER MANIFEST: Create and Push docker manifest list - $TARGET:$EMQ_VERSION-alpine-amd64."
docker manifest create $TARGET:$EMQ_VERSION-alpine-amd64 \
$TARGET:$EMQ_VERSION-alpine-amd64
echo "DOCKER MANIFEST: Create and Push docker manifest list - ${TARGET}:${BUILD_VERSION}-alpine-amd64."
docker manifest create ${TARGET}:${BUILD_VERSION}-alpine-amd64 \
${TARGET}:${BUILD_VERSION}-alpine-amd64

# Manifest Push alpine-amd64
docker manifest push $TARGET:$EMQ_VERSION-alpine-amd64
docker manifest push ${TARGET}:${BUILD_VERSION}-alpine-amd64

# Manifest Create alpine-arm32v6
echo "DOCKER MANIFEST: Create and Push docker manifest list - $TARGET:$EMQ_VERSION-alpine-arm32v6."
docker manifest create $TARGET:$EMQ_VERSION-alpine-arm32v6 \
$TARGET:$EMQ_VERSION-alpine-arm32v6
echo "DOCKER MANIFEST: Create and Push docker manifest list - ${TARGET}:${BUILD_VERSION}-alpine-arm32v6."
docker manifest create ${TARGET}:${BUILD_VERSION}-alpine-arm32v6 \
${TARGET}:${BUILD_VERSION}-alpine-arm32v6

# Manifest Annotate alpine-arm32v6
docker manifest annotate $TARGET:$EMQ_VERSION-alpine-arm32v6 $TARGET:$EMQ_VERSION-alpine-arm32v6 --os=linux --arch=arm --variant=v6
docker manifest annotate ${TARGET}:${BUILD_VERSION}-alpine-arm32v6 ${TARGET}:${BUILD_VERSION}-alpine-arm32v6 --os=linux --arch=arm --variant=v6

# Manifest Push alpine-arm32v6
docker manifest push $TARGET:$EMQ_VERSION-alpine-arm32v6
docker manifest push ${TARGET}:${BUILD_VERSION}-alpine-arm32v6

# Manifest Create alpine-arm64v8
echo "DOCKER MANIFEST: Create and Push docker manifest list - $TARGET:$EMQ_VERSION-alpine-arm64v8."
docker manifest create $TARGET:$EMQ_VERSION-alpine-arm64v8 \
$TARGET:$EMQ_VERSION-alpine-arm64v8
echo "DOCKER MANIFEST: Create and Push docker manifest list - ${TARGET}:${BUILD_VERSION}-alpine-arm64v8."
docker manifest create ${TARGET}:${BUILD_VERSION}-alpine-arm64v8 \
${TARGET}:${BUILD_VERSION}-alpine-arm64v8

# Manifest Annotate alpine-arm64v8
docker manifest annotate $TARGET:$EMQ_VERSION-alpine-arm64v8 $TARGET:$EMQ_VERSION-alpine-arm64v8 --os=linux --arch=arm64 --variant=v8
docker manifest annotate ${TARGET}:${BUILD_VERSION}-alpine-arm64v8 ${TARGET}:${BUILD_VERSION}-alpine-arm64v8 --os=linux --arch=arm64 --variant=v8

# Manifest Push alpine-amd64
docker manifest push $TARGET:$EMQ_VERSION-alpine-arm64v8
docker manifest push ${TARGET}:${BUILD_VERSION}-alpine-arm64v8
}

setup_dependencies() {
Expand Down Expand Up @@ -188,7 +175,7 @@ update_docker_configuration() {
# "max-concurrent-uploads": 100
# }' | sudo tee /etc/docker/daemon.json

sudo service docker restart
# sudo service docker restart
}

prepare_qemu(){
Expand Down
64 changes: 43 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,61 @@ language:
- 'bash'

env:
global:
- TARGET=raymondmm/emqtt
- QEMU_VERSION=v2.12.0
global:
- TARGET=raymondmm/emqtt
- QEMU_VERSION=v2.12.0
matrix:
- BUILD_FROM=amd64/alpine:3.7 QEMU_ARCH=x86_64 OS_ARCH=alpine-amd64
- BUILD_FROM=arm32v6/alpine:3.7 QEMU_ARCH=arm OS_ARCH=alpine-arm32v6
- BUILD_FROM=arm64v8/alpine:3.7 QEMU_ARCH=aarch64 OS_ARCH=alpine-arm64v8

before_install:
- ./.docker/docker.sh prepare

install: true

before_script:
# Set EMQ_VERSION
- if [ ! -z "$TRAVIS_TAG" ]; then export EMQ_VERSION=$TRAVIS_TAG; else export EMQ_VERSION=v2.3.8; fi
# Set BUILD_VERSION
- if [ ! -z "${TRAVIS_TAG}" ]; then export BUILD_VERSION=${TRAVIS_TAG}; else export BUILD_VERSION=v2.3.10; fi

script:
- ./.docker/docker.sh build
- ./.docker/docker.sh test
# Build Docker image
- ./.docker/docker.sh build

# Test Docker image
- ./.docker/docker.sh test

# Push Docker image (TODO move to function)
- >
if [ ! -z "${TRAVIS_TAG}" ]; then
# Tag Docker image
./.docker/docker.sh tag
# Docker Login
echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
after_success:
- >
if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
# Docker Login
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# Push Docker image
docker push ${TARGET}:${BUILD_VERSION}-${OS_ARCH}
# Tag all images
./.docker/docker.sh tag
# Docker Logout
docker logout
fi
# Push all images
./.docker/docker.sh push
jobs:
include:
- stage: manifest
if: tag =~ ^v
script:
# Create and push Docker manifest lists (TODO move to function)
# Docker Login
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

# Create and push manifest list
./.docker/docker.sh manifest-list
# Create and Push Docker Manifest Lists to Docker Hub
- echo "Create manifest list for all docker images."
- ./.docker/docker.sh manifest-list

# Docker Logout
docker logout
fi
# Docker Logout
- docker logout

# notify me when things fail
notifications:
Expand Down
46 changes: 0 additions & 46 deletions archived/.travis.yml

This file was deleted.

Loading

0 comments on commit cd7b053

Please sign in to comment.