0

I have made a post-receive hook on a git repository to my server:

#!/bin/bash

echo "Deploy to server"

tempdir="/home/pcmagas/deploy/master"

if [[ ! -d $tempdir ]]; then
    echo -e "\tCreating branch dir: ${tempdir}"
    mkdir -p ${tempdir}
fi

# Locally deploy code

echo -e "\tCleaning..."
git --work-tree=${tempdir} clean -fd master -- .
echo -e "\tPushing To temporary directory..."
git --work-tree=${tempdir} checkout -f master -- .
chmod 775 ${tempdir} -R


echo "Installing 3rd party libraries"
cd ${tempdir}
composer install
#mkdir ${tempdir}/var/cache/prod
#bower install
#npm install gulp gulp-util gulp-rename gulp-uglify
#gulp prod

echo "Setting Up Database Changes"

export OPENSHIFT_POSTGRESQL_DB_HOST=localhost 
export OPENSHIFT_POSTGRESQL_DB_PORT=5432
export OPENSHIFT_APP_NAME=symphotest
export OPENSHIFT_POSTGRESQL_DB_USERNAME=symphotest
export OPENSHIFT_POSTGRESQL_DB_PASSWORD=samplepasswd


php bin/console doctrine:database:create --if-not-exists

php bin/console doctrine:generate:entity AppBundle
php bin/console doctrine:schema:update --force

#echo "Moving to server"
#rsync -rav  --delete --progress -T /tmp --exclude-from=${tempdir}/exclude.txt --chown "www-data" ${tempdir}/ /home/www/syphotest/htdocs/ > ~/logs.txt

#echo "Fixing Permissions"
#sudo chown -R www-data:www-data /home/www/syphotest/htdocs/*
#sudo chmod +w /home/www/syphotest/htdocs/var/cache/prod
#sudo chown www-data:www-data /home/www/syphotest/htdocs/var/cache/prod
#sudo chown www-data:www-data /home/www/syphotest/htdocs/var/logs
#sudo chown www-data:www-data /home/www/syphotest/htdocs/app/

But when the script runs these commands it fails to generate the tables:

php bin/console doctrine:database:create --if-not-exists

php bin/console doctrine:generate:entity AppBundle
php bin/console doctrine:schema:update --force

The config.yml is:

imports:
    - { resource: params.php }
    - { resource: security.yml }
    - { resource: services.yml }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: en

framework:
    #esi:             ~
    #translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
        handler_id:  session.handler.native_file
        save_path:   "%kernel.root_dir%/sessions/%kernel.environment%"
    fragments:       ~
    http_method_override: true
    assets: ~

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

And the parameters for the connection are:

<?php
  $container->setParameter('secret','samplesecret');

  // Db Parameters
  $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"));

  //mailer_host
  $container->setParameter('mailer_transport', 'smtp');
  $container->setParameter('mailer_host', '127.0.0.1');
  $container->setParameter('mailer_user', null);
  $container->setParameter('mailer_password', null);
?>

On my script I managed to export the enviroment variables:

export OPENSHIFT_POSTGRESQL_DB_HOST=localhost 
export OPENSHIFT_POSTGRESQL_DB_PORT=5432
export OPENSHIFT_APP_NAME=symphotest
export OPENSHIFT_POSTGRESQL_DB_USERNAME=symphotest
export OPENSHIFT_POSTGRESQL_DB_PASSWORD=samplepasswd

But somehow it fails to use them and I get the following errors:

  [Doctrine\DBAL\Exception\ConnectionException]                                          
  An exception occured in driver: SQLSTATE[08006] [7] fe_sendauth: no password supplied  



  [Doctrine\DBAL\Driver\PDOException]                    
  SQLSTATE[08006] [7] fe_sendauth: no password supplied  



  [PDOException]                                         
  SQLSTATE[08006] [7] fe_sendauth: no password supplied  


doctrine:database:create [--connection [CONNECTION]] [--if-not-exists] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>



  [Symfony\Component\Console\Exception\RuntimeException]  
  Too many arguments.                                     


doctrine:generate:entity [--entity ENTITY] [--fields FIELDS] [--format FORMAT] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>



  [Doctrine\DBAL\Exception\ConnectionException]                                          
  An exception occured in driver: SQLSTATE[08006] [7] fe_sendauth: no password supplied  



  [Doctrine\DBAL\Driver\PDOException]                    
  SQLSTATE[08006] [7] fe_sendauth: no password supplied  



  [PDOException]                                         
  SQLSTATE[08006] [7] fe_sendauth: no password supplied  


doctrine:schema:update [--complete] [--dump-sql] [-f|--force] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

My postgresql configuration is (/etc/postgresql/9.3/main/pg_hba.conf):

# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             localhost            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

Please I need you help. For some reason it cannot find the password. I do not know the solution to the problem.

2 Answers 2

1

Based on this answer it seems to be, that PHP does not provide dynamically created variables to be used with getenv.

I would try to predefine the variables with some default values and only overwrite them in your script.

Sign up to request clarification or add additional context in comments.

1 Comment

I made a scrit with hardcoded credentials ans still cannot fix the db. The irony is when post-recieve is executed by hand on the server database id updated sucessfully.
0

RenameMoce the post_receive hook as an idepedent script in the hooks folder and run it manually.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.