From 8970ce1399436ea52ee3e709f1dfba842ff2cff8 Mon Sep 17 00:00:00 2001 From: Burton Rheutan Date: Mon, 3 Jun 2019 20:46:00 -0500 Subject: [PATCH] Build to create images with binary Update the build to create images of the binaries for each of the supported platforms: darwin, armhf, arm64, windows, and x86_64 (linux) Also updated the travis file in order to push these images up to docker hub and create a manifest file for easy multi-arch image pulls Signed-off-by: Burton Rheutan --- .travis.yml | 30 +++++++++++++++++++++++++++++- Dockerfile.packager | 6 ++++++ build.sh | 15 +++++++-------- make_manifest.sh | 18 ++++++++++++++++++ 4 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 Dockerfile.packager create mode 100755 make_manifest.sh diff --git a/.travis.yml b/.travis.yml index f8905236..ebc81c37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,34 @@ addons: before_install: script: - sh build.sh +after_success: + - if [ -z $DOCKER_NS ] ; then + export DOCKER_NS=functions; + fi + - if [ ! -z "$TRAVIS_TAG" ] ; then + export DOCKER_CLI_EXPERIMENTAL=enabled + + docker tag $DOCKER_NS/of-watchdog:latest-dev-darwin $DOCKER_NS/of-watchdog:$TRAVIS_TAG-darwin; + docker tag $DOCKER_NS/of-watchdog:latest-dev-armhf $DOCKER_NS/of-watchdog:$TRAVIS_TAG-armhf; + docker tag $DOCKER_NS/of-watchdog:latest-dev-arm64 $DOCKER_NS/of-watchdog:$TRAVIS_TAG-arm64; + docker tag $DOCKER_NS/of-watchdog:latest-dev-windows $DOCKER_NS/of-watchdog:$TRAVIS_TAG-windows; + docker tag $DOCKER_NS/of-watchdog:latest-dev-x86_64 $DOCKER_NS/of-watchdog:$TRAVIS_TAG-x86_64; + echo $DOCKER_PASSWORD | docker login -u=$DOCKER_USERNAME --password-stdin; + docker push $DOCKER_NS/of-watchdog:$TRAVIS_TAG-darwin; + docker push $DOCKER_NS/of-watchdog:$TRAVIS_TAG-armhf; + docker push $DOCKER_NS/of-watchdog:$TRAVIS_TAG-arm64; + docker push $DOCKER_NS/of-watchdog:$TRAVIS_TAG-windows; + docker push $DOCKER_NS/of-watchdog:$TRAVIS_TAG-x86_64; + + ./make_manifest.sh + docker push $DOCKER_NS/of-watchdog:$TRAVIS_TAG + + echo $QUAY_PASSWORD | docker login -u=$QUAY_USERNAME --password-stdin quay.io; + docker push quay.io/$DOCKER_NS/of-watchdog:$TRAVIS_TAG-armhf; + docker push quay.io/$DOCKER_NS/of-watchdog:$TRAVIS_TAG-arm64; + docker push quay.io/$DOCKER_NS/of-watchdog:$TRAVIS_TAG-windows; + docker push quay.io/$DOCKER_NS/of-watchdog:$TRAVIS_TAG-x86_64; + fi before_deploy: - ./ci/hashgen.sh deploy: @@ -28,4 +56,4 @@ deploy: - "./of-watchdog.exe.sha256" skip_cleanup: true on: - tags: true + tags: true diff --git a/Dockerfile.packager b/Dockerfile.packager new file mode 100644 index 00000000..fe50056d --- /dev/null +++ b/Dockerfile.packager @@ -0,0 +1,6 @@ +FROM functions/of-watchdog:build as build +FROM scratch + +ARG PLATFORM + +COPY --from=build /go/src/github.com/openfaas-incubator/of-watchdog/of-watchdog$PLATFORM ./fwatchdog \ No newline at end of file diff --git a/build.sh b/build.sh index 1ff78893..526927ad 100755 --- a/build.sh +++ b/build.sh @@ -1,11 +1,4 @@ -#!/bin/sh - -export arch=$(uname -m) - -if [ ! "$arch" = "x86_64" ] ; then - echo "Build not supported on $arch, use cross-build." - exit 1 -fi +#!/bin/bash if [ ! "$http_proxy" = "" ] then @@ -14,6 +7,12 @@ else docker build -t functions/of-watchdog:build . fi +docker build --no-cache --build-arg PLATFORM="-darwin" -t openfaas/of-watchdog:latest-dev-darwin . -f Dockerfile.packager +docker build --no-cache --build-arg PLATFORM="-armhf" -t openfaas/of-watchdog:latest-dev-armhf . -f Dockerfile.packager +docker build --no-cache --build-arg PLATFORM="-arm64" -t openfaas/of-watchdog:latest-dev-arm64 . -f Dockerfile.packager +docker build --no-cache --build-arg PLATFORM=".exe" -t openfaas/of-watchdog:latest-dev-windows . -f Dockerfile.packager +docker build --no-cache --build-arg PLATFORM="" -t openfaas/of-watchdog:latest-dev-x86_64 . -f Dockerfile.packager + docker create --name buildoutput functions/of-watchdog:build echo docker cp buildoutput:/go/src/github.com/openfaas-incubator/of-watchdog/of-watchdog ./of-watchdog diff --git a/make_manifest.sh b/make_manifest.sh new file mode 100755 index 00000000..1a769695 --- /dev/null +++ b/make_manifest.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +export USR=$DOCKER_NS +export TAG=$TRAVIS_TAG + +docker manifest create $USR/of-watchdog:$TAG \ + $USR/of-watchdog:$TAG-darwin \ + $USR/of-watchdog:$TAG-x86_64 \ + $USR/of-watchdog:$TAG-armhf \ + $USR/of-watchdog:$TAG-arm64 \ + $USR/of-watchdog:$TAG-windows + +docker manifest annotate $USR/of-watchdog:$TAG --arch arm $USR/of-watchdog:$TAG-darwin +docker manifest annotate $USR/of-watchdog:$TAG --arch arm $USR/of-watchdog:$TAG-armhf +docker manifest annotate $USR/of-watchdog:$TAG --arch arm64 $USR/of-watchdog:$TAG-arm64 +docker manifest annotate $USR/of-watchdog:$TAG --os windows $USR/of-watchdog:$TAG-windows + +docker manifest push $USR/of-watchdog:$TAG