Skip to content

Commit

Permalink
Support check on hub before building (#6)
Browse files Browse the repository at this point in the history
* Support check on hub before building

* Fix lint
  • Loading branch information
pvizeli authored Apr 25, 2019
1 parent 4a13a8b commit 1e641e1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -e
DOCKER_TIMEOUT=20
DOCKER_PID=-1
DOCKER_HUB=
DOCKER_HUB_CHECK=false
DOCKER_CACHE=true
DOCKER_LATEST=true
DOCKER_PUSH=true
Expand Down Expand Up @@ -94,6 +95,8 @@ Options:
Use same tag as cache tag instead latest.
-d, --docker-hub <DOCKER_REPOSITORY>
Set or overwrite the docker repository.
--docker-hub-check
Check if the version already exists before starting the build.
--docker-login
Login into docker hub on startup (need '-ti' docker opts)
--no-crossbuild-cleanup
Expand Down Expand Up @@ -207,6 +210,7 @@ function run_build() {

local push_images=()
local cache_tag="latest"
local metadata

# Overwrites
if [ -n "$DOCKER_HUB" ]; then repository="$DOCKER_HUB"; fi
Expand All @@ -217,6 +221,18 @@ function run_build() {
# shellcheck disable=SC1117
image="$(echo "$image" | sed -r "s/\{arch\}/$build_arch/g")"

# Check if image exists on docker hub
if [ "$DOCKER_HUB_CHECK" == "true" ]; then
metadata="$(curl -s "https://hub.docker.com/v2/repositories/$repository/$image/tags/$version/")"

if [ -n "$metadata" ] && [ "$(echo "$metadata" | jq --raw-output '.name')" == "$version" ]; then
bashio::log.info "Skip build, found $image:$version on dockerhub"
return 0
else
bashio::log.info "Start build, $image:$version is not on dockerhub"
fi
fi

# Init Cache
if [ "$DOCKER_CACHE" == "true" ]; then
if [ "$SELF_CACHE" == "true" ]; then
Expand Down Expand Up @@ -675,6 +691,9 @@ while [[ $# -gt 0 ]]; do
DOCKER_HUB=$2
shift
;;
--docker-hub-check)
DOCKER_HUB_CHECK=true
;;
--docker-login)
DOCKER_LOGIN=true
;;
Expand Down

0 comments on commit 1e641e1

Please sign in to comment.