dimanche 28 décembre 2014

AWS Elastic Beanstalk + uWSGI

I am trying to deploy a Python 3.4.2, Django 1.7 application using a Docker container with AWS Elastic Beanstalk. I am running uWSGI in the container to serve my application's dynamic content. Static content should be served from Amazon S3.


Everything seems (to me, anyways) to be configured correctly, and my error logs don't report anything, but when I upload my application the Health Check returns RED and when I navigate to my-app.elasticbeanstalk.com the page is entirely white. Running cURl on the url returns nothing, as well.


Elastic Beanstalk's /var/log/nginx/access.log contains the following lines over and over again



172.31.22.11 - - [29/Dec/2014:07:01:17 +0000] "GET //vitrufitness-staging.elasticbeanstalk.com HTTP/1.1" 404 3409 "-" "ELB-HealthChecker/1.0"
172.31.39.129 - - [29/Dec/2014:07:01:17 +0000] "GET //vitrufitness-staging.elasticbeanstalk.com HTTP/1.1" 404 3409 "-" "ELB-HealthChecker/1.0"
172.31.39.129 - - [29/Dec/2014:07:01:28 +0000] "GET //vitrufitness-staging.elasticbeanstalk.com HTTP/1.1" 404 3409 "-" "ELB-HealthChecker/1.0"
172.31.22.11 - - [29/Dec/2014:07:01:38 +0000] "GET //vitrufitness-staging.elasticbeanstalk.com HTTP/1.1" 404 3409 "-" "ELB-HealthChecker/1.0"


I wonder if the problem is due to the ports that I have exposed in my Dockerfile, or the way that I have uWSGI configured.


Here is my uwsgi.ini file (I am running the :docker section). I am not sure if I need to use http:, socket: or http-socket: to work with Elastic Beanstalk. I think Elastic Beanstalk uses Nginx reverse-proxy to serve the container.



[uwsgi]
ini = :base

[docker]
ini = :base
logto = /var/logs/uwsgi.log
http = :8000
socket = :8080
master = true
processes = 4

[base]
chdir = %dapp_dir/
pythonpath = %dapp_dir/
module=my_app.wsgi:application
die-on-term = true
# Set settings module.
env = DJANGO_SETTINGS_MODULE=my_app.settings
chmod-socket=664


Here is my Dockerfile



FROM ubuntu:14.04

# Get most recent apt-get
RUN apt-get -y update

# Install python and other tools
RUN apt-get install -y tar git curl nano wget dialog net-tools build-essential
RUN apt-get install -y python3 python3-dev python-distribute
RUN apt-get install -y nginx supervisor
# Get Python3 version of pip
RUN apt-get -y install python3-setuptools
RUN easy_install3 pip

RUN pip install uwsgi
RUN apt-get -y install libxml2-dev libxslt1-dev

RUN apt-get install -y python-software-properties uwsgi-plugin-python3

# Install GEOS
RUN apt-get -y install binutils libproj-dev gdal-bin

# Install node.js
RUN apt-get install -y nodejs npm

# Install postgresql dependencies
RUN apt-get update && \
apt-get install -y postgresql libpq-dev && \
rm -rf /var/lib/apt/lists

# Install pylibmc dependencies
RUN apt-get update
RUN apt-get install -y libmemcached-dev zlib1g-dev libssl-dev

ADD . /home/docker/code

# Setup config files
RUN ln -s /home/docker/code/supervisor-app.conf /etc/supervisor/conf.d/

RUN pip install -r /home/docker/code/app_dir/requirements.txt

# Create directory for logs
RUN mkdir -p /var/logs
RUN mkdir /static
RUN touch /home/docker/code/app_dir/logfile

# Set environment
ENV PYTHONPATH $PYTHONPATH:/home/docker/code/app_dir
ENV DJANGO_SETTINGS_MODULE my_app.settings

EXPOSE 8000 8080

CMD ["/home/docker/code/start.sh"]


And since I am pulling my docker image from DockerHub, rather than having EB build from the Dockerfile itself, here is my Dockerrun.aws.json file that I need:



{
"AWSEBDockerrunVersion": "1",
"Authentication": {

"Bucket": "my_bucket",
"Key": "docker/dockercfg"
},
"Image": {
"Name": "me/my_image:0.0.1",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8000"
}
],
"Logging": "/var/eb_log"
}




Aucun commentaire:

Enregistrer un commentaire