

install: install/system install/python

install/python: install/system @skip:key=./Pipfile.lock
    pipenv install

install/system:
    lazy_brew jq docker-compose

docker/bash: docker/build install/system
    docker-compose run --entrypoint=bash bake

docker/release: docker/build install/system docker/release/github
    docker-compose push

docker/release/github: install/system docker/build
    REGISTRY=${REGISTRY:-docker.pkg.github.com}
    USERNAME=${USERNAME:-kennethreitz}

    set -ux

    declare -a IMAGES=('bake:core' 'bake:latest')

    for IMAGE in "${IMAGES[@]}"; do
        REMOTE_IMAGE="$REGISTRY/$USERNAME/bake/$IMAGE"

        # Tag the images for GitHub Registry.
        docker tag "$USERNAME/$IMAGE" "$REMOTE_IMAGE"

        # Push the images to GitHub.
        docker push "$REMOTE_IMAGE"
    done

docker/build: install/system
    # Build the images.
    set -ex && docker-compose build


function lazy_brew {
    set -e
    # Install jq if it's not available.

    if ! which jq > /dev/null; then
        set -ex && brew install jq
    else
        echo 'jq is already installed!'
    fi

    # Install requested packages, if they aren't installed.
    for PACKAGE in "$@"; do
        if ! brew info --installed --json | jq 'map(.name) | index( "$PACKAGE" )' > /dev/null; then
            set -ex && brew install "$PACKAGE" > /dev/null
        fi
    done
}
export lazy_brew
