Created
          March 14, 2015 22:07 
        
      - 
      
- 
        Save Nav-Appaiya/b720ee7254202393d8cb to your computer and use it in GitHub Desktop. 
    This script creates a Gear with symfony in Openshift
  
        
  
    
      This file contains hidden or 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 | |
| read -p "Enter your app name: " APP | |
| if [ q$APP == q ] ; then | |
| echo "No app ... aborting" | |
| exit 1 | |
| fi | |
| read -p "Enter database engine [mysql|pgsql] (mysql): " ENG | |
| if [ q$ENG == q ] ; then | |
| ENG=mysql | |
| fi | |
| case $ENG in | |
| mysql) | |
| ;; | |
| pgsql) | |
| ;; | |
| *) | |
| echo "Invalid database" | |
| exit 1 | |
| esac | |
| cat <<EOF | |
| __________________ | |
| Creating: $APP | |
| Database: $ENG | |
| ------------------ | |
| \\ | |
| \\ | |
| .--. | |
| |o_o | | |
| |:_/ | | |
| // \\ \\ | |
| (| | ) | |
| /'\\_ _/\`\\ | |
| \\___)=(___/ | |
| EOF | |
| rhc create-app -t php-5.4 -a $APP | |
| export APPSSH=`rhc app-show -a $APP | grep SSH | cut -d ":" -f 2 | xargs echo` # Not used, at this moment ... | |
| # Installing | |
| curl -s https://getcomposer.org/installer | php | |
| rm $APP/index.php | |
| ./composer.phar create-project -n symfony/framework-standard-edition ./tmp$APP 2.4.* | |
| mv ./tmp$APP/* ./$APP | |
| mv ./tmp$APP/.[gt]* ./$APP | |
| rmdir tmp$APP | |
| mv composer.phar ./$APP | |
| cd $APP | |
| # Fixing ICU | |
| patch -p0 <<EOF | |
| --- ./composer.json | |
| +++ ./composer.json | |
| @@ -9,6 +9,7 @@ | |
| "require": { | |
| "php": ">=5.3.3", | |
| "symfony/symfony": "~2.4", | |
| + "symfony/icu": "1.1.*", | |
| "doctrine/orm": "~2.2,>=2.2.3", | |
| "doctrine/doctrine-bundle": "~1.2", | |
| "twig/extensions": "~1.0", | |
| EOF | |
| ./composer.phar update -n | |
| # Remove old php | |
| git rm index.php | |
| git commit -m "Delete index.php" | |
| # Installing locally | |
| sudo ln -s `pwd`/web /var/www/$APP | |
| sudo php app/console --env=dev cache:clear | |
| sudo rm app/logs/* | |
| sudo chmod -R a+rw app/cache app/logs | |
| # Add project | |
| git add -A | |
| git commit -m "Starting Symfony Project $APP" | |
| # Hook | |
| echo "Creating hooks" | |
| cat > .openshift/action_hooks/deploy <<EOF | |
| #!/bin/bash | |
| export COMPOSER_HOME="\$OPENSHIFT_DATA_DIR/.composer" | |
| if [ ! -f "\$OPENSHIFT_DATA_DIR/composer.phar" ]; then | |
| curl -s https://getcomposer.org/installer | /usr/bin/php -- --install-dir=\$OPENSHIFT_DATA_DIR | |
| else | |
| /usr/bin/php \$OPENSHIFT_DATA_DIR/composer.phar self-update | |
| fi | |
| unset GIT_DIR | |
| cd \$OPENSHIFT_REPO_DIR | |
| /usr/bin/php \$OPENSHIFT_DATA_DIR/composer.phar install -n --prefer-dist | |
| /usr/bin/php \$OPENSHIFT_REPO_DIR/app/console cache:clear --env=dev | |
| chmod -R 0777 \$OPENSHIFT_REPO_DIR/app/cache | |
| chmod -R 0777 \$OPENSHIFT_REPO_DIR/app/logs | |
| EOF | |
| chmod +x .openshift/action_hooks/deploy | |
| git add .openshift/action_hooks/deploy | |
| git commit -m "Hooking deploy" | |
| # Mysql | |
| if [ $ENG == mysql ]; then | |
| echo "Creating (and parameterizing) MySQL cartridge" | |
| rhc add-cartridge -c mysql-5.5 -a $APP | |
| cat > app/config/$ENG-params.php <<EOF | |
| <?php | |
| \$container->setParameter('database_driver', 'pdo_mysql'); | |
| \$container->setParameter('database_host', getEnv("OPENSHIFT_MYSQL_DB_HOST")); | |
| \$container->setParameter('database_port', getEnv("OPENSHIFT_MYSQL_DB_PORT")); | |
| \$container->setParameter('database_name', getEnv("OPENSHIFT_APP_NAME")); | |
| \$container->setParameter('database_user', getEnv("OPENSHIFT_MYSQL_DB_USERNAME")); | |
| \$container->setParameter('database_password', getEnv("OPENSHIFT_MYSQL_DB_PASSWORD")); | |
| ?> | |
| EOF | |
| else | |
| echo "Creating (and parameterizing) PostgreSQL cartridge" | |
| rhc add-cartridge -c postgresql-9.2 -a $APP | |
| cat > app/config/$ENG-params.php <<EOF | |
| <?php | |
| \$container->setParameter('database_driver', 'pdo_pgsql'); | |
| \$container->setParameter('database_host', getEnv("OPENSHIFT_POSTGRESQL_DB_HOST")); | |
| \$container->setParameter('database_port', getEnv("OPENSHIFT_POSTGRESQL_DB_PORT")); | |
| \$container->setParameter('database_name', getEnv("OPENSHIFT_APP_NAME")); | |
| \$container->setParameter('database_user', getEnv("OPENSHIFT_POSTGRESQL_DB_USERNAME")); | |
| \$container->setParameter('database_password', getEnv("OPENSHIFT_POSTGRESQL_DB_PASSWORD")); | |
| ?> | |
| EOF | |
| fi | |
| patch -p0 <<EOF | |
| --- ./app/config/config.yml | |
| +++ ./app/config/config.yml | |
| @@ -1,6 +1,7 @@ | |
| imports: | |
| - { resource: parameters.yml } | |
| - { resource: security.yml } | |
| + - { resource: $ENG-params.php } | |
| EOF | |
| git add ./app/config/config.yml ./app/config/$ENG-params.php | |
| git commit -m "$ENG params" | |
| # Pushing! | |
| git push | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment