Giter Site home page Giter Site logo

devilbox-cli's Introduction

Devilbox CLI

npm npm GitHub file size in bytes GitHub license

A simple and conveniant command line to manage devilbox from anywhere


Getting Started

Requirements

You need Devilbox to be installed somewhere on your computer.

By default, the script will use the path $HOME/.devilbox. If you have cloned devilbox somewhere else, add the following to your profile and change ##PATH_TO_DEVILBOX## accordingly:

export DEVILBOX_PATH="$HOME/##PATH_TO_DEVILBOX##"

Then reload your terminal or run source ~/.zshrc if you use zsh.

Install

As simple as :

npm install -g devilbox-cli

If installed successfully, you should see something like this when you run devilbox -v:

devilbox-cli v0.4.1 (2020-12-06)
A simple and conveniant cli to manage devilbox from anywhere
https://github.com/louisgab/devilbox-cli

Alternatives

If you don't have npm or don't wan to use it, you can also download the script directly:

curl -O https://raw.githubusercontent.com/louisgab/devilbox-cli/master/dist/devilbox-cli.sh
chmod +x devilbox-cli.sh
sudo mv devilbox-cli.sh /usr/local/bin/devilbox

This way you can call the script from anywhere, but you won't be able to download updates (that was the point of using npm). For a manual update, delete it first

sudo rm /usr/local/bin/devilbox

Then re-download the script.

Usage

devilbox-cli provides all basic command to manage your installation:

devilbox check   # Check your .env
devilbox config  # Get and set variables on your .env
devilbox enter   # Enter the php container with shell.sh script
devilbox exec    # Execute a command in the container
devilbox mysql   # Execute a command in the container
devilbox open    # Open the devilbox intranet
devilbox run     # Start the containers
devilbox stop    # Stop all containers
devilbox restart # Stop and rerun all containers
devilbox update  # Update to latest devilbox version

To see containers current versions defined in devilbox .env file, use the config command:

devilbox config --apache --php --mysql
# [!] Apache current version is 2.4
# [!] PHP current version is 7.2
# [!] MySql current version is 5.6

It can also list available versions of any container:

devilbox config --mysql=*
# [!] MySql available versions:
# 5.5
# 5.6
# 5.7
# 8.0

And of course, it can change any version:

devilbox config --php=8.0
# [✔] PHP version updated to 8.0

You can also point devilbox to your projects folder:

devilbox config --www=../Documents/Projects/www
# [✔] Projects path config updated to ../Documents/Projects/wwww

And if you dont remember a command, devilbox help is your best friend :)

Optional Configuration

By default, the run command will start the default LAMP stack containers php httpd mysql. The command can be customized by configuring your desired services via the $DEVILBOX_CONTAINERS variable. For example, if you'd like to also run the NOSQL stack, you would define the following:

export DEVILBOX_CONTAINERS="php httpd mysql redis memcd mongo"

Then reload your terminal or run source ~/.zshrc if you use zsh.

Important notes

The script was tested on zsh and bash on linux. Use at your own risk on other platforms.

Contributing

Highly welcomed! The script only implements the basics I needed for myself (LAMP). It may be useful for others to add missing commands, test it on macOS and Windows, and test in on other shells.

License

MIT License

devilbox-cli's People

Contributors

llaville avatar louisgab avatar thomasplevy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

devilbox-cli's Issues

Feature: handle additional services with new `compose` command

Hello,

My suggestion, is to add a new command to handle other services/containers that we could add in docker-compose.overrride.yml easily.

We have to fix a coding standard to make it possible.
As introduced in devilbox project itself there is a compose/ folder with lot of docker-compose.overrride.yml-* files

Here are what my draft version is able to do :

dist/devilbox-cli.sh compose --containers will give the current stack containers : see DEVILBOX_CONTAINERS env var already available

i.e: with defaults containers

dist/devilbox-cli.sh compose --containers
[!] Stack Containers ready:
httpd
php
mysql

Now, if I want to launch httpd, php, mysql (default containers) plus mailhog, we have to run

dist/devilbox-cli.sh compose --containers=mailhog

And the four containers will be launch

When there are many others containers, we just have to enclose list in double quote like this

dist/devilbox-cli.sh compose --containers="mailhog portainer"

Hope you will like this new feature. Waiting your feedback to propose a PR.

get mysql version error

this line in get_current_choice function is not valid for:
mariadb-*
percona-*

current=$(grep -Eo "^$config+[.[:digit:]]*" "$ENV_FILE" | sed "s/.*$config//g")

Run containers other than php, mysql, & httpd using the cli?

I'm finding this very useful but I've recently decided to add some additional services outside of the aforementioned list and I'm not finding a way to quickly start / stop these containers using this CLI.

After reviewing everything it looks like that's because these services are hardcoded into the run command.

I've taken a stab at rewriting the command to accommodate my requirement but I'm not super familiar with bash and ended up doing something kind of hacky to get it working to my liking.

My desire would be to be able to either specify which services I'd like to run via run and stop when calling the command, for example devilbox run -s http mysql php mailhog, or, alternatively, and what I've come up with, is to specify default services via a variable which will be used in favor of the currently hardcoded list if it exists. This would allow the existing default behavior to start my additional container if I decide I want an additional container. For example:

EXPORT DEVILBOX_SERVICES="php mysql httpd mailhog

When I run devilbox run it should start all of these services.

Here's the modifications I made to the compiled distribution script to make this latter option possible:

get_default_services() {
    if [ -n "$DEVILBOX_SERVICES" ]; then
        printf %s "${DEVILBOX_SERVICES}"
    else
        printf %s "httpd php mysql"
    fi
}

run_containers () {
    docker-compose up $(get_default_services)
}

run_containers_silent () {
    docker-compose up -d $(get_default_services)
}

If this seems like an acceptable solution I'd be happy to convert this into a useable PR and submit it for you.

Thanks,

New feature: Restart command

I wrote a simple bash command to restart devilbox via the cli, devilbox stop && devilbox run -s. In the last week I've found myself regularly running this command.

If it seems generally useful I added a new command to the devilbox-cli to enable this in a single command:

devilbox restart    # Stop and restart containers.
devilbox restart -s # Stop and restart containers silently.

I've already committed the command to my fork and if it feels useful I'll submit it as a PR instead of working off my fork locally.

Here's the diff if you're interested: https://github.com/louisgab/devilbox-cli/compare/master...gocodebox:feature/restart-command?expand=1

However I accidentally committed after submitting #4 and I don't feel like rewriting history on my fork to get a clean diff without the changes made to #4

Thanks! This is a great tool and I just want to make it a little better for my personal needs

Is it possible to install it without npm ?

I am not fan of installing node and npm in my local system, that's why I use Devilbox.
Could you provide instructions for manual installation ?

Thank you in advance.

devilbox run in detached mode?

Hi,

It seems that devilbox run behaves like docker-compose up. Is it possible to change it to make it detached? As of docker-compose up -d

Needs to allow for winpty in windows

Yes I know we should use at our own risk so just alerting to the fact that you can't do "devilbox e" in windows as it complains about winpty, and with winpty prefixed, it gives an error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.