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
71
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
400
I Can Be A Speaker, So Can You
elbaschid
0
270
Click - PyCaribbean 2017 - Puerto Rico
elbaschid
0
390
Conferencing - Engineering Meeting
elbaschid
1
42
Show & Tell - PyCon US 2016 Summary
elbaschid
1
96
Click: A Pleasure To Write, A Pleasure To Use
elbaschid
0
580
Hunting for Treasure in Django
elbaschid
1
610
Moby & The Beanstalk
elbaschid
1
470
Docker In Production - A War Story
elbaschid
1
300
Other Decks in Technology
See All in Technology
ガバメントクラウドのセキュリティ対策事例について
fujisawaryohei
0
530
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
210
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
190
MLOps の現場から
asei
6
630
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
160
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
370
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
180
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
210
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
510
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
A Philosophy of Restraint
colly
203
16k
Fireside Chat
paigeccino
34
3.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Scaling GitHub
holman
458
140k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
KATA
mclloyd
29
14k
A Tale of Four Properties
chriscoyier
157
23k
Being A Developer After 40
akosma
87
590k
The Cult of Friendly URLs
andyhume
78
6.1k
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