go-toolbox/build.sh
Stanislav N. aka pztrn 8b945c8f90
All checks were successful
continuous-integration/drone Build is passing
Initial commit.
2024-05-04 13:18:37 +05:00

38 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# build.sh checks if docker image with same sha256 exists remotely.
# if exists, do nothing, if not, build the image
commit_sha="${DRONE_COMMIT_SHA}"
image_path="${REGISTRY}${REGISTRY_PROJECT}"
if [ "${DRONE_TAG}" != "" ]; then
tag="${DRONE_TAG}"
else
tag="${DRONE_COMMIT_SHA}"
fi
# Starting Docker daemon.
/usr/local/bin/dockerd --data-root=/var/lib/docker --max-concurrent-uploads 1 &
# Wait for it.
echo "* Waiting for Docker daemon to start..."
while true; do
if docker ps &>/dev/null; then
break
fi
done
echo "* Logging in to registry..."
docker login -u "${REGISTRY_USERNAME}" -p "${REGISTRY_PASSWORD}" "${REGISTRY}"
echo "* Building docker image ${image_path}:${tag}..."
if docker manifest inspect "${image_path}:${tag}" >/dev/null; then
echo "* Docker image ${image_path}:${tag} is already exists on remote, no rebuilt necessary."
exit 0
fi
docker build --pull --build-arg VCS_REF="${commit_sha}" --build-arg VCS_URL="${image_path}" --tag "${image_path}:${tag}" .
docker push "${image_path}:${tag}"