Forums

git push post-receive hook ... resulting in apps not ready.

All,

I'm trying to get git push working.. following the guidance at https://blog.pythonanywhere.com/87/

The main difference is that I have several of the settings stored as environment variables within a virualenv, and thus I need to start the virtualenv before the remainder of the hook proceeds. When I do a push to python anywhere the remote is returning django.core.exception.AppRegistryNotReady.

The issue is that the Virtualenv doesn't seem to be loading.. When I run the post-receive hook manually with the vitualenv activate everything runs fine.. Anyone know the correct syntax, to start the virualenv in the current shell from a bash script ?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#!/bin/bash

set -e # Exit if anything fails

# activate virtualenv to load needed env variables
source /home/nzimpfer/.virtualenvs/metadata-catalog/bin/activate

# Checkout new code in git repo
mkdir -p /var/www/sites/MBP-MetadataCatalog
GIT_WORK_TREE=/var/www/sites/MBP-MetadataCatalog git checkout --force

just to confirm, is that a portion of code in your ~/bare-repos/mysite.git/hooks/post-receive file?

by the way- here is our recommended way of dealing with environment variables

yes.. that is a portion of the post-receive file..

Hmm.. The link provides some additional insight.. I will implement that and see if that resolves the issue. Thanks.

Tried replacing source with dot?

. /home/nzimpfer/.virtualenvs/metadata-catalog/bin/activate

dot is not valid in that context

This worked for me:

1
2
3
4
5
6
7
#!/bin/bash
set -e
GIT_WORK_TREE=/home/me/mysite git checkout -f
cd ~
. .virtualenvs/my-virtualenv/bin/
python manage.py collectstatic --noinput
touch /var/www/me_eu_pythonanywhere_com_wsgi.py

The dot did work as microprediction suggested.

Notice I had to use --noinput instead of -y

Make sure the post-receive is executable too:

chmod ug+x post-receive

Thanks! That's a useful update. You and microprediction are right, . is entirely valid there.