Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Magic Beans - Deploying Django on Elastic Beans...
Search
Seb
September 11, 2014
Technology
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Magic Beans - Deploying Django on Elastic Beanstalk
Seb
September 11, 2014
Transcript
37 slides
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
More Decks by Seb
See All by Seb
Double Click - Continue Building Better CLIs
elbaschid
0
510
I Can Be A Speaker, So Can You
elbaschid
0
350
Click - PyCaribbean 2017 - Puerto Rico
elbaschid
0
480
Conferencing - Engineering Meeting
elbaschid
1
59
Show & Tell - PyCon US 2016 Summary
elbaschid
1
120
Click: A Pleasure To Write, A Pleasure To Use
elbaschid
0
710
Hunting for Treasure in Django
elbaschid
1
760
Moby & The Beanstalk
elbaschid
1
570
Docker In Production - A War Story
elbaschid
1
330
Other Decks in Technology
See All in Technology
gem install とrequire のむこうがわ
ydah
0
110
Biohub - Cell Tracking During Development 5th place solution
rist
0
160
速くなるほど、深く考える AI時代のQAに学ぶ
kobayashiyorimitsu
0
240
Quick Automate | 目指せ Quick マスター 12
inariku
PRO
1
120
閉域網でのAPI公開の選択肢全部比較!
takano0131
2
320
AIで実装が加速したのに、 なぜ私は仕事の大半で人と話し続けていたのか?
say_no_w
0
120
Sonnetだけで業務はまわる?
kintotechdev
1
130
「AIチャットからもできないの?」と言われたら ~業務アプリをMCP対応するときの認証・認可の勘所
oidfj
0
350
「任されビリティ」で引き受けて「よしなりてぃ」に頼らず任せる / Accept tasks with "makasarebility" and hand them over without relying on "yoshinarily"
pauli
1
680
Datadog の権限統制 〜Org 統合に向けて調べた注意点 / JDDUG-Meetup_24
visional_engineering_and_design
1
160
仕様と現実の間で落とし所を探るリモートMCPの認証・認可 — Sansanの認証基盤における課題と実践
sansantech
PRO
2
330
Where Should Platform Complexity Live? Lessons from a Cross-Team PR Preview Platform
taiki45
0
110
Featured
See All Featured
The SEO Collaboration Effect
kristinabergwall1
1
620
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Deep Space Network (abreviated)
tonyrice
0
420
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
280
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
600
Typedesign – Prime Four
hannesfritz
42
3.2k
The Invisible Side of Design
smashingmag
301
52k
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Writing Fast Ruby
sferik
630
63k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k