This commit is contained in:
37
build.sh
Executable file
37
build.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/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}"
|
||||
Reference in New Issue
Block a user