Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit b776908

Browse files
author
Jon Wayne Parrott
committed
Using a virtualenv, fixes #45 (#90)
1 parent a543766 commit b776908

2 files changed

Lines changed: 44 additions & 5 deletions

File tree

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ COPY appengine-compat /opt/appengine-compat
66
# Add the vmruntime
77
COPY appengine-vmruntime /opt/appengine-vmruntime
88

9+
# Create a virtualenv. This virtualenv will contain the compat library,
10+
# vmruntime, and the user's app's dependencies.
11+
RUN virtualenv /env
12+
ENV VIRTUAL_ENV /env
13+
ENV PATH /env/bin:$PATH
14+
915
# Install the compat library and the vmruntime.
1016
RUN pip install --upgrade /opt/appengine-compat /opt/appengine-vmruntime
1117

12-
# Install requirements needed by the default configuration.
18+
# Install the default WSGI server and dependencies.
1319
COPY resources/requirements.txt /opt/requirements.txt
1420
RUN pip install --upgrade -r /opt/requirements.txt
1521

@@ -28,8 +34,8 @@ EXPOSE 8080
2834
# Configure the entrypoint with Managed VMs-essential configuration like "bind",
2935
# but leave the rest up to the config file.
3036
ENTRYPOINT [\
31-
"/usr/bin/env",\
32-
"gunicorn", "-b", ":8080",\
37+
"/env/bin/gunicorn",\
38+
"-b", ":8080",\
3339
"vmruntime.wsgi:meta_app",\
3440
"--log-file=-",\
3541
"-c", "gunicorn.conf.py"]

appengine-compat/setup.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,43 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
#
14+
15+
import os
16+
1517
from setuptools import find_packages
1618
from setuptools import setup
1719

20+
21+
NAMESPACE_DECLARATION = """
22+
try:
23+
__import__('pkg_resources').declare_namespace(__name__)
24+
except ImportError:
25+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
26+
"""
27+
28+
29+
def patch_namespace_package(file):
30+
with open(file, 'r') as f:
31+
contents = f.read()
32+
33+
if NAMESPACE_DECLARATION in contents:
34+
return
35+
36+
with open(file, 'a') as f:
37+
f.write(NAMESPACE_DECLARATION)
38+
39+
# WARNING: GIANT FLAMING LAVA PIT HACK.
40+
# Patch the App Engine SDK's google/__init__.py to force it to be a namespace
41+
# package. Without this, none of the other google namespace packages will work
42+
# (e.g. protobuf).
43+
# To be removed with github issue #91.
44+
patch_namespace_package(os.path.join(
45+
os.path.dirname(__file__),
46+
'exported_appengine_sdk',
47+
'google',
48+
'__init__.py'))
49+
50+
1851
setup(
1952
name='appengine-compat',
2053
version='0.64',
@@ -32,7 +65,7 @@
3265
package_dir={'': 'exported_appengine_sdk'},
3366
include_package_data=True,
3467
packages=find_packages('exported_appengine_sdk', exclude=['lib.*']),
35-
# namespace_packages=['google'], # This skips google/__init__.py
68+
namespace_packages=['google'],
3669
install_requires=[
3770
'requests>=2.5.0',
3871
'webapp2>=2.5.2',

0 commit comments

Comments
 (0)