Sunday 8 November 2020

How to set up Gcloud Flex Environment custom container pylibmc

I am trying to set up memcached for my application. Locally it works just fine.

Now time to deploy to a real server, I am using Google cloud app engine flex environment.

It's a custom runtime. I am able to install my app just fine, but when it comes time to running, I get a 500 for views that I use Memcached.

My first thinking is because of the caches settings:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
        'LOCATION': '127.0.0.1:11211',
  }

I am thinking it has something to do with this location setting. Being that this '127.0.0.1:11211' works for a local environment, how do I setup a location for gcloud custom runtime flex environment?

If that's not why I am getting the 500, what could be the better setup. Here is my docker file:

FROM python:3.8

EXPOSE 8080

RUN apt-get update && apt-get install  --reinstall -y \
  binutils \
  libproj-dev \
  libmemcached11 \
  libmemcachedutil2 \
  libmemcached-dev \
  libz-dev

ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

ADD . .

# Run a WSGI server to serve the application. gunicorn must be declared as
CMD exec gunicorn --bind :8080 --workers 1 --threads 8 main:app --timeout 0 --preload

and app.yaml file:

runtime: custom

# the PROJECT-DIRECTORY is the one with settings.py and wsgi.py
entrypoint: gunicorn -b :8080 app.wsgi
#entrypoint: gunicorn -b :$PORT app.wsgi 
env: flex # for Google Cloud Flexible App Engine

# any environment variables you want to pass to your application.
# accessible through os.environ['VARIABLE_NAME']
env_variables:
  DEBUG: 'False' # always False for deployment
  ....
  STATIC_URL: 'https://storage.googleapis.cd...' you sync static files to
  

beta_settings:
# from command >> gcloud sql instances describe DATABASE-NAME <<
  cloud_sql_instances: apppp-instance

handlers:
- url: /.*
  script: auto
  secure: always

automatic_scaling:
  min_num_instances: 1
  max_num_instances: 4

runtime_config:
  python_version: 3

enter image description here



from How to set up Gcloud Flex Environment custom container pylibmc

No comments:

Post a Comment