dip CLI

repository·master·Indexed 23 days ago

https://github.com/bibendi/dip

A CLI developer tool that provides a native-like interaction experience with Dockerized applications. It abstracts complex Docker commands via a dip.yml configuration file, allowing developers to run containerized processes as if they were local. Key features include shell integration for ZSH and Bash, preflight checks, infrastructure management for shared services, and support for both Docker Compose and kubectl runners.

Tokens
8.4K
Snippets
14
Records
77
Agent score
79%

What's inside dip

  1. Use preflight checks to protect commands

    master

    The preflight section in dip.yml defines an array of shell commands that Dip runs before any command that interacts with a running container or cluster (e.g., dip compose ..., dip ktl ..., dip run ..., or interaction shorthands).

    If any preflight command exits with a non-zero status, Dip aborts the operation. This is useful for verifying credentials, checking for required files, or ensuring environment variables are set.

    Note: Preflight is NOT triggered by:

    • dip down --all (cross-project teardown)
    • dip ssh
    • dip infra
    • dip provision
    preflight:
      - ./bin/check-credentials
      - test -f .env
  2. Organize configurations with Modules

    master

    Modules allow you to group related interaction commands in separate files to improve maintainability across multiple projects. Module files must be stored in a .dip subdirectory next to your dip.yml.

    • Loading: List module names in the modules array in dip.yml.
    • Expansion: Module contents are expanded into the main configuration.
    • Overriding: You can override a command defined in a module by redefining it directly in your main dip.yml.
    • Limitation: Nested modules are not supported.
    # ./dip.yml
    modules:
     - sasts
     - rails
    
    # Redefining a module command in the main config
    interaction:
      brakeman:
        command: docker run another-image ...
  3. Quick start with AI using dip-skill

    master

    Use dip-skill to automatically configure a dip environment. It detects your project's tech stack and bootstraps the necessary dip.yml, Docker Compose files, and Dockerfiles.

    npx skills add kalashnikovisme/dip-skill
  4. Configure dip with dip.yml

    master

    Dip uses a dip.yml file for configuration. It searches for this file in the current working directory or the nearest parent directory up to the root.

    Key configuration features:

    • Overrides: If a dip.override.yml exists in the same directory, it is merged into the main configuration.
    • Custom Path: You can specify a custom configuration file path by setting the DIP_FILE environment variable.
    • Validation: You can validate your configuration using dip validate. To enable VSCode schema validation, add the following comment to the top of your dip.yml: # yaml-language-server: $schema=https://raw.githubusercontent.com/bibendi/dip/refs/heads/master/schema.json
    version: '8.0'
    
    environment:
      COMPOSE_EXT: development
      STAGE: "staging"
    
    compose:
      files:
        - docker/docker-compose.yml
        - docker/docker-compose.$COMPOSE_EXT.yml
      project_name: bear
    
    interaction:
      rails:
        description: Run Rails commands
        service: app
        command: bundle exec rails
  5. Set up SSH agent with dip ssh

    master

    The dip ssh up command runs an ssh-agent container that shares your host's ~/.ssh/id_rsa via a named volume ssh_data.

    To use this, your docker-compose.yml must:

    1. Set the environment variable SSH_AUTH_SOCK=/ssh/auth/sock.
    2. Connect to the external volume ssh_data.

    Usage:

    • Standard: dip ssh up
    • With specific UID: dip ssh up -u 1000
    # docker-compose.yml requirement
    services:
      web:
        environment:
          - SSH_AUTH_SOCK=/ssh/auth/sock
        volumes:
          - ssh-data:/ssh:ro
    
    volumes:
      ssh-data:
        external:
          name: ssh_data
  6. Integrate dip into your shell (ZSH or Bash)

    master

    You can inject dip into your current shell session to run commands without the dip prefix. This enables direct execution of commands defined in your dip.yml or standard Docker Compose commands.

    Usage: Run the following command to activate shell integration:

    eval "$(dip console)"

    Features:

    • Automatic Aliases: Once integrated, you can type commands like <run-command>, compose, up <service>, ktl, or provision directly.
    • Directory Awareness: Shell aliases are automatically removed when you change directories and renewed when you enter a directory containing a dip.yml file.
    • Environment Variable Support: In shell mode, dip attempts to detect manually passed environment variables (e.g., VERSION=123 rails db:migrate).

    Warning: Be aware of potential collisions with local tools. For example, if you have both local and Docker-based frontend tools (like yarn), you should either avoid adding yarn to your dip.yml or avoid using shell integration to prevent conflicts.

  7. How `dip console` injection and aliases work

    master

    The dip console command uses an injection mechanism to provide convenient aliases for common tasks. This allows you to run dip commands directly as if they were native shell functions.

    Automatic Aliases

    If a dip.yml configuration exists, dip automatically creates aliases for:

    1. Any keys defined under the interaction section of your dip.yml.
    2. Core commands: compose, up, stop, down, provision, and build.

    For example, if compose is aliased, running compose up in your shell is equivalent to running dip compose up.

    Zsh Integration

    If you are using zsh, dip hooks into the chpwd function. This means that whenever you change directories (cd), dip will automatically call dip_reload to ensure your environment and aliases remain synchronized with your current context.

  8. Configure dip using dip.yml and override files

    master

    Dip uses a dip.yml file for configuration. It supports an override mechanism where a file named dip.yml.override.yml can be used to merge additional settings into the base configuration.

    File Discovery Logic:

    1. Explicit Path: If the DIP_FILE environment variable is set, Dip uses that path. If override: true is active (during override loading), it automatically appends .override.yml to the path provided in DIP_FILE.
    2. Automatic Search: If DIP_FILE is not set, Dip searches for dip.yml starting from the current working directory and traverses up the directory tree until the file is found or the root is reached.
    3. Overrides: When loading overrides, if DIP_FILE is set to dip.yml, the system looks for dip.yml.override.yml.
  9. Use modules to extend dip configuration

    master

    You can extend your configuration by using the modules key in dip.yml. Modules must be specified as an array of strings. Each string corresponds to a filename located in a .dip directory relative to your dip.yml file.

    For example, if your config has modules: [auth], Dip will look for .dip/auth.yml. The contents of these module files are deep-merged into the main configuration. Note that nested modules (modules within modules) are not supported.

  10. How Docker Compose profiles affect command execution

    master

    When using profiles in your dip.yml configuration for a Docker Compose runner, dip automatically modifies the execution behavior to ensure compatibility with docker compose.

    Specifically, if profiles are defined:

    1. The method is forced to up (because docker compose does not support profiles for other commands like run).
    2. The command is cleared.
    3. run_options are removed because they are not supported by the up command.

    Profiles are passed to the underlying command using the --profile <profile_name> flag for each profile specified.

  11. Understand the internal structure of a Dip infrastructure service

    master

    When managing infrastructure services via dip, each service is identified by a name and is associated with specific Docker Compose and networking configurations.

    An infrastructure service requires either a git repository URL or a local path.

    Key attributes generated for a service include:

    • Location: If using git, the service is stored at #{Dip.home_path}/infra/{name}/{ref}. If using a path, it uses the expanded local path.
    • Project Name: The Docker Compose project name follows the pattern dip-infra-{name}-{ref}.
    • Network Name: The Docker network name follows the pattern dip-net-{name}-{ref}.
    • Network Environment Variable: To access the service's network, use the environment variable DIP_INFRA_NETWORK_{NAME_IN_UPPERCASE_WITH_UNDERSCORES} (e.g., a service named my-db uses DIP_INFRA_NETWORK_MY_DB).