Arion Documentation
repository·main·Indexed 21 days ago
https://github.com/hercules-ci/arionArion is a tool within the Hercules-CI ecosystem for building and running multi-container applications using NixOS modules. It provides specialized support for Docker images built with Nix and can be deployed via remote Docker sockets, registry uploads, or as a NixOS module using the virtualisation.arion configuration. The tool includes a CLI for managing service lifecycles, executing commands in containers, and evaluating Docker Compose files as JSON.
What's inside Arion
- Arion is a tool designed to build and run multi-container applications using NixOS modules. It provides specialized support for Docker images built with Nix, which enables a smoother development experience and improved performance compared to standard Docker workflows.
Use nixified scripts to hack on the arion command
mainThe
arioncommand is written in Haskell. While you can make changes directly to the Haskell code, you can use the provided nixified scripts in the repository root to manage common development tasks without needing deep experience with Haskell tooling.# Typechecking ./build ./live-check # Running tests ./live-unit-tests # Haskell REPL ./repl # Running arion ./run-arion ./run-arion-via-nixPrototype new features using the module system
mainThe Arion module system does not distinguish between modules and configurations. You can prototype new features by factoring out functionality directly within a real-world project instead of modifying the core source code.Deploy Arion projects using Docker images
mainWhen
useHostStoreis disabled, Arion builds Docker images that can be deployed to any Docker host, including non-NixOS hosts. You have two primary methods for deployment:- Remote Docker socket: You can deploy directly to a single Docker host using its socket. This method does not require a registry. Note that access to a Docker socket is equivalent to root access on the host.
- Registry upload: You can push images to a registry using
arion push. Alternatively, you can implement custom push logic usingarion cat, theevalfunction on thearionpackage, or thelib.evalfunction on the flake to retrieve the defined images.
Deploy Arion projects as a NixOS module
mainArion projects can be integrated into a NixOS configuration. This approach allows for efficient transfers using Nix's copy-closure algorithm and utilizes transparent binary caches instead of a stateful Docker registry.
Important Note: This deployment method does NOT use an
arion-pkgs.nixfile; it reuses the host'spkgsinstead.To use this, add the Arion NixOS module to your
imports. Depending on how you use Arion, choose one of the following import methods:- NIV:
((import ./nix/sources.nix).arion + "/nixos-module.nix") - Flakes:
arion.nixosModules.arion(wherearionis a flake input) - Other: Use
builtins.fetchTarballwith the specific commit hash of Arion.
Configure the project under
virtualisation.arion.{ imports = [ # Pick one of: # - niv ((import ./nix/sources.nix).arion + "/nixos-module.nix") # - or flakes (where arion is a flake input) arion.nixosModules.arion # - or other: copy commit hash of arion and replace HASH in: (builtins.fetchTarball "https://github.com/hercules-ci/arion/archive/HASH.tar.gz" + "/nixos-module.nix") ]; virtualisation.arion = { backend = "podman-socket"; # or "docker" projects.example = { serviceName = "example"; # optional systemd service name, defaults to arion-example settings = { # Specify your project here, or import it from a file. # NOTE: This does NOT use ./arion-pkgs.nix, but defaults to NixOS' pkgs. imports = [ ./arion-compose.nix ]; }; }; }; }- NIV:
Iterate on built-in modules via local source
mainTo refactor or modify existing built-in modules, you must fork and edit the Arion source code directly. For a fast iteration cycle, use the
run-arion-quickscript. Note that this may use outdated command logic.To start the environment:
~/src/arion/run-arion-quick up -dIf you need to update the
arioncommand logic for the next run, remove the cached result:rm ~/src/arion/result-run-arion-quick~/src/arion/run-arion-quick up -d rm ~/src/arion/result-run-arion-quickConfigure virtualisation.arion for NixOS
mainWhen using the NixOS module, use the
virtualisation.arionattribute set to define your deployment settings:backend: Specifies the container runtime socket to use (e.g.,"podman-socket"or"docker").projects.<name>: A set of project definitions.serviceName: (Optional) The systemd service name. If not provided, it defaults toarion-<project-name>.settings: A set of settings for the project. You can useimportsto pull in your project configuration from a file (e.g.,imports = [ ./arion-compose.nix ];). Note that these settings will use the host'spkgsrather than a project-specificarion-pkgs.nix.
Arion Common CLI Options
mainThese options can be applied to most Arion commands to configure the Nix evaluation and Docker Compose behavior.
-f,--file FILE: Specify one or more configuration files. If multiple are provided, they are merged. Defaults to./arion-compose.nix.-p,--pkgs EXPR: Use the Nix expressionEXPRto obtain the Nixpkgs attribute set used for bootstrapping and evaluation. Defaults to./arion-pkgs.nix.--nix-arg ARG: Pass an extra argument to the Nix evaluator. Example:--nix-arg --option --nix-arg substitute --nix-arg false.--prebuilt-file JSONFILE: Use a prebuilt JSON file instead of evaluating Nix expressions. This causes other evaluation-related options to be ignored.--no-ansi: Avoid ANSI control sequences in output.--compatibility: If set, Docker Compose will attempt to convertdeploykeys in v3 files to their non-Swarm equivalent.--log-level LEVEL: Set the log level toDEBUG,INFO,WARNING,ERROR, orCRITICAL.
# Example usage with custom files and nix args arion -f custom-compose.nix -p custom-pkgs.nix --nix-arg --option flag true upArion Core Commands
mainArion provides several high-level commands for managing your composition:
cat: Spit out the evaluated Docker Compose file as JSON.repl: Start a Nix REPL for the entire composition, allowing you to interact with the evaluated configuration.exec: Execute a command in a running container (see exec command details).
arion cat arion replArion Docker Compose Commands
mainArion passes many standard Docker Compose commands through to the underlying engine. These are grouped by their effect on the lifecycle of the services:
Build/Lifecycle Commands:
build: Build or rebuild services.bundle: Generate a Docker bundle from the Compose file.create: Create services.pull: Pull service images.push: Push service images.restart: Restart services.run: Run a one-off command.scale: Set number of containers for a service.start: Start services.up: Create and start containers.
Management/State Commands:
config: Validate and view the Compose file.down: Stop and remove containers, networks, images, and volumes.events: Receive real-time events from containers.images: List images.kill: Kill containers.logs: View output from containers.pause: Pause services.port: Print the public port for a port binding.ps: List containers.rm: Remove stopped containers.stop: Stop services.top: Display the running processes.unpause: Unpause services.
Utility Commands:
help: Get help on a command.version: Show the Docker-Compose version information.
Execute commands in containers with `exec`
mainThe
execcommand allows you to run a command inside a running service container.Usage:
arion exec [OPTIONS] SERVICE [COMMAND] [ARGS...]Options:
-d,--detach: Run the command in the background.--privileged: Give extended privileges to the process.-u,--user USER: Run the command as this user.-T: Disable pseudo-tty allocation.--index INDEX: Index of the container if there are multiple instances of a service (must be >= 1).-e,--env KEY=VALUE: Set environment variables (can be used multiple times).-w,--workdir DIR: Working directory in which to start the command in the container.
If no
COMMANDis provided, Arion attempts to use thedefaultExecdefined in the service configuration. If that is also missing, it defaults to/bin/sh.# Run a command as root in the 'web' service arion exec --user root web ls /app # Run a detached command with an environment variable arion exec -d -e DEBUG=true web python manage.py migrate # Run in a specific container instance (index 2) arion exec --index 2 web top