Last active
June 24, 2017 04:18
-
-
Save danny-englander/be26c716d225870ad41f to your computer and use it in GitHub Desktop.
OpenShift Origin Drupal Deploy Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This deploy hook gets executed after dependencies are resolved and the | |
# build hook has been run but before the application has been started back | |
# up again. This script gets executed directly, so it could be python, php, | |
# ruby, etc. | |
# Bash help: http://www.panix.com/~elflord/unix/bash-tute.html | |
# For information about action hooks supported by OpenShift, consult the documentation: | |
# http://openshift.github.io/documentation/oo_user_guide.html#the-openshift-directory | |
#### | |
# Drupal specific deploy script (Drupal 6, 7 or 8) | |
# Place this file in /.openshift/action_hooks/ (The .openshift folder will be in the root of your repo) | |
# The file name should be "deploy" such that you have: | |
# .openshift/action_hooks/deploy | |
# Conventions: Vars in curley braces have the slash after implied so no need to add it. | |
# e.g. ${OPENSHIFT_REPO_DIR}php/foobar = /repo/php/foobar | |
# See all OpenShift vars here: | |
# https://www.openshift.com/developers/openshift-environment-variables | |
# In settings.php you can leverage the enviroment variables like this: | |
# // Define env vars. | |
# if (array_key_exists('OPENSHIFT_APP_NAME', $_SERVER)) { | |
# $src = $_SERVER; | |
# } else { | |
# $src = $_ENV; | |
# } | |
# | |
# $conf["file_private_path"] = $src['OPENSHIFT_DATA_DIR'] . "private"; | |
# $conf["file_temporary_path"] = $src['OPENSHIFT_DATA_DIR'] . "tmp"; | |
#### | |
# Start Deploy | |
echo "Starting Deploy..." | |
# Let's create the drupal files directory in the Openshift data folder ($OPENSHIFT_DATA_DIR). | |
echo "Check for the files directory, if not created - create it" | |
if [ ! -d ${OPENSHIFT_DATA_DIR}sites/default/files ]; then | |
mkdir -p ${OPENSHIFT_DATA_DIR}sites/default/files | |
echo "Done creating files directory" | |
else | |
echo "The files directory already exists" | |
fi | |
#### | |
echo "Check for the private directory, if not created - create it" | |
if [ ! -d ${OPENSHIFT_DATA_DIR}private ]; then | |
mkdir -p ${OPENSHIFT_DATA_DIR}private | |
echo "Done creating private directory" | |
else | |
echo "The private directory already exists" | |
fi | |
#### | |
echo "Check for the tmp directory, if not created - create it" | |
if [ ! -d ${OPENSHIFT_DATA_DIR}tmp ]; then | |
mkdir -p ${OPENSHIFT_DATA_DIR}tmp | |
echo "Done creating tmp directory" | |
else | |
echo "The tmp directory already exists" | |
fi | |
#### | |
# Set permissions on the files directory. | |
echo "Now chmod 777 -R files and private" | |
chmod -R 777 ${OPENSHIFT_DATA_DIR}sites/default/files | |
chmod -R 777 ${OPENSHIFT_DATA_DIR}private | |
chmod -R 777 ${OPENSHIFT_DATA_DIR}tmp | |
echo "chmod done, permissions set to 777" | |
#### | |
# Symlink our files folder to the repo. | |
# Note the "php" directory below seems to be the best way to serve OpenShift files. | |
# This is good as that allows us for directories one level above such as tmp and private | |
echo "Create sym links for writeable directories" | |
ln -sf ${OPENSHIFT_DATA_DIR}sites/default/files ${OPENSHIFT_REPO_DIR}php/sites/default | |
echo "Files sym links created" | |
#### | |
# Copy default.settings.php from the repo, rename it and place it in the data directory. | |
# if it's there already, skip it. | |
if [ ! -f ${OPENSHIFT_DATA_DIR}sites/default/settings.php ]; | |
then | |
cp ${OPENSHIFT_REPO_DIR}php/sites/default/default.settings.php ${OPENSHIFT_DATA_DIR}sites/default/settings.php | |
echo "settings.php copied." | |
else | |
echo "Looks like the settings.php file is already there, we won't overwrite it." | |
fi | |
#### | |
# symlink the settings.php file. | |
echo "Create sym link for settings.php" | |
ln -sf ${OPENSHIFT_DATA_DIR}sites/default/settings.php ${OPENSHIFT_REPO_DIR}php/sites/default/settings.php | |
echo "settings.php symlink created" | |
#### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## sample output from above on git push | |
Pushing to ssh://[app_id]@apptest-example.rhcloud.com/~/git/apptest.git/ | |
Counting objects: 9, done. | |
Delta compression using up to 8 threads. | |
Compressing objects: 100% (5/5), done. | |
Writing objects: 100% (5/5), 903 bytes | 0 bytes/s, done. | |
Total 5 (delta 2), reused 0 (delta 0) | |
remote: Stopping PHP 5.4 cartridge (Apache+mod_php) | |
remote: Waiting for stop to finish | |
remote: Waiting for stop to finish | |
remote: Syncing git content to other proxy gears | |
remote: Building git ref 'master', commit 0d85512 | |
remote: Checking .openshift/pear.txt for PEAR dependency... | |
remote: Preparing build for deployment | |
remote: Activating deployment | |
remote: HAProxy already running | |
remote: HAProxy instance is started | |
remote: check for files directory, if not created - create it | |
remote: Done creating directories | |
remote: Now chmod 777 -R files. | |
remote: chmod done | |
remote: create sym links for writeable directories | |
remote: files sym links created! | |
remote: Looks like the settings.php file is already there, we won't overwrite it. | |
remote: create sym link for settings.php | |
remote: settings.php symlink created. | |
remote: Starting PHP 5.4 cartridge (Apache+mod_php) | |
remote: Application directory "php/" selected as DocumentRoot | |
remote: ------------------------- | |
remote: Git Post-Receive Result: success | |
remote: Activation status: success | |
remote: Deployment completed with status: success | |
To to ssh://[app_id]@apptest-example.rhcloud.com/~/git/apptest.git/ | |
f9428f0..0d85512 master -> master | |
updating local tracking ref 'refs/remotes/origin/master' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment