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
Seb
September 11, 2014
Technology
0
75
Magic Beans - Deploying Django on Elastic Beanstalk
Seb
September 11, 2014
Tweet
Share
More Decks by Seb
See All by Seb
Double Click - Continue Building Better CLIs
elbaschid
0
430
I Can Be A Speaker, So Can You
elbaschid
0
290
Click - PyCaribbean 2017 - Puerto Rico
elbaschid
0
420
Conferencing - Engineering Meeting
elbaschid
1
44
Show & Tell - PyCon US 2016 Summary
elbaschid
1
99
Click: A Pleasure To Write, A Pleasure To Use
elbaschid
0
610
Hunting for Treasure in Django
elbaschid
1
650
Moby & The Beanstalk
elbaschid
1
490
Docker In Production - A War Story
elbaschid
1
310
Other Decks in Technology
See All in Technology
3D生成AIのための画像生成
kosukeito
2
580
Winning at PHP in Production in 2025
beberlei
1
260
OpsJAWS34_CloudTrailLake_for_Organizations
hiashisan
0
240
30代からでも遅くない! 内製開発の世界に飛び込み、最前線で戦うLLMアプリ開発エンジニアになろう
minorun365
PRO
16
5k
白金鉱業Meetup_Vol.18_AIエージェント時代のUI/UX設計
brainpadpr
1
270
Gateway H2 モジュールで スマートホーム入門
minoruinachi
0
120
Как мы автоматизировали интеграционное тестирование с Gonkey и не пожалели. Паша Егорычев, Кирилл Поляков
lamodatech
0
1.4k
Simplify! 10 ways to reduce complexity in software development
ufried
1
160
より良い開発者体験を実現するために~開発初心者が感じた生成AIの可能性~
masakiokuda
0
230
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
220
バクラクの認証基盤の成長と現在地 / bakuraku-authn-platform
convto
4
880
Computer Use〜OpenAIとAnthropicの比較と将来の展望〜
pharma_x_tech
6
930
Featured
See All Featured
Visualization
eitanlees
146
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
770
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
178
53k
Why Our Code Smells
bkeepers
PRO
336
57k
Typedesign – Prime Four
hannesfritz
41
2.6k
It's Worth the Effort
3n
184
28k
For a Future-Friendly Web
brad_frost
177
9.7k
GitHub's CSS Performance
jonrohan
1030
460k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
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