Remove the bash implementation
This commit is contained in:
parent
3918799b9a
commit
adc2e34deb
3 changed files with 0 additions and 357 deletions
|
@ -19,7 +19,6 @@ data-files: nix/*.nix
|
|||
, nix/modules/composition/*.nix
|
||||
, nix/modules/nixos/*.nix
|
||||
, nix/modules/service/*.nix
|
||||
, arion-image/Dockerfile
|
||||
|
||||
-- all data is verbatim from some sources
|
||||
data-dir: src
|
||||
|
|
39
arion.nix
39
arion.nix
|
@ -1,39 +0,0 @@
|
|||
{ stdenv, lib
|
||||
, coreutils, docker_compose, jq
|
||||
}:
|
||||
let
|
||||
|
||||
# TODO: Replace by a new expression for the new Haskell main
|
||||
arion = stdenv.mkDerivation {
|
||||
name = "arion";
|
||||
src = ./src;
|
||||
unpackPhase = "";
|
||||
buildPhase = "";
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $out/share/arion
|
||||
cp -a nix $out/share/arion/
|
||||
cp -a arion-image $out/share/arion/
|
||||
tar -czf $out/share/arion/arion-image/tarball.tar.gz -C arion-image/tarball .
|
||||
substitute arion $out/bin/arion \
|
||||
--subst-var-by path ${lib.makeBinPath [jq coreutils docker_compose]} \
|
||||
--subst-var-by nix_dir $out/share/arion/nix \
|
||||
;
|
||||
chmod a+x $out/bin/arion
|
||||
'';
|
||||
inherit passthru;
|
||||
};
|
||||
|
||||
passthru = {
|
||||
inherit eval build;
|
||||
};
|
||||
|
||||
eval = import "${nix_dir}/eval-composition.nix";
|
||||
|
||||
build = args@{...}:
|
||||
let composition = eval args;
|
||||
in composition.config.build.dockerComposeYaml;
|
||||
|
||||
nix_dir = "${arion.outPath}/share/arion/nix";
|
||||
|
||||
in
|
||||
arion
|
317
src/arion
317
src/arion
|
@ -1,317 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Close off the python module search path
|
||||
#
|
||||
# Accepting directories from the environment into the search path
|
||||
# tends to break things. Docker Compose does not have a plugin
|
||||
# system as far as I can tell, so I don't expect this to break a
|
||||
# feature, but rather to make the program more robustly self-
|
||||
# contained.
|
||||
unset PYTHONPATH
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export PATH="@path@:$PATH"
|
||||
|
||||
nix_dir="@nix_dir@"
|
||||
docker_compose_args=()
|
||||
files=()
|
||||
command="docker-compose"
|
||||
pkgs_argument="./arion-pkgs.nix"
|
||||
|
||||
debug() {
|
||||
# echo "$@"
|
||||
:
|
||||
}
|
||||
|
||||
while test $# != 0; do
|
||||
case "$1" in
|
||||
-f|--file)
|
||||
shift
|
||||
files+=("$1")
|
||||
;;
|
||||
-f*)
|
||||
files+=("${1/#-f/}")
|
||||
;;
|
||||
--file=*)
|
||||
files+=("${1/#--file=}")
|
||||
;;
|
||||
--pkgs)
|
||||
shift
|
||||
pkgs_argument="$1"
|
||||
;;
|
||||
-h|--help|help)
|
||||
command="help"
|
||||
shift
|
||||
break
|
||||
;;
|
||||
cat)
|
||||
command="$1"
|
||||
shift
|
||||
break
|
||||
;;
|
||||
repl)
|
||||
command="$1"
|
||||
shift
|
||||
break
|
||||
;;
|
||||
exec)
|
||||
command="$1"
|
||||
shift
|
||||
break
|
||||
;;
|
||||
docker-compose)
|
||||
command="docker-compose"
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
while test $# != 0; do
|
||||
docker_compose_args+=("$1")
|
||||
shift
|
||||
done
|
||||
|
||||
case "$command" in
|
||||
help)
|
||||
cat <<EOF
|
||||
|
||||
Arion wraps your system's docker-compose, providing a NixOps-like
|
||||
experience for simple container deployments.
|
||||
|
||||
Usage:
|
||||
arion up|logs|... - execute docker-compose commands
|
||||
arion cat - display raw docker-compose.yaml
|
||||
arion config - validate and display the config file
|
||||
arion repl - explore the config interactively
|
||||
arion help
|
||||
arion docker-compose help
|
||||
arion docker-compose help up|logs|...
|
||||
|
||||
Top-level arion options
|
||||
|
||||
These must be provided before the command.
|
||||
|
||||
--file FILE Use FILE instead of the default ./arion-compose.nix
|
||||
Can be specified multiple times for a merged configuration.
|
||||
--pkgs EXPR Use EXPR instead of ./arion-pkgs.nix to get the
|
||||
Nixpkgs attrset used for bootstrapping and evaluating
|
||||
the configuration.
|
||||
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ ${#files[@]} == 0 ]]; then
|
||||
files=("./arion-compose.nix")
|
||||
fi
|
||||
|
||||
|
||||
debug docker_compose_args: "${docker_compose_args[@]}"
|
||||
debug files: "${files[@]}"
|
||||
|
||||
docker_compose_yaml=.tmp-nix-docker-compose-$$-$RANDOM.yaml
|
||||
cleanup() {
|
||||
rm -f $docker_compose_yaml
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
modules="["
|
||||
|
||||
for file in "${files[@]}"; do
|
||||
case "$file" in
|
||||
/*)
|
||||
modules="$modules (/. + $(printf '"%q"' "$file"))"
|
||||
;;
|
||||
*)
|
||||
modules="$modules (./. + $(printf '"/%q"' "$file"))"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
modules="$modules ]"
|
||||
|
||||
debug modules: "$modules"
|
||||
|
||||
old_IFS="$IFS"
|
||||
IFS=""
|
||||
args=(
|
||||
)
|
||||
IFS="$old_IFS"
|
||||
for arg in "${args[@]}"; do
|
||||
echo "arg: $arg"
|
||||
done
|
||||
|
||||
do_eval() {
|
||||
echo 1>&2 "Evaluating configuration..."
|
||||
# read-write-mode is required for import from derivation
|
||||
nix-instantiate \
|
||||
"$nix_dir/eval-composition.nix" \
|
||||
--eval \
|
||||
--read-write-mode \
|
||||
--json \
|
||||
--argstr uid "$UID" \
|
||||
--arg modules "$modules" \
|
||||
--arg pkgs "$pkgs_argument" \
|
||||
--show-trace \
|
||||
--attr 'config.build.dockerComposeYamlText' \
|
||||
| jq -r . >$docker_compose_yaml;
|
||||
}
|
||||
|
||||
do_build() {
|
||||
echo 1>&2 "Building configuration..."
|
||||
nix-build \
|
||||
"$nix_dir/eval-composition.nix" \
|
||||
--out-link $docker_compose_yaml \
|
||||
--argstr uid "$UID" \
|
||||
--arg modules "$modules" \
|
||||
--arg pkgs "$pkgs_argument" \
|
||||
--show-trace \
|
||||
--attr 'config.build.dockerComposeYaml' \
|
||||
>/dev/null ;
|
||||
|
||||
echo 1>&2 "Ensuring required images are loaded..."
|
||||
jq -r <"$docker_compose_yaml" \
|
||||
'.["x-arion"].images | map(" - " + .imageName + ":" + .imageTag) | join("\n")'
|
||||
eval "$(
|
||||
jq -r '.["docker-compose"]["x-arion"].images as $images
|
||||
| .["existing-images"] as $loaded
|
||||
| $images
|
||||
| map(
|
||||
if $loaded[.imageName + ":" + .imageTag]
|
||||
then ""
|
||||
else "docker load <" + .image + ";" end
|
||||
)
|
||||
| join("\n")
|
||||
' <<EOF
|
||||
{
|
||||
"docker-compose": $(cat $docker_compose_yaml),
|
||||
"existing-images": {
|
||||
$(docker images \
|
||||
--filter "dangling=false" \
|
||||
--format '"{{.Repository}}:{{.Tag}}": true,')
|
||||
"": false
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)"
|
||||
}
|
||||
|
||||
|
||||
do_repl() {
|
||||
# nix repl doesn't autocall its <FILES> arguments
|
||||
# so we improvise. We need a file in this directory
|
||||
# to make sure that all paths are as expected :(
|
||||
trap do_repl_cleanup EXIT;
|
||||
|
||||
REPL_TMP=.tmp-repl-$$-$RANDOM
|
||||
cat <<EOF
|
||||
Launch a repl for you, using a temporary file: $REPL_TMP.
|
||||
|
||||
This loads the configuration from the modules
|
||||
${files[*]}
|
||||
|
||||
To get started:
|
||||
|
||||
To see deployment-wide configuration
|
||||
type config. and hit TAB
|
||||
To see the services
|
||||
type config.docker-compose.evaluatedServices TAB or ENTER
|
||||
To bring the top-level Nixpkgs attributes into scope
|
||||
type :a (config._module.args.pkgs) // { inherit config; }
|
||||
|
||||
EOF
|
||||
cat >"$REPL_TMP" <<EOF
|
||||
import $nix_dir/eval-composition.nix {
|
||||
uid = "$UID";
|
||||
modules = $modules;
|
||||
pkgs = $pkgs_argument;
|
||||
}
|
||||
EOF
|
||||
|
||||
nix repl \
|
||||
"$REPL_TMP" \
|
||||
;
|
||||
}
|
||||
do_repl_cleanup() {
|
||||
rm -f $REPL_TMP
|
||||
}
|
||||
|
||||
run_exec() {
|
||||
case "${#docker_compose_args[@]}" in
|
||||
0)
|
||||
echo "As an argument to exec, please specify a service"
|
||||
exit 1
|
||||
;;
|
||||
1)
|
||||
case "${docker_compose_args[0]}" in
|
||||
-*|--*)
|
||||
echo "As an argument to exec, please specify a service"
|
||||
echo "Note that executing the default command currently does not support"
|
||||
echo "docker-compose options."
|
||||
# This requires parsing the options, in order to figure out
|
||||
# which service to invoke.
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
serviceName="${docker_compose_args[0]}"
|
||||
do_eval
|
||||
default_args=()
|
||||
while read arg; do
|
||||
default_args+=("$arg")
|
||||
done < <(
|
||||
jq < "$docker_compose_yaml" \
|
||||
--arg serviceName "$serviceName" \
|
||||
-r \
|
||||
'.["x-arion"].serviceInfo[$serviceName].defaultExec | tostream | .[1] | select(.)'
|
||||
)
|
||||
docker-compose -f $docker_compose_yaml exec "$serviceName" "${default_args[@]}"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
do_eval
|
||||
docker-compose -f $docker_compose_yaml exec "${docker_compose_args[@]}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "$command" in
|
||||
cat)
|
||||
do_eval
|
||||
jq . < "$docker_compose_yaml"
|
||||
;;
|
||||
repl)
|
||||
do_repl
|
||||
;;
|
||||
exec)
|
||||
run_exec "$@"
|
||||
;;
|
||||
docker-compose)
|
||||
if [[ ${#docker_compose_args[@]} != 0
|
||||
&& ${docker_compose_args[0]} != "help"
|
||||
&& ${docker_compose_args[0]} != "version"
|
||||
]]; then
|
||||
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
|
||||
docker-compose -f $docker_compose_yaml "${docker_compose_args[@]}"
|
||||
;;
|
||||
esac
|
Loading…
Reference in a new issue