Do not build for commands that do not need images

This commit is contained in:
Robert Hensing 2018-12-23 13:00:04 +01:00
parent 0f6a1bd41f
commit f503e556ea
2 changed files with 32 additions and 4 deletions

View file

@ -136,6 +136,20 @@ for arg in "${args[@]}"; do
echo "arg: $arg" echo "arg: $arg"
done done
do_eval() {
echo 1>&2 "Evaluating configuration..."
nix-instantiate \
"$nix_dir/eval-docker-compose.nix" \
--eval \
--json \
--argstr uid "$UID" \
--arg modules "$modules" \
--arg pkgs "$pkgs_argument" \
--show-trace \
--attr 'config.build.dockerComposeYamlText' \
| jq -r . >$docker_compose_yaml;
}
do_build() { do_build() {
echo 1>&2 "Building configuration..." echo 1>&2 "Building configuration..."
nix-build \ nix-build \
@ -191,7 +205,7 @@ do_repl_cleanup() {
case "$command" in case "$command" in
cat) cat)
do_build do_eval
jq . < "$docker_compose_yaml" jq . < "$docker_compose_yaml"
;; ;;
repl) repl)
@ -201,8 +215,18 @@ case "$command" in
if [[ ${#docker_compose_args[@]} != 0 if [[ ${#docker_compose_args[@]} != 0
&& ${docker_compose_args[0]} != "help" && ${docker_compose_args[0]} != "help"
&& ${docker_compose_args[0]} != "version" && ${docker_compose_args[0]} != "version"
]]; then ]]; then
do_build case "${docker_compose_args[0]}" in
help|version)
:
;;
config|down|events|exec|images|kill|logs|pause|port|ps|rm|stop|top|unpause)
do_eval
;;
*)
do_build
;;
esac
fi fi
docker-compose -f $docker_compose_yaml "${docker_compose_args[@]}" docker-compose -f $docker_compose_yaml "${docker_compose_args[@]}"
;; ;;

View file

@ -30,6 +30,9 @@ in
build.dockerComposeYaml = lib.mkOption { build.dockerComposeYaml = lib.mkOption {
type = lib.types.package; type = lib.types.package;
}; };
build.dockerComposeYamlText = lib.mkOption {
type = lib.types.string;
};
docker-compose.raw = lib.mkOption { docker-compose.raw = lib.mkOption {
type = lib.types.attrs; type = lib.types.attrs;
}; };
@ -39,7 +42,8 @@ in
}; };
}; };
config = { config = {
build.dockerComposeYaml = pkgs.writeText "docker-compose.yaml" (builtins.toJSON (config.docker-compose.raw)); build.dockerComposeYaml = pkgs.writeText "docker-compose.yaml" config.build.dockerComposeYamlText;
build.dockerComposeYamlText = builtins.toJSON (config.docker-compose.raw);
docker-compose.raw = { docker-compose.raw = {
version = "3"; version = "3";