#!/bin/bash set -e # Push push CI images function push_ci_image(){ echo "Pushing ${REPONAME}/${IMGNAME}:${IMGTAG} ..." docker buildx build --file build/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag ${REPONAME}/${IMGNAME}:${IMGTAG} . } # Push Release Images function push_release_image(){ if [ ! -z "${CIRCLE_TAG}" ]; then # Push with different tags if tagged as a release # When github is tagged with a release, then CircleCI will # set the release tag in env CIRCLE_TAG echo "Pushing ${REPONAME}/${IMGNAME}:${CIRCLE_TAG} ..." docker buildx build --file build/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag ${REPONAME}/${IMGNAME}:${CIRCLE_TAG} . echo "Pushing ${REPONAME}/${IMGNAME}:latest ..." docker buildx build --file build/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag ${REPONAME}/${IMGNAME}:latest . fi; } # Check for Image Details if [ -z "${REPONAME}" ] || [ -z "${IMGNAME}" ] || [ -z "${IMGTAG}" ] then echo "Image details are missing. Nothing to push."; exit 1 fi IMAGEID=$( docker images -q ${REPONAME}/${IMGNAME}:${IMGTAG} ) # Verify Docker Credentials if [ ! -z "${DNAME}" ] && [ ! -z "${DPASS}" ]; then docker login -u "${DNAME}" -p "${DPASS}"; build_type=$(echo $1 | cut -d "=" -f 2) if [ "${build_type}" == "ci" ]; then push_ci_image; elif [ "${build_type}" == "release" ]; then push_release_image; else echo "Invalid build type"; exit 1 fi else echo "No docker credentials provided. Skip uploading ${REPONAME}/${IMGNAME}:${IMGTAG} to docker hub"; fi