Skip to content

Commit

Permalink
Merge pull request cytopia#115 from cytopia/DVL-012-customise-bash
Browse files Browse the repository at this point in the history
DVL-012 be able to customize bash config files
  • Loading branch information
cytopia authored Aug 18, 2017
2 parents bbfd938 + 87b7219 commit 0c4290b
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
/mod/php-fpm-7.2/*.so
/mod/hhvm-latest/*.so

# Ignore custom bash and other confi files
/bash/*
!/bash/bashrc.sh-example
!/bash/README.md

######################################
# GENERIC
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,16 @@ Every single attachable container comes with many different versions. In order t

#### Enter the container

You can also work directly inside the php container. Simply use the bundled scripts `bash.sh` or `root_bash.sh`. The `PS1` will automatically be populated with current chosen php version.
You can also work directly inside the php container. Simply use the bundled scripts `shell.sh`. The `PS1` will automatically be populated with current chosen php version.
```shell
# Enter as user devilbox (normal operation / development)
host> ./bash.sh
host> ./shell.sh
devilbox@php-7.0.19 in /shared/httpd $
```
```shell
# Enter as root user (do root stuff)
host> ./root_bash.sh
host> ./shell.sh
devilbox@php-7.0.19 in /shared/httpd $ sudo su -
root@php-7.0.19 in /shared/httpd $
```

Expand Down
Empty file added bash/README.md
Empty file.
14 changes: 14 additions & 0 deletions bash/bashrc.sh-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Bashrc folder
#
# 1. This folder will be mounted to /etc/bashrc-devilbox.d
# 2. All files ending by *.sh will be sourced by bash automatically
# for the devilbox and root user.
#


# Add your custom vimrc and always load it with vim.
# Also make sure you add vimrc to this folder.
alias vim='vim -u /etc/bashrc-devilbox.d/vimrc



3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ services:
# to load custom PHP modules
- ${DEVILBOX_PATH}/mod/${PHP_SERVER}:/usr/lib64/php/custom-modules:ro

# Mount devilbox user-defined bash config
- ${DEVILBOX_PATH}/bash:/etc/bashrc-devilbox.d

# Mount custom mass virtual hosting
# (configured in /etc/${HTTPD_SERVER}/02-vhost-mass.conf)
- ${HOST_PATH_HTTPD_DATADIR}:/shared/httpd
Expand Down
22 changes: 11 additions & 11 deletions docs/Backups.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ There are many different options to backup your MySQL database including some fo

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the backup
devilbox@php-7.1.6 in /shared/httpd $ mysqldump-secure
Expand Down Expand Up @@ -209,7 +209,7 @@ To find out more about the configuration and options of mysqldump-secure, visit

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the backup
devilbox@php-7.1.6 in /shared/httpd $ mysqldump -h mysql -u root -p my_db_name > /shared/backups/mysql/my_db_name.sql
Expand Down Expand Up @@ -239,7 +239,7 @@ In order to restore or import mysql databases on the command line, you need to u

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the import
devilbox@php-7.1.6 in /shared/httpd $ mysql -h mysql -u root -p my_db_name < /shared/backups/mysql/my_db_name.sql
Expand All @@ -249,7 +249,7 @@ devilbox@php-7.1.6 in /shared/httpd $ mysql -h mysql -u root -p my_db_name < /sh

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the import
devilbox@php-7.1.6 in /shared/httpd $ zcat /shared/backups/mysql/my_db_name.sql.gz | mysql -h mysql -u root -p my_db_name
Expand All @@ -259,7 +259,7 @@ devilbox@php-7.1.6 in /shared/httpd $ zcat /shared/backups/mysql/my_db_name.sql.

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the import
devilbox@php-7.1.6 in /shared/httpd $ tar xzOf /shared/backups/mysql/my_db_name.sql.tar.gz | mysql -h mysql -u root -p my_db_name
Expand All @@ -284,7 +284,7 @@ devilbox@php-7.1.6 in /shared/httpd $ tar xzOf /shared/backups/mysql/my_db_name.

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the import
devilbox@php-7.1.6 in /shared/httpd $ pg_dump -h pgsql -U postgres -W my_db_name > /shared/backups/pgsql/my_db_name.sql
Expand All @@ -308,7 +308,7 @@ In order to restore or import PostgreSQL databases on the command line, you need

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the import
devilbox@php-7.1.6 in /shared/httpd $ psql -h pgsql -U postgres -W my_db_name < /shared/backups/pgsql/my_db_name.sql
Expand All @@ -318,7 +318,7 @@ devilbox@php-7.1.6 in /shared/httpd $ psql -h pgsql -U postgres -W my_db_name <

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the import
devilbox@php-7.1.6 in /shared/httpd $ zcat /shared/backups/pgsql/my_db_name.sql.gz | psql -h pgsql -U postgres -W my_db_name
Expand All @@ -328,7 +328,7 @@ devilbox@php-7.1.6 in /shared/httpd $ zcat /shared/backups/pgsql/my_db_name.sql.

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the import
devilbox@php-7.1.6 in /shared/httpd $ tar xzOf /shared/backups/pgsql/my_db_name.sql.tar.gz | psql -h pgsql -U postgres -W my_db_name
Expand All @@ -349,7 +349,7 @@ devilbox@php-7.1.6 in /shared/httpd $ tar xzOf /shared/backups/pgsql/my_db_name.

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the dump into /shared/backups/mongo
devilbox@php-7.1.6 in /shared/httpd $ mongodump --out /shared/backups/mongo
Expand All @@ -365,7 +365,7 @@ To find out more about the configuration and options of mongodump, visit its pro

```shell
# Enter the Container
host> ./bash.sh
host> ./shell.sh

# Start the restore/import from /shared/backups/mongo
devilbox@php-7.1.6 in /shared/httpd $ mongorestore /shared/backups/mongo
Expand Down
62 changes: 58 additions & 4 deletions docs/Configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Configure |
2. [The devilbox `cfg/` directory](#12-the-devilbox-cfg-directory)
3. [The devilbox `mod/` directory](#13-the-devilbox-mod-directory)
1. [Custom PHP module example](#134-custom-php-module-example)
4. [The operating system `hosts` file](#14-the-operating-system-hosts-file)
5. [The operating system `resolv.conf` file](#15-the-operating-system-resolvconf-file)
4. [The devilbox `bash/` directory](#14-the-devilbox-bash-directory)
5. [The operating system `hosts` file](#15-the-operating-system-hosts-file)
6. [The operating system `resolv.conf` file](#16-the-operating-system-resolvconf-file)
2. [Devilbox general settings](#2-devilbox-general-settings)
1. [Verbosity](#21-verbosity)
2. [Devilbox base path](#22-devilbox-base-path)
Expand All @@ -43,6 +44,7 @@ Configure |
3. [php.ini](#423-phpini)
4. [HHVM](#424-hhvm)
5. [Custom PHP modules](#425-custom-php-modules)
6. [Customize bash and other tools](#426-customize-bash-and-other-tools)
3. [Apache / Nginx](#43-apache--nginx)
1. [Select Httpd version](#431-select-httpd-version)
2. [Host port](#432-host-port)
Expand Down Expand Up @@ -176,13 +178,19 @@ zend_extension = /usr/lib64/php/custom-modules/ioncube_loader_lin_7.0.so

**Note:** PHP configuration files are loaded by file names in alphabetical order and the ioncube zend extension needs to be loaded before any other zend extension. This is the reason why its configuration file name starts with `00-`.

#### 1.4 The operating system `hosts` file
#### 1.4 The devilbox `bash/` directory

Inside the devilbox root directory you will find a folder called `bash/`. Every file inside this folder ending by `*.sh` will be source by your bash, allowing for a customized bash configuration. All files not ending by `*.sh` will be ignored and can be used to create config files for other programs.

The `bash/` folder will be mounted into the PHP/HHVM container to `/etc/bashrc-devilbox.d/`.

#### 1.5 The operating system `hosts` file

On Linux and OSX your hosts file is located at `/etc/hosts` on Windows it will be at `C:\Windows\System32\drivers\etc`. Use this file to setup custom DNS entries if you are not using Auto-DNS.

Read up on it below at `/etc/hosts` or `Auto-DNS` section.

#### 1.5 The operating system `resolv.conf` file
#### 1.6 The operating system `resolv.conf` file

This file is used to add the devilbox DNS server for Auto-DNS.

Expand Down Expand Up @@ -444,6 +452,52 @@ zend_extension = /usr/lib64/php/custom-modules/ioncube_loader_lin_7.0.so

**Note:** PHP configuration files are loaded by file names in alphabetical order and the ioncube zend extension needs to be loaded before any other zend extension. This is the reason why its configuration file name starts with `00-`.

##### 4.2.6 Customize bash and other tools

The devilbox supports to load custom configuration files for your Docker containers bash. Put any file ending by `*.sh` into the `bash/` folder and they will automatically be sourced by your container's bash. It is also possible to add any other configuration files into that folder and start your app with the appended configuration path. To better understand how that works, have a look at the paths:

| Docker | bash host path | Path inside Docker container |
|---------|----------------------------|------------------------|
| PHP 5.4 | `bash/<cfg>.sh` | `/etc/bashrc-devilbox.d/<cfg>.sh` |
| PHP 5.5 | `bash/<cfg>.sh` | `/etc/bashrc-devilbox.d/<cfg>.sh` |
| PHP 5.6 | `bash/<cfg>.sh` | `/etc/bashrc-devilbox.d/<cfg>.sh` |
| PHP 7.0 | `bash/<cfg>.sh` | `/etc/bashrc-devilbox.d/<cfg>.sh` |
| PHP 7.1 | `bash/<cfg>.sh` | `/etc/bashrc-devilbox.d/<cfg>.sh` |
| PHP 7.2 | `bash/<cfg>.sh` | `/etc/bashrc-devilbox.d/<cfg>.sh` |
| HHVM | `bash/<cfg>.sh` | `/etc/bashrc-devilbox.d/<cfg>.sh` |

So lets assume you also want to change your vim configuration and have vim always use that specific config file during startup. This is achieved by placing the vim config file into that directory and create a bash alias, that always starts vim with that config file:

On your host system do the following:

```shell
# Create your vim config in the devilbox bash directory `my-vimrc`
$ vim bash/my-vimrc
```
```vim
" You vim
set encoding=utf-8 " The encoding displayed
set nocompatible " Use vim defaults instead of vi defaults
set autoread " Automatically reload file contents when changed from outside
set backspace=indent,eol,start " Allow backspacing over everything in insert mode
set hidden " Start new file with :e without having to save current
set history=50 " Remember commands entered in :
set undolevels=100 " Use many levels of undo
set shell=$SHELL " Set Shell
set more " to show pages using `more` in command outpouts
set title " show vim in terminal title
```

Now add a custom bash config and create an alias to always start vim with the above created config:
```shell
$ vim bash/my-bash.sh
```
```shell
alias vim='vim -u /etc/bashrc-devilbox.d/my-vimrc'
```

The next time you open `vim` within the PHP/HHVM docker container, it will automatically source your `my-vimrc`.

#### 4.3 Apache / Nginx

##### 4.3.1 Select Httpd version
Expand Down
16 changes: 8 additions & 8 deletions docs/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ It will be ready in eight simple steps:

```shell
# 1. Enter the PHP container
host> ./bash.sh
host> ./shell.sh

# 2. Create a new VirtualHost directory
devilbox@php-7.0.20 in /shared/httpd $ mkdir my-cake
Expand Down Expand Up @@ -165,7 +165,7 @@ It will be ready in six simple steps:

```shell
# 1. Enter the PHP container
host> ./bash.sh
host> ./shell.sh

# 2. Create a new VirtualHost directory
devilbox@php-7.0.20 in /shared/httpd $ mkdir my-drupal
Expand Down Expand Up @@ -213,7 +213,7 @@ It will be ready in six simple steps:

```shell
# 1. Enter the PHP container
host> ./bash.sh
host> ./shell.sh

# 2. Create a new VirtualHost directory
devilbox@php-7.0.20 in /shared/httpd $ mkdir my-laravel
Expand Down Expand Up @@ -259,7 +259,7 @@ It will be ready in six simple steps:

```shell
# 1. Enter the PHP container
host> ./bash.sh
host> ./shell.sh

# 2. Create a new VirtualHost directory
devilbox@php-7.0.20 in /shared/httpd $ mkdir my-phalcon
Expand Down Expand Up @@ -306,7 +306,7 @@ It will be ready in six simple steps:

```shell
# 1. Enter the PHP container
host> ./bash.sh
host> ./shell.sh

# 2. Create a new VirtualHost directory
devilbox@php-7.0.20 in /shared/httpd $ mkdir my-symfony
Expand Down Expand Up @@ -356,7 +356,7 @@ It will be ready in six simple steps:

```shell
# 1. Enter the PHP container
host> ./bash.sh
host> ./shell.sh

# 2. Create a new VirtualHost directory
devilbox@php-7.0.20 in /shared/httpd $ mkdir my-wp
Expand Down Expand Up @@ -402,7 +402,7 @@ It will be ready in six simple steps:

```shell
# 1. Enter the PHP container
host> ./bash.sh
host> ./shell.sh

# 2. Create a new VirtualHost directory
devilbox@php-7.0.20 in /shared/httpd $ mkdir my-yii
Expand Down Expand Up @@ -448,7 +448,7 @@ It will be ready in six simple steps:

```shell
# 1. Enter the PHP container
host> ./bash.sh
host> ./shell.sh

# 2. Create a new VirtualHost directory
devilbox@php-7.0.20 in /shared/httpd $ mkdir my-zend
Expand Down
2 changes: 1 addition & 1 deletion docs/Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ To quickly find setup instructions for your framework of choice head over to **[
The PHP Docker container is your workhorse which has many tools pre-installed and you can do every task inside instead of doing it on the docker host. Entering the container is done via a shipped script:

```shell
host> ./bash.sh
host> ./shell.sh
devilbox@php-7.0.19 in /shared/httpd $
```

Expand Down
9 changes: 5 additions & 4 deletions docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,22 @@ The situation inside the container is not different from on the Docker host. All

#### 3.1 As devilbox user

In the devilbox git directory you will find a bash script called `bash.sh`. Just execute this script and it will take you directly into the PHP docker container at the project root directory.
In the devilbox git directory you will find a bash script called `shell.sh`. Just execute this script and it will take you directly into the PHP docker container at the project root directory.

```shell
host> ./bash.sh
host> ./shell.sh
devilbox@php-7.0.19 in /shared/httpd $
```

As you can see, the PS1 prompt will also show you the current configured PHP version.

#### 3.2 As root user

In case you need to perform some tasks that are only possible with root rights (such as installing or updating software), you can also use the `root_bash.sh` script.
In case you need to perform some tasks that are only possible with root rights (such as installing or updating software), you can do so via password-less `sudo`.

```shell
host> ./root_bash.sh
host> ./shell.sh
devilbox@php-7.0.19 in /shared/httpd $ sudo su -
root@php-7.0.19 in /shared/httpd $
```

Expand Down
4 changes: 0 additions & 4 deletions root_bash.sh

This file was deleted.

File renamed without changes.

0 comments on commit 0c4290b

Please sign in to comment.