Skip to content

Commit f6fcc6c

Browse files
authored
Merge pull request sclorg#145 from pkubatrh/app_home
Add APP_HOME variable to set the application's location when needed
2 parents c4e5f98 + 4dec209 commit f6fcc6c

32 files changed

Lines changed: 96 additions & 32 deletions

File tree

2.7/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ a `.s2i/environment` file inside your source code repository.
115115
can be read from there. For an example, see
116116
[setup-test-app](https://github.com/openshift/s2i-python/tree/master/2.7/test/setup-test-app).
117117
118+
* **APP_HOME**
119+
120+
This variable can be used to specify a sub-directory in which the application to be run is contained.
121+
The directory pointed to by this variable needs to contain `wsgi.py` (for Gunicorn) or `manage.py` (for Django).
122+
123+
If `APP_HOME` is not provided, the `assemble` and `run` scripts will use the application's root
124+
directory.
125+
118126
* **APP_CONFIG**
119127
120128
Path to a valid Python file with a

2.7/s2i/bin/assemble

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ if should_collectstatic; then
2828
(
2929
echo "---> Collecting Django static files ..."
3030

31-
# Find shallowest manage.py script, either ./manage.py or <project>/manage.py
32-
manage_file=$(find . -maxdepth 2 -type f -name 'manage.py' -printf '%d\t%P\n' | sort -nk1 | cut -f2 | head -1)
31+
32+
APP_HOME=${APP_HOME:-.}
33+
# Look for 'manage.py' in the directory specified by APP_HOME, or the current directory
34+
manage_file=$APP_HOME/manage.py
3335

3436
if [[ ! -f "$manage_file" ]]; then
3537
echo "WARNING: seems that you're using Django, but we could not find a 'manage.py' file."

2.7/s2i/bin/run

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ else
4141
test -n "$app_file_check" && (>&2 echo "ERROR: file '$app_file_check' not found.") && exit 1
4242
fi
4343

44-
# Find shallowest manage.py script, either ./manage.py or <project>/manage.py
45-
manage_file=$(find . -maxdepth 2 -type f -name 'manage.py' -printf '%d\t%P\n' | sort -nk1 | cut -f2 | head -1)
44+
APP_HOME=${APP_HOME:-.}
45+
# Look for 'manage.py' in the directory specified by APP_HOME, or the current direcotry
46+
manage_file=$APP_HOME/manage.py
4647

4748
if should_migrate; then
4849
if [[ -f "$manage_file" ]]; then
@@ -56,9 +57,9 @@ fi
5657

5758
if is_gunicorn_installed; then
5859
if [[ -z "$APP_MODULE" ]]; then
59-
# Find shallowest wsgi.py file, one of ./wsgi.py, <project>/wsgi.py or <project>/<project>/wsgi.py,
60-
# replace "/" with "." and remove ".py" suffix
61-
APP_MODULE=$(find . -maxdepth 3 -type f -name 'wsgi.py' -printf '%d\t%P\n' | sort -nk1 | cut -f2 | head -1 | sed 's:/:.:;s:.py$::')
60+
# Look only in the directory specified by APP_HOME, or the current directory
61+
# replace all "/" with ".", remove leading "." and ".py" suffix
62+
APP_MODULE=$(find $APP_HOME -maxdepth 1 -type f -name 'wsgi.py' | sed 's:/:.:g;s:^\.\+::;s:\.py$::')
6263
fi
6364

6465
if [[ -z "$APP_MODULE" && -f setup.py ]]; then
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_HOME=project

2.7/test/app-home-test-app/project/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def application(environ, start_response):
2+
start_response('200 OK', [('Content-Type','text/plain')])
3+
return [b"Hello World from app-home WSGI application!"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gunicorn

2.7/test/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
IMAGE_NAME=${IMAGE_NAME:-openshift/python-27-centos7-candidate}
1010

11-
declare -a WEB_APPS=({standalone,setup,django,numpy}-test-app)
11+
declare -a WEB_APPS=({standalone,setup,django,numpy,app-home}-test-app)
1212

1313
# TODO: Make command compatible for Mac users
1414
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"

3.3/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ file inside your source code repository.
115115
can be read from there. For an example, see
116116
[setup-test-app](https://github.com/openshift/s2i-python/tree/master/3.3/test/setup-test-app).
117117
118+
* **APP_HOME**
119+
120+
This variable can be used to specify a sub-directory in which the application to be run is contained.
121+
The directory pointed to by this variable needs to contain `wsgi.py` (for Gunicorn) or `manage.py` (for Django).
122+
123+
If `APP_HOME` is not provided, the `assemble` and `run` scripts will use the application's root
124+
directory.
125+
118126
* **APP_CONFIG**
119127
120128
Path to a valid Python file with a

3.3/s2i/bin/assemble

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ if should_collectstatic; then
3232
(
3333
echo "---> Collecting Django static files ..."
3434

35-
# Find shallowest manage.py script, either ./manage.py or <project>/manage.py
36-
manage_file=$(find . -maxdepth 2 -type f -name 'manage.py' -printf '%d\t%P\n' | sort -nk1 | cut -f2 | head -1)
35+
36+
APP_HOME=${APP_HOME:-.}
37+
# Look for 'manage.py' in the directory specified by APP_HOME, or the current directory
38+
manage_file=$APP_HOME/manage.py
3739

3840
if [[ ! -f "$manage_file" ]]; then
3941
echo "WARNING: seems that you're using Django, but we could not find a 'manage.py' file."

0 commit comments

Comments
 (0)