Skip to content

Instantly share code, notes, and snippets.

@creack
Created June 19, 2013 21:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save creack/5818456 to your computer and use it in GitHub Desktop.
Save creack/5818456 to your computer and use it in GitHub Desktop.
prestasthop orchestration for docker
#!/bin/sh
# Set conveniance variables0
PS_PATH=/var/www/prestashop
PS_SETTINGS_FILE=$PS_PATH/config/settings.inc.php
PS_SETTINGS_TEMPLATE=$PS_PATH/config/settings.inc.php.template
# Build the base PrestaShop image from the Dockerfile
IMAGE_ID=$(cat Dockerfile | docker build - | tail -1)
# Set a root password (random), grant access from outside and create the database
MYSQL_PASSWORD=$(date | \grep -o '[A-Za-z0-9]' | head -n 21 | tr -d '\n')
TMP_ID=$(docker run -d $IMAGE_ID bash -c "mysqld& sleep 3; mysqladmin -u root password $MYSQL_PASSWORD && echo \"grant all on *.* to 'root'@'%' identified by '$MYSQL_PASSWORD' with grant option\"| mysql -u root -p$MYSQL_PASSWORD && echo create database prestashop | mysql -u root -p$MYSQL_PASSWORD")
docker wait $TMP_ID > /dev/null
IMAGE_ID=$(docker commit $TMP_ID)
# Run mysqld, retrieve its ip
MYSQL_ID=$(docker run -d $IMAGE_ID /usr/sbin/mysqld)
MYSQL_IP=$(docker inspect $MYSQL_ID | \grep IpAddress | sed 's/[^0-9.]//g' | tr -d '\n')
# Generate a config file in for PrestaShop to be aware of mysqld
#TMP_ID=$(docker run $IMAGE_ID bash -c "cat $PS_SETTINGS_TEMPLATE > $PS_SETTINGS_FILE && chown www-data:www-data $PS_SETTINGS_FILE")
TMP_ID=$(docker run -d $IMAGE_ID bash -c "cat $PS_SETTINGS_TEMPLATE | sed 's/%_DB_SERVER_VALUE_%/$MYSQL_IP/g' | sed 's/%_DB_PASSWD_VALUE_%/$MYSQL_PASSWORD/g' > $PS_SETTINGS_FILE && chown www-data:www-data $PS_SETTINGS_FILE && chown -R www-data:www-data /var/www/prestashop")
docker wait $TMP_ID > /dev/null
IMAGE_ID=$(docker commit $TMP_ID prestashop)
# tag the image as PrestaShop
docker tag $IMAGE_ID prestashop
# Run Apache
APACHE_ID=$(docker run -d -p :80 $IMAGE_ID /usr/sbin/apache2ctl -D FOREGROUND)
APACHE_IP=$(docker inspect $APACHE_ID | \grep IpAddress | sed 's/[^0-9.]//g' | tr -d '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment