How can I composer update on OpenShift?

2019-05-18 00:46发布

问题:

I am trying to use Slim on OpenShift with a free node. I can run composer update from the SSH sessions without any problem.

The only problem is every time I want to commit files through git I have to go to the console and run composer install again. My question is there is any easy way to workaround this? I tried a BASH script in /project/.openshift/action_hooks/post_deploy but the server is not creating the vendor folder under runtime/repo

回答1:

I always do it via action hooks:

Inside my project directory I have a script called by /project/.openshift/action_hooks/post_deploy where post_deploy is a bash script. Here goes what I have been using:

#!/bin/bash

export MY_PHPCOMPOSER=$OPENSHIFT_DATA_DIR/composer.phar

# if composer not exists, download
if [ ! -f $MY_PHPCOMPOSER ]; then
    cd $OPENSHIFT_DATA_DIR
    echo "Downloading composer..."
    php -r "readfile('https://getcomposer.org/installer');" | php 
fi

$MY_PHPCOMPOSER -n -q self-update
cd $OPENSHIFT_REPO_DIR 
# install
php -dmemory_limit=1G $MY_PHPCOMPOSER install

So post_deploy script will perform every time which you push your repo to openshit. It work like a charm!

Side note

Since not always the OpenShift composer's version is updated it's safe to download a new composer copy and use it. Also, don't forget adjusting permissions settings.

Helpful links

  • Openshift builds
  • Openshift Default Build Lifecycle


回答2:

I know that my answer is late but according to the Openshift documentation you can enable composer install after each build by just creating a marker file:

touch .openshift/markers/use_composer