Last active
February 27, 2016 00:51
-
-
Save silvioq/9601033 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 [ q$ENG == qmysql ]; 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 | |
Hola @SergioEnrique ... retomé algunos trabajos con OpenShift y vi este mensaje de hace más de un año ... lamentablemente, no me había aparecido la notificación ... Ya cambié
if [ $ENG == mysql ];
por
if [ q$ENG == qmysql ];
que es lo correcto, tal cual como me decís.
Espero que te haya servido este script, saludos y gracias por la data!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
En la línea 104 -> if [ $ENG == mysql ]; then
Parece que tiene un error, pues elegí mysql y me creó PostgreSQL
la variable $ENG contenía "mysql" correctamente porque me creó el archivo /app/config/mysql-params.php pero con los datos de configuración de PostgreSQL.
No sé si se tenga que poner entre comillas u otra cosa para que detecte la condición correctamente
Actualizo:
Estaba ocupando el comando sh, el cual no detecta muchos comandos, sin embargo es bueno tenerlo en cuenta, por lo tanto la línea corregida para que siempre funcione sería:
Línea 104: