Skip to content

estarter/d-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# sync with github
git remote -v
git remote add upstream https://github.com/estarter/d-tools.git
git fetch upstream
git merge upstream/master
git remote rm upstream

d-tools

The aim of this project is to tackle a problem of "too long commands" in docker. It is a set of useful commands to deal with docker / docker-compose projects in a laconic way.

How to use

Check out usage example based on d-tools-example project (screenplay).

Features

  • Control sophisticated docker-compose project in a simple way
  • Call it from any location
  • Memorise your active docker-compose files and docker-compose project name
  • Allows custom scripts execution before docker build process

Control commands

  • dset - specify project name and docker-compose files. .d-tool.config.json in local or home dir will be created.
  • dbuild - prepare docker build context and build one, few or all images (wrapper for docker-compose build).
  • dup - starts up the system (wrapper for docker-compose up)
  • dps - shows running containers (wrapper for docker ps)
  • ddown - removes and clean up the system (wrapper for docker-compose down)
  • dstart - Start a set of docker containers or all containers (wrapper for docker start or docker-compose start)
  • drestart - Restart a set of docker containers or all containers (wrapper for docker start or docker-compose start)
  • dstop - Stop a set of docker containers or all running containers (wrapper for docker stop or docker-compose stop)
  • dcleanup - remove all dangling images and volumes. It may save a lot of your HD.

Assistant commands

  • dbash container - get a bash session inside the container
  • dlog container - prints out container's log using custom /usr/bin/dlog command. When you have a big zoo of technologies and containers, with different path conventions, it's useful to have a same command that shows log files (example).
  • dclient container - run karaf's client command inside karaf container
  • ddeploy -c container file.jar - deploy file.jar to container server, i.e. copy to the deploy folder /d that should be a symlink to actual deploy folder

Skip container parameter to use the same container:

dlog server
# server logs ...
dbash
# connects to server container
dlog
# server logs ...

Prepare docker context

dbuild auto-discovers prebuild.sh scripts in any build/context folders defined in your docker-compose files and execute it before running docker-compose build command.

That allows you to execute a custom actions just before docker-compose build command is called. It's useful in non-trivial project to prepare docker build context automatically before building the image. For example, you can run the build program in prebuild.sh (e.g. maven).

Try how it works in test project (see prebuild.sh example)

Notes

  • -h options in any script shows all available option
  • dup command would not recreate your containers on change. Use docker rm and dcleanup to recreate a container.
  • dbuild command by default would pull the image. It's could be annoying, but allows to avoid some silly mistakes.

How to install

Update python modules

# if PIP is not installed
sudo apt-get install python-setuptools python-dev build-essential
sudo easy_install pip
sudo pip install argcomplete PyYAML

Make it a git-submodule to your project.

git submodule add -b master https://github.com/estarter/d-tools.git
# add to the PATH variable to call the script from any location
echo "export PATH=$PATH:$(pwd)/d-tools" >> ~/.bashrc

Note that PATH variable would only work for one project.

Autocomplete

BASH

sudo pip install argcomplete

activate-global-python-argcomplete

echo ". $(pwd)/autocomplete.sh" >> ~/.bashrc

ZSH

sudo pip install argcomplete

# enable bash autocomplete supprot
echo 'autoload -Uz compinit bashcompinit' >> ~/.zshrc
echo 'compinit' >> ~/.zshrc
echo 'bashcompinit' >> ~/.zshrc

echo ". $(pwd)/autocomplete.sh" >> ~/.zshrc

Related resources

  1. docker / docker-compose
  2. Docker for Java Developers
  3. jq / jid
  4. docker-tool

TODO

  1. write unit test for them; current test solution: cp ddeploy ddeploy.py && pytest ddeploy.py ; rm ddeploy.py
  2. automate build + PEP-check code

About

useful commands to deal with docker / docker-compose projects

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •