Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
refactoring: load the composer cache once and mount into containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Schnitzel committed May 26, 2017
1 parent d3d56a6 commit f680e3f
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 41 deletions.
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
cached
delegated
consistent
cachalot
/cached/*
!/cached/docker-compose.yml
/delegated/*
!/delegated/docker-compose.yml
/consistent/*
!/consistent/docker-compose.yml
/cachalot/*
!/cachalot/docker-compose.yml
composer-cache
drupal
39 changes: 39 additions & 0 deletions cachalot/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Create the Drupal site you would like here
version: '2'
services:
drupal:
# Choose the URL and hostname for this Docker Container
# NEEDS to end with '.docker.amazee.io' !
# DO NOT remove the '&hostname'
hostname: &hostname cachalot.docker.amazee.io

environment:
# If you use https://github.com/drupal-composer/drupal-project or something similar,
# the Drupal root is not inside the repository root. Here you can define in which folder
# the Drupal root lives
WEBROOT: web

AMAZEEIO_DISABLE_ALIASES: 'true'

# If you would like to use blackfire.io, uncomment and add your server credentials:
#BLACKFIRE_SERVER_ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
#BLACKFIRE_SERVER_TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# If you want to use stage_file_proxy, uncomment following line and add the production url of your website:
#AMAZEEIO_PRODUCTION_URL: 'http://example.com'

# APC Support is by enabled by default, but in some cases it can cause issues, change to 0 to disable:
APC: 1


################################################
### Do not change anything below here, unless you know what know what you are doing.
VIRTUAL_HOST: *hostname
image: amazeeio/drupal:php70-basic
volumes:
- .:/var/www/drupal/public_html
- ../composer-cache:/var/www/drupal/.composer/cache
container_name: *hostname
network_mode: bridge
ports:
- "3306"
39 changes: 39 additions & 0 deletions cached/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Create the Drupal site you would like here
version: '2'
services:
drupal:
# Choose the URL and hostname for this Docker Container
# NEEDS to end with '.docker.amazee.io' !
# DO NOT remove the '&hostname'
hostname: &hostname cached.docker.amazee.io

environment:
# If you use https://github.com/drupal-composer/drupal-project or something similar,
# the Drupal root is not inside the repository root. Here you can define in which folder
# the Drupal root lives
WEBROOT: web

AMAZEEIO_DISABLE_ALIASES: 'true'

# If you would like to use blackfire.io, uncomment and add your server credentials:
#BLACKFIRE_SERVER_ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
#BLACKFIRE_SERVER_TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# If you want to use stage_file_proxy, uncomment following line and add the production url of your website:
#AMAZEEIO_PRODUCTION_URL: 'http://example.com'

# APC Support is by enabled by default, but in some cases it can cause issues, change to 0 to disable:
APC: 1


################################################
### Do not change anything below here, unless you know what know what you are doing.
VIRTUAL_HOST: *hostname
image: amazeeio/drupal:php70-basic
volumes:
- .:/var/www/drupal/public_html:cached
- ../composer-cache:/var/www/drupal/.composer/cache:cached
container_name: *hostname
network_mode: bridge
ports:
- "3306"
39 changes: 39 additions & 0 deletions consistent/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Create the Drupal site you would like here
version: '2'
services:
drupal:
# Choose the URL and hostname for this Docker Container
# NEEDS to end with '.docker.amazee.io' !
# DO NOT remove the '&hostname'
hostname: &hostname consistent.docker.amazee.io

environment:
# If you use https://github.com/drupal-composer/drupal-project or something similar,
# the Drupal root is not inside the repository root. Here you can define in which folder
# the Drupal root lives
WEBROOT: web

AMAZEEIO_DISABLE_ALIASES: 'true'

# If you would like to use blackfire.io, uncomment and add your server credentials:
#BLACKFIRE_SERVER_ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
#BLACKFIRE_SERVER_TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# If you want to use stage_file_proxy, uncomment following line and add the production url of your website:
#AMAZEEIO_PRODUCTION_URL: 'http://example.com'

# APC Support is by enabled by default, but in some cases it can cause issues, change to 0 to disable:
APC: 1


################################################
### Do not change anything below here, unless you know what know what you are doing.
VIRTUAL_HOST: *hostname
image: amazeeio/drupal:php70-basic
volumes:
- .:/var/www/drupal/public_html:consistent
- ../composer-cache:/var/www/drupal/.composer/cache:consistent
container_name: *hostname
network_mode: bridge
ports:
- "3306"
39 changes: 39 additions & 0 deletions delegated/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Create the Drupal site you would like here
version: '2'
services:
drupal:
# Choose the URL and hostname for this Docker Container
# NEEDS to end with '.docker.amazee.io' !
# DO NOT remove the '&hostname'
hostname: &hostname delegated.docker.amazee.io

environment:
# If you use https://github.com/drupal-composer/drupal-project or something similar,
# the Drupal root is not inside the repository root. Here you can define in which folder
# the Drupal root lives
WEBROOT: web

AMAZEEIO_DISABLE_ALIASES: 'true'

# If you would like to use blackfire.io, uncomment and add your server credentials:
#BLACKFIRE_SERVER_ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
#BLACKFIRE_SERVER_TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# If you want to use stage_file_proxy, uncomment following line and add the production url of your website:
#AMAZEEIO_PRODUCTION_URL: 'http://example.com'

# APC Support is by enabled by default, but in some cases it can cause issues, change to 0 to disable:
APC: 1


################################################
### Do not change anything below here, unless you know what know what you are doing.
VIRTUAL_HOST: *hostname
image: amazeeio/drupal:php70-basic
volumes:
- .:/var/www/drupal/public_html:delegated
- ../composer-cache:/var/www/drupal/.composer/cache:delegated
container_name: *hostname
network_mode: bridge
ports:
- "3306"
38 changes: 27 additions & 11 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,52 @@

function printtime {
START=$(date +%s)
"$@" &> /dev/null
"$@"
END=$(date +%s)
DIFF=$(echo "$END - $START" | bc)
echo "$DIFF seconds"
echo -e "\033[97;48;5;21m ${DIFF} seconds\x1B[K\033[0m\n"
}

function colorecho {
echo -e "\033[30;48;5;82m $1 \x1B[K\033[0m"
}


function runTest {
pushd $1

echo "### $1: starting container"
colorecho "### $1: removing old containers"
printtime docker-compose down -v || true

colorecho "### $1: starting container"
printtime docker-compose up -d --force

echo "### $1: drush site install 3x"
colorecho "### $1: remove old drupal folder"
printtime docker-compose exec --user drupal drupal bash -c 'chmod -R +w drupal && rm -rf drupal'

colorecho "### $1: composer create project"
printtime docker-compose exec --user drupal drupal bash -c 'composer create-project amazeeio/drupal-project:8.x-dev drupal --no-interaction'

colorecho "### $1: drush site install 3x"
for i in `seq 1 3`;
do
printtime docker-compose exec -T --user drupal drupal bash -c 'cd ~/public_html/web && drush -y si --account-name=blub [email protected]'
printtime docker-compose exec --user drupal drupal bash -c 'cd ~/public_html/drupal/web && drush -y si --account-name=blub [email protected]'
done


echo "### $1: drush cr 3x"
colorecho "### $1: drush cr 3x"
for i in `seq 1 3`;
do
printtime docker-compose exec -T --user drupal drupal bash -c 'cd ~/public_html/web && drush -y cr'
printtime docker-compose exec --user drupal drupal bash -c 'cd ~/public_html/drupal/web && drush -y cr'
done

colorecho "### $1: removing containers"
printtime docker-compose down -v || true

popd
}

echo "### CACHALOT"
colorecho "### CACHALOT"
# Loading env variables so that we use Cachalot (Docker Machine)
eval $(amazeeio-cachalot env)

Expand All @@ -41,11 +57,11 @@ runTest cachalot
# see https://docs.docker.com/docker-for-mac/docker-toolbox/
unset ${!DOCKER_*}

echo "### Docker for Mac - delegated"
colorecho "### Docker for Mac - delegated"
runTest delegated

echo "### Docker for Mac - cached"
colorecho "### Docker for Mac - cached"
runTest cached

echo "### Docker for Mac - consistent"
colorecho "### Docker for Mac - consistent"
runTest consistent
35 changes: 9 additions & 26 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
#!/bin/bash

function createFolder {
chmod -R +w $1
rm -rf $1
mkdir -p $1

echo "### composer create-project in $1"
composer create-project amazeeio/drupal-project:8.x-dev $1 --no-interaction &> /dev/null
}

function setupDockerCompose {
echo "### changing docker-compose.yml hostname to $1.docker.amazee.io"
sed -i -e "s/changeme.docker.amazee.io/$1.docker.amazee.io/" $1/docker-compose.yml
function setupCache {
echo "### warming composer-cache to be mounted into docker containers"
chmod -R +w composer-cache drupal
rm -rf composer-cache drupal
mkdir -p composer-cache drupal

mkdir -p composer-cache
COMPOSER_CACHE_DIR=$PWD/composer-cache composer create-project amazeeio/drupal-project:8.x-dev drupal --no-interaction &> /dev/null
}

function configureMountType {
echo "### changing docker-compose.yml to use $1 volume mount"
sed -i -e "s/.:\/var\/www\/drupal\/public_html$/.:\/var\/www\/drupal\/public_html:$1/" $1/docker-compose.yml
}

for i in cachalot cached consistent delegated; do
createFolder $i
setupDockerCompose $i
done

# Set the MountType in docker-compose, important: not for cachalot as cachalot does not support any mount types
for i in cached consistent delegated; do
configureMountType $i
done
setupCache

0 comments on commit f680e3f

Please sign in to comment.