Last active
June 16, 2016 15:30
-
-
Save benley/2cb092060309185f8b32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Generate a Docker image from a Nix store path. | |
set -e | |
USAGE='USAGE: ./nixdock <storepath> [<entrypoint>] [<dockertag>]' | |
if [[ $# -lt 1 || $# -gt 3 ]]; then | |
echo "$USAGE" >&2; exit 1 | |
elif [[ "$1" == "--help" ]]; then | |
echo "$USAGE"; exit 0 | |
fi | |
drv=$1 | |
entrypoint=${2:+ENTRYPOINT [\"$2\"]} | |
tag=${3:-} | |
path=$(nix-store --realize "$drv") | |
img=$(tar -cP -C "$path" \ | |
./ $(nix-store --query --requisites "$path") \ | |
| docker import ${entrypoint:+-c "$entrypoint"} - "$tag") | |
echo "Store path: ${path}" >&2 | |
[[ -n "$tag" ]] && echo "Docker tag: ${tag}" >&2 | |
if [[ -n "$entrypoint" ]]; then | |
echo -n "Entrypoint: " >&2 | |
docker inspect "$img" | jq -c .[].Config.Entrypoint >&2 | |
fi | |
echo "$img" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment