Managing multiple projects and their services simultaneously can be a hassle, especially when switching between them requires manually starting and stopping various prerequisites. dcli is a Go-based command-line tool designed to make it easier to switch between projects by providing an interactive, prompt-based interface that manages your Docker services and dependencies.
The tool works by reading a YAML configuration file where you define your projects, their services, dependencies, and Docker Compose files. Using the prompt UI, you can quickly select a project and manage its services directly from the terminal.
For a sample configuration and example services, please refer to the dcli-other-projects repository, which contains several example project setups.
- Service Management: Define individual services and their respective Docker Compose files.
- Dependency Resolution: Automatically start dependencies in the correct order when starting a service.
- Common Services: Define shared services and containers that are used across multiple services in a project.
- Docker Compose Integration: Use Docker Compose files for automatic container management based on your project setup.
- Interactive Prompt UI: A user-friendly interface powered by
promptuithat allows users to select and manage services through terminal prompts.
- Main Project (dcli): https://github.com/mh-daneshvar/dcli
- Sample Projects (dcli-other-projects): https://github.com/mh-daneshvar/dcli-other-projects
Below is an example YAML file that defines a project and its services. You can use this to configure your own project setup:
projects:
Project One:
services:
- label: Auth Service
dependencies:
- Users Service
containers:
- graylog
docker_compose_file_path: /path/to/auth-service/docker-compose.yaml
- label: Users Service
docker_compose_file_path: /path/to/users-service/docker-compose.yaml
- label: Catalogue Service
commands:
- whoami
- eval "$(ssh-agent -s)" && ssh-add ~/.ssh/github
- 'echo "SSH Agent PID: $SSH_AGENT_PID"'
docker_compose_file_path: /path/to/catalogue-service/docker-compose.yaml
common:
containers:
- open-webui
docker_compose_file_path: /path/to/common-services/docker-compose.yaml- projects: This is the top-level key containing all your project definitions.
- Project One: This is a sample project containing multiple services.
- services: A list of services associated with the project.
- label: The name of the service (e.g., "Auth Service", "Users Service").
- dependencies: Other services that must be running for this service to start.
- containers: Optional list of Docker containers that need to be running for the service.
- docker_compose_file_path: Path to the Docker Compose file responsible for managing the service.
- common: Shared containers and services that should be running for all services within the project.
- containers: List of shared containers.
- docker_compose_file_path: Docker Compose file for shared services.
Ensure that you have the following tools installed:
- Go (for building the CLI tool)
- Docker and Docker Compose (for managing containers)
-
Clone the main project repository:
git clone https://github.com/mh-daneshvar/dcli.git
-
Navigate to the project directory:
cd dcli -
Tidy up dependencies:
go mod tidy
This ensures all necessary modules are correctly listed and unused dependencies are removed.
-
Build and install the project using the provided
Makefile. The following commands are available in theMakefile:-
Build the project:
make build
This command builds the binary for your current operating system.
-
Install the binary:
sudo make install
This installs the
dclibinary into/usr/local/bin(or another path specified in theMakefile). -
Build for all supported platforms:
make build-all
This cross-compiles the binary for Windows, Linux, and macOS across
amd64architecture. The binaries will be generated in the local directory. -
Clean up the built binaries:
make clean
This removes any previously built binaries from the local directory.
-
Uninstall the binary:
sudo make uninstall
This removes the installed binary from the system (default location:
/usr/local/bin). -
Cross-compile for a specific platform (e.g., Windows
amd64):make build-cross OS=windows ARCH=amd64
This cross-compiles the binary for a specific OS and architecture.
-
-
Clone the helper repository that contains sample projects and services:
git clone https://github.com/mh-daneshvar/dcli-other-projects.git
Once the dcli binary is installed, running the CLI will present you with an interactive menu. This menu is built using the promptui library and allows you to choose actions based on available projects and services.
-
Run the CLI tool:
dcli
-
The tool will prompt you to select an action. For example:
? Select An Action: - Local Development -
After selecting Local Development, you will be prompted to select a project from the list of projects defined in your YAML file. Example:
? Select the Project: - Project One - Project Two -
Once you select a project, you can choose to start or stop individual services, or stop all services. For example:
? Select the Service: - Auth Service - Users Service - Catalogue Service - Stop All Services -
Based on your selection:
- The selected service will either start or stop.
- If "Stop All Services" is selected, all services related to that project will be stopped.
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the main repository (dcli).
- Create a feature branch (
git checkout -b feature/YourFeatureName). - Commit your changes (
git commit -m 'Add YourFeatureName'). - Push to your branch (
git push origin feature/YourFeatureName). - Open a pull request on the main repository.
This project is distributed under the MIT License. See the LICENSE file for more details.