commit
parent
29821bc1d1
commit
5c15a2c1b0
|
|
@ -8,7 +8,7 @@
|
|||
#
|
||||
|
||||
set -e
|
||||
# set -u
|
||||
set -u
|
||||
|
||||
IMAGE_ALIASES=${IMAGE_ALIASES:-}
|
||||
ERROR=${ERROR:-}
|
||||
|
|
@ -103,36 +103,6 @@ build() {
|
|||
DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
fi
|
||||
|
||||
if [ -z $BUILDER ]; then
|
||||
echo "BUILDER not specified, trying with podman"
|
||||
BUILDER=$(command -v podman || true)
|
||||
if [[ ! -x $BUILDER ]]; then
|
||||
echo "[WARNING] podman is not installed, trying with buildah"
|
||||
BUILDER=$(command -v buildah || true)
|
||||
if [[ ! -x $BUILDER ]]; then
|
||||
echo "[WARNING] buildah is not installed, trying with docker"
|
||||
BUILDER=$(command -v docker || true)
|
||||
if [[ ! -x $BUILDER ]]; then
|
||||
echo "[ERROR] neither docker, buildah, nor podman are installed. Aborting"; exit 1
|
||||
fi
|
||||
else
|
||||
BUILD_COMMAND="bud"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [[ ! -x $(command -v "$BUILDER" || true) ]]; then
|
||||
echo "Builder $BUILDER is missing. Aborting."; exit 1
|
||||
fi
|
||||
if [[ $BUILDER =~ "docker" || $BUILDER =~ "podman" ]]; then
|
||||
if [[ ! $($BUILDER ps) ]]; then
|
||||
echo "Builder $BUILDER is not functioning. Aborting."; exit 1
|
||||
fi
|
||||
fi
|
||||
if [[ $BUILDER =~ "buildah" ]]; then
|
||||
BUILD_COMMAND="bud"
|
||||
fi
|
||||
fi
|
||||
|
||||
# If Dockerfile is empty, build all Dockerfiles
|
||||
if [ -z ${DOCKERFILE} ]; then
|
||||
DOCKERFILES_TO_BUILD="$(ls ${DIR}/Dockerfile*)"
|
||||
|
|
@ -167,14 +137,14 @@ build_image() {
|
|||
-e "s;\${BUILD_PREFIX};${PREFIX};" \
|
||||
-e "s;\${BUILD_TAG};${TAG};" \
|
||||
> ${DIR}/.Dockerfile
|
||||
cd "${DIR}" && "${BUILDER}" build -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} .
|
||||
cd "${DIR}" && docker build -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} .
|
||||
DOCKER_BUILD_STATUS=$?
|
||||
rm ${DIR}/.Dockerfile
|
||||
if [ $DOCKER_BUILD_STATUS -eq 0 ]; then
|
||||
printf "Build of ${BLUE}${IMAGE_NAME} ${GREEN}[OK]${NC}\n"
|
||||
if [ ! -z "${SHA_TAG}" ]; then
|
||||
SHA_IMAGE_NAME=${ORGANIZATION}/${PREFIX}-${NAME}:${SHA_TAG}
|
||||
"${BUILDER}" tag ${IMAGE_NAME} ${SHA_IMAGE_NAME}
|
||||
docker tag ${IMAGE_NAME} ${SHA_IMAGE_NAME}
|
||||
DOCKER_TAG_STATUS=$?
|
||||
if [ $DOCKER_TAG_STATUS -eq 0 ]; then
|
||||
printf "Re-tagging with SHA based tag ${BLUE}${SHA_IMAGE_NAME} ${GREEN}[OK]${NC}\n"
|
||||
|
|
@ -186,7 +156,7 @@ build_image() {
|
|||
if [ ! -z "${IMAGE_ALIASES}" ]; then
|
||||
for TMP_IMAGE_NAME in ${IMAGE_ALIASES}
|
||||
do
|
||||
"${BUILDER}" tag ${IMAGE_NAME} ${TMP_IMAGE_NAME}:${TAG}
|
||||
docker tag ${IMAGE_NAME} ${TMP_IMAGE_NAME}:${TAG}
|
||||
DOCKER_TAG_STATUS=$?
|
||||
if [ $DOCKER_TAG_STATUS -eq 0 ]; then
|
||||
printf " /alias ${BLUE}${TMP_IMAGE_NAME}:${TAG}${NC} ${GREEN}[OK]${NC}\n"
|
||||
|
|
@ -205,8 +175,8 @@ build_image() {
|
|||
}
|
||||
|
||||
check_docker() {
|
||||
if ! "${BUILDER}" ps > /dev/null 2>&1; then
|
||||
output=$("${BUILDER}" ps)
|
||||
if ! docker ps > /dev/null 2>&1; then
|
||||
output=$(docker ps)
|
||||
printf "${RED}Docker not installed properly: ${output}${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -216,12 +186,12 @@ docker_exec() {
|
|||
if has_docker_for_windows_client; then
|
||||
MSYS_NO_PATHCONV=1 docker.exe "$@"
|
||||
else
|
||||
"$(which "${BUILDER}")" "$@"
|
||||
"$(which docker)" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
has_docker_for_windows_client() {
|
||||
GLOBAL_HOST_ARCH=$("${BUILDER}" version --format {{.Client}})
|
||||
GLOBAL_HOST_ARCH=$(docker version --format {{.Client}})
|
||||
|
||||
if [[ "${GLOBAL_HOST_ARCH}" = *"windows"* ]]; then
|
||||
return 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue