gitlab-build-images/scripts/build-helpers.sh
Rémy Coutable 611204c382
Only build/tag/push images once
Signed-off-by: Rémy Coutable <remy@rymai.me>
2020-03-02 14:08:29 +01:00

25 lines
491 B
Bash

function image_already_exists() {
image=$1
$(docker pull $image > /dev/null)
}
function build_if_needed() {
image=$1
if ! image_already_exists $image; then
docker build -t "$image" -f "Dockerfile.$image" .
else
echo "$image already exists, skipping build."
fi
}
function push_if_needed() {
image=$1
if ! image_already_exists $image; then
docker push "$image"
else
echo "$image already exists, skipping push."
fi
}