Skip to content

Commit f963bdc

Browse files
committed
Sample for deployment of Python application to EC2 using Amazon
CodeDeploy
1 parent 8e1252d commit f963bdc

15 files changed

Lines changed: 169 additions & 2 deletions

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.ve/
2+
coverage/
3+
.*.swp
4+
*.pyc

‎.gitmodules‎

Whitespace-only changes.

‎README.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
# sample-python-codedeploy
2-
Sample project showing how to continuously deploy to AWS using codedeploy.
1+
sample-python-codedeploy
2+
========================
3+
4+
This sample demonstrates how to setup continuous integration and deployment for a Python project deployed to Amazon EC2 using Amazon CodeDeploy service.
5+
6+
For more detailed documentation, please see Shippable's continuous deployment section. http://docs.shippable.com/en/latest/config.html#continuous-deployment
7+
8+
This sample is built for Shippable, a docker based continuous integration and deployment platform.

‎app.wsgi‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
sys.path.insert(0, '/home/ec2-user/sample-app')
3+
4+
from application import application

‎application.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import flask
3+
4+
application = flask.Flask(__name__)
5+
application.debug = True
6+
7+
@application.route('/')
8+
def hello_world():
9+
storage = Storage()
10+
storage.populate()
11+
score = storage.score()
12+
return "Hello world, %d!" % score
13+
14+
class Storage():
15+
def __init__(self):
16+
self.db = dict()
17+
18+
def populate(self):
19+
self.db['score'] = 1234
20+
21+
def score(self):
22+
return self.db['score']
23+
24+
if __name__ == "__main__":
25+
application.run(host='0.0.0.0')

‎appspec.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 0.0
2+
os: linux
3+
files:
4+
- source: /app.wsgi
5+
destination: /var/www/sample-app
6+
- source: /
7+
destination: /home/ec2-user/sample-app
8+
- source: /conf/sample_app.conf
9+
destination: /etc/httpd/conf.d
10+
hooks:
11+
AfterInstall:
12+
- location: scripts/install_dependencies
13+
timeout: 300
14+
runas: root
15+
ApplicationStart:
16+
- location: scripts/start_server
17+
timeout: 300
18+
runas: root
19+
ApplicationStop:
20+
- location: scripts/stop_server
21+
timeout: 300
22+
runas: root

‎conf/sample_app.conf‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WSGISocketPrefix /var/run/wsgi
2+
3+
<VirtualHost *>
4+
WSGIDaemonProcess sample_app user=ec2-user group=ec2-user threads=5
5+
WSGIScriptAlias / /var/www/sample-app/app.wsgi
6+
7+
<Directory /var/www/sample-app>
8+
WSGIProcessGroup sample_app
9+
WSGIApplicationGroup %{GLOBAL}
10+
Order deny,allow
11+
Allow from all
12+
</Directory>
13+
</VirtualHost>

‎config.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
branch-defaults:
2+
master:
3+
environment: sample-python-env
4+
global:
5+
application_name: sample-python
6+
default_region: us-west-2
7+
profile: eb-cli
8+
sc: git

‎requirements.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nose
2+
coverage
3+
Flask

‎scripts/install_dependencies‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
yum install -y httpd mod_wsgi.x86_64
3+
easy_install pip
4+
pip install -r /home/ec2-user/sample-app/requirements.txt

0 commit comments

Comments
 (0)