Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Magic Beans - Deploying Django on Elastic Beans...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Seb
September 11, 2014
Technology
90
0
Share
Magic Beans - Deploying Django on Elastic Beanstalk
Seb
September 11, 2014
More Decks by Seb
See All by Seb
Double Click - Continue Building Better CLIs
elbaschid
0
480
I Can Be A Speaker, So Can You
elbaschid
0
320
Click - PyCaribbean 2017 - Puerto Rico
elbaschid
0
460
Conferencing - Engineering Meeting
elbaschid
1
48
Show & Tell - PyCon US 2016 Summary
elbaschid
1
110
Click: A Pleasure To Write, A Pleasure To Use
elbaschid
0
680
Hunting for Treasure in Django
elbaschid
1
720
Moby & The Beanstalk
elbaschid
1
530
Docker In Production - A War Story
elbaschid
1
320
Other Decks in Technology
See All in Technology
Fabric MCPの紹介と使い分け
ryomaru0825
1
130
自動テストだけで リリース判断できるチームへ - 鍵はテストの量ではなくリリース判断基準の再設計にあった / Redesigning Release Criteria for Lightweight Releases
ewa
7
3.4k
もっとコンテンツをよく構造化して理解したいので、LLM 時代こそ Taxonomy の設計品質に目を向けたい〜!
morinota
0
190
音声言語モデル手法に関する発表の紹介
kzinmr
0
160
AIと乗り切った1,500ページ超のヘルプサイト基盤刷新とさらにその先の話
mugi_uno
2
300
Agent の「自由」と「安全」〜未来に向けて今できること〜
katayan
0
340
大学職員のための生成AI最前線 :最前線を、AIガバナンスとして読み直すためのTips
gmoriki
2
3.6k
Oracle Cloud Infrastructure:2026年4月度サービス・アップデート
oracle4engineer
PRO
0
340
AIが盛んな時代に 技術記事を書き始めて起きた私の中での小さな変化
peintangos
0
360
Sociotechnical Architecture Reviews: Understanding Teams, not just Artefacts
ewolff
1
130
古今東西SRE
okaru
1
130
サービスの信頼性を高めるため、形骸化した「プロダクションミーティング」を立て直すまでの取り組み
stefafafan
1
240
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
120
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
110
Done Done
chrislema
186
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.3k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
380
Documentation Writing (for coders)
carmenintech
77
5.3k
Code Reviewing Like a Champion
maltzj
528
40k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Statistics for Hackers
jakevdp
799
230k
Transcript
Magic Beans Deploying Django on Elastic Beanstalk with Docker Sebastian
Vetter @elbaschid github.com/elbaschid
For those who don't know me • Sebastian Vetter •
Backend Developer @ Snowball One • You can find me on: • twitter: @elbaschid • github: github.com/elbaschid
Deploying Websites Can Be Ugly
Deploying Websites Can Be Ugly 1. Set up server infrastructure.
2. Develop a magical application. 3. Use continuous integration, e.g. Travis 4. On success, manually deploy via scripts
Let's try and make it more beautiful
And we'll use beans for that
Not This One!
That's better!
AWS Elastic Beanstalk (EB) • Amazon's PaaS solution • Heroku-style
deployments • Combines various parts of AWS And now with Docker support
EB Architecture (I)
EB Architecture (II)
Elastic Beanstalk Console (I)
Elastic Beanstalk Console (II)
What is Docker?
What is Docker? • Isolated processes in userspace • Immutable
containers • Lightweight images • Git-style container distribution • More on https://www.docker.com/ whatisdocker/
Let's look at the magic
The ideal solution ...
... was a failure!
The new approach
The main steps 1. Push to github 2. Triggers a
test build on Travis 3. On success: 1. Create deployment artefact 2. Store in S3 3. Beanstalk creates Docker container 4. Deploy to EC2
How it works
Options to run/deploy a docker container on EB. • Using
Dockerrun.aws.json to pull from docker registry • Using Dockerfile to build on the EC2 instance • Using zip archive including both files + more
The build artefact my-magic-app.zip + Dockerfile + Dockerrun.aws.json + scripts/
+ .ebextensions/ ....
Dockerfile FROM stackbrew/ubuntu:14.04 RUN apt-get -qq update && \ apt-get
install -y -q all-the-things && \ curl https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py && \ python /tmp/get-pip.py ADD www /app/ WORKDIR /app RUN pip install -r deploy/requirements/test.txt EXPOSE 8000 VOLUME ['/var/log'] ADD scripts/start.sh /app/start.sh CMD /app/start.sh
Dockerrun.aws.json { "AWSEBDockerrunVersion": "1", "Volumes": [ { "HostDirectory": "/var/log/my-app", "ContainerDirectory":
"/var/log" } ], "Ports": [ { "ContainerPort": "8000" } ], "Logging": "/var/log" }
Setting up Travis to release docker image on success. •
Run the full test suite • After success, build the Docker container • Deploy the new container incl. static files
After successful tests after_success: - cd .. - ./scripts/deploy_to_beanstalk.sh
Putting the magic into beans • No easy to use
deployment scripts from Amazon • eb: useless and broken • awscli: easy to setup but lots of cli flags
It's Roll-Your-Own Time • Small script beanstalk • Uses beans.yml
for configuration • Inspired by tools like fig
Settings in beans.yml app_name: my-eb-app bucket_name: my-s3-bucket my-app-env: environment: AWS_ACCESS_KEY_ID:
AWS_SECRET_KEY: DJANGO_SECRET_KEY: DJANGO_DATABASE_HOST: <RDS host> DJANGO_DATABASE_PORT: <RDS port> DJANGO_DATABASE_NAME: <RDS DB name DJANGO_CONFIGURATION: Test settings: 'command': Timeout: 1000
Using Beansstalk $ python beanstalk.py create_archive <version> $ python beanstalk.py
release <version> $ python beanstalk.py deploy <env> <version> As an example: export RELEASE_VERSION=$TRAVIS_JOB_ID-$GIT_COMMIT $ python beanstalk.py create_archive ${RELEASE_VERSION} $ python beanstalk.py release ${RELEASE_VERSION} $ python beanstalk.py deploy my-app-env ${RELEASE_VERSION}
Versioning and deployment to EB environment. • Semantic versioning doesn't
work in CD (<major>.<minor>.<patch>) • How to generate meaningful versions?
What we do: • Use the Travis Job ID •
And the git commit GIT_COMMIT=$(git rev-parse --short HEAD) RELEASE_VERSION=$TRAVIS_JOB_$GIT_COMMIT
Running the Docker container #!/bin/bash set -e python manage.py migrate
/usr/local/bin/uwsgi --http :8000 \ --wsgi-file deploy/wsgi/test.py \ --logto /var/log/uwsgi.log
Ideas and improvements • Building docker images on Travis CI
and alternatives (Circle CI, Wercker). • Running browser tests against the production container instead of live server testcase. • Handling migrations in continiuous deployment. • Deploying with zero downtime.
Looks great from up here
But still not Paradise