Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

Commit 4539d8e

Browse files
committed
Issue #1206: Add Docker bakery commands.
1 parent 8084dde commit 4539d8e

File tree

8 files changed

+150
-1
lines changed

8 files changed

+150
-1
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
"process-timeout": 1800
2626
},
2727
"scripts": {
28-
"run-tests": "./tests/run-tests.sh"
28+
"run-tests": "./tests/run-tests.sh",
29+
"docker-bake": "./provisioning/docker/bake.sh",
30+
"docker-save-image": "./provisioning/docker/save-image.sh",
31+
"docker-load-image": "./provisioning/docker/load-image.sh"
2932
}
3033
}

default.config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ solr_xmx: "128M"
319319
# Selenium configuration.
320320
selenium_version: 2.53.0
321321

322+
# Docker configuration.
323+
docker_container_name: drupal-vm
324+
docker_image_name: drupal-vm
325+
docker_image_path: ~/Downloads
326+
322327
# Other configuration.
323328
dashboard_install_dir: /var/www/dashboard
324329
known_hosts_path: ~/.ssh/known_hosts

docs/other/docker.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Drupal VM can be used to bake and share [Docker](https://www.docker.com) images.
2+
3+
While building a single Docker container with the entire LAMP/LEMP/LAPP stack is not necessarily the best way to manage Docker-based infrastructure, it works.
4+
5+
TODO:
6+
7+
- composer docker-bake
8+
- composer docker-save-image
9+
- composer docker-load-image

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pages:
6767
- 'Vagrant and VirtualBox': 'other/vagrant-virtualbox.md'
6868
- 'Vagrant LXC provider': 'other/vagrant-lxc.md'
6969
- 'Improving Performance': 'other/performance.md'
70+
- 'Docker': 'other/docker.md'
7071
- 'BigPipe with Drupal VM': 'other/bigpipe.md'
7172
- 'Drupal multisite': 'deployment/multisite.md'
7273
- 'Drupal 6 Notes': 'other/drupal-6.md'

provisioning/docker/bake.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# Set variables.
4+
DRUPALVM_MACHINE_NAME="${DRUPALVM_MACHINE_NAME:-drupal-vm}"
5+
DRUPALVM_HOSTNAME="${DRUPALVM_HOSTNAME:-localhost}"
6+
DRUPALVM_PROJECT_ROOT="${DRUPALVM_PROJECT_ROOT:-/var/www/drupalvm}"
7+
8+
HOST_HTTP_PORT="${HOST_HTTP_PORT:-8080}"
9+
HOST_HTTPS_PORT="${HOST_HTTPS_PORT:-8443}"
10+
11+
DISTRO="${DISTRO:-ubuntu1604}"
12+
OPTS="${OPTS:---privileged}"
13+
INIT="${INIT:-/lib/systemd/systemd}"
14+
15+
# Pretty colors.
16+
red='\033[0;31m'
17+
green='\033[0;32m'
18+
neutral='\033[0m'
19+
20+
# Set volume options.
21+
if [[ "$OSTYPE" == "darwin"* ]]; then
22+
volume_opts='rw,cached'
23+
else
24+
volume_opts='rw'
25+
fi
26+
27+
# Run the container.
28+
printf "\n"${green}"Bringing up Docker container..."${neutral}"\n"
29+
docker run --name=$DRUPALVM_MACHINE_NAME -d \
30+
--add-host "$DRUPALVM_HOSTNAME drupalvm":127.0.0.1 \
31+
-v $PWD:$DRUPALVM_PROJECT_ROOT/:$volume_opts \
32+
-p $HOST_HTTP_PORT:80 \
33+
-p $HOST_HTTPS_PORT:443 \
34+
$OPTS \
35+
geerlingguy/docker-$DISTRO-ansible:latest \
36+
$INIT
37+
38+
# Create Drupal directory.
39+
docker exec $DRUPALVM_MACHINE_NAME mkdir -p $DRUPALVM_PROJECT_ROOT/drupal
40+
41+
# Set things up and run the Ansible playbook.
42+
printf "\n"${green}"Running setup playbook..."${neutral}"\n"
43+
docker exec --tty $DRUPALVM_MACHINE_NAME env TERM=xterm \
44+
ansible-playbook $DRUPALVM_PROJECT_ROOT/tests/test-setup.yml
45+
46+
printf "\n"${green}"Provisioning Drupal VM inside Docker container..."${neutral}"\n"
47+
docker exec $DRUPALVM_MACHINE_NAME env TERM=xterm ANSIBLE_FORCE_COLOR=true \
48+
ansible-playbook $DRUPALVM_PROJECT_ROOT/provisioning/playbook.yml
49+
50+
printf "\n"${green}"...done!"${neutral}"\n"
51+
52+
printf "\n"${green}"Visit the Drupal VM dashboard: http://localhost:$HOST_HTTP_PORT"${neutral}"\n"

provisioning/docker/load-image.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
#
3+
# Load a Docker image from an archive (tar).
4+
#
5+
# Required configuration (in config.yml):
6+
#
7+
# docker_image_name: drupal-vm
8+
# docker_image_path: ~/Downloads
9+
#
10+
11+
# Exit on any individual command failure.
12+
set -e
13+
14+
# Include YAML parser.
15+
source provisioning/docker/parse-yaml.sh
16+
17+
# Pretty colors.
18+
red='\033[0;31m'
19+
green='\033[0;32m'
20+
neutral='\033[0m'
21+
22+
# Set variables.
23+
image_name=$(parse_yaml config.yml docker_image_name)
24+
image_path=$(parse_yaml config.yml docker_image_path)
25+
image_full_path="$image_path/$image_name.tar.gz"
26+
image_full_path=${image_full_path/#\~/$HOME} # Expand ~ to $HOME.
27+
28+
# Load the image.
29+
printf "\n"${green}"Loading Docker image..."${neutral}"\n"
30+
gunzip -c $image_full_path | docker load
31+
printf ${green}"...done!"${neutral}"\n"

provisioning/docker/parse-yaml.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
#
3+
# Parse a YAML file.
4+
#
5+
# Usage:
6+
# parse_yaml [file-path] [variable-to-retrieve]
7+
#
8+
# Requires ruby.
9+
# @see https://coderwall.com/p/bm_tpa/reading-yaml-files-in-bash-with-ruby
10+
# @todo Consider using PHP so user doesn't need to install Ruby.
11+
12+
function parse_yaml {
13+
ruby -ryaml -e 'puts ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@"
14+
}

provisioning/docker/save-image.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
#
3+
# Commit a Docker image and save it to an archive (tar).
4+
#
5+
# Required configuration (in config.yml):
6+
#
7+
# docker_container_name: drupal-vm
8+
# docker_image_name: drupal-vm
9+
# docker_image_path: ~/Downloads
10+
#
11+
12+
# Exit on any individual command failure.
13+
set -e
14+
15+
# Include YAML parser.
16+
source provisioning/docker/parse-yaml.sh
17+
18+
# Pretty colors.
19+
red='\033[0;31m'
20+
green='\033[0;32m'
21+
neutral='\033[0m'
22+
23+
# Set variables.
24+
container_name=$(parse_yaml config.yml docker_container_name)
25+
image_name=$(parse_yaml config.yml docker_image_name)
26+
image_path=$(parse_yaml config.yml docker_image_path)
27+
image_full_path="$image_path/$image_name.tar.gz"
28+
image_full_path="${image_full_path/#\~/$HOME}" # Expand ~ to $HOME.
29+
30+
# Save the image.
31+
printf "\n"${green}"Saving Docker container to $image_full_path..."${neutral}"\n"
32+
docker commit $container_name $image_name
33+
docker save $image_name | gzip -1 > $image_full_path
34+
printf ${green}"...done!"${neutral}"\n"

0 commit comments

Comments
 (0)