SlideShare a Scribd company logo
API Versioning 1.0.501
With Docker And Nginx
Using every tool in the box
We divided the project into several
different services.
[Web Server (nginx), PHP (php-fpm),
Redis, Mysql (for local development)]
We established an internal repository of base
images using Ansible (and Ansible Container).
We used Docker compose to do the final
configurations and put them all together.
Dockerize The Project
CI And Deployment
We used Apache Ant to automate running
tests, run metrics on the code, and build
and push images.
We used multiple build.xml files. One for
each environment (development, Staging,
Production).
We used Bitbucket Pipelines to call the
Ant scripts and deploy.
ECS
A container
management service that
supports Docker containers
CloudWatch
a monitoring service for
AWS cloud resources 
ELB
Automatically distributes
incoming application traffic
EC2
Secure and
resizable compute
capacity in the cloud.
The Amazon Tools
Task Definitions
A set of rules and
configurations for container
instances
AWS CLI
A unified tool to manage
your AWS services
ECR
A fully-managed 
Docker container registry
Clusters
a logical grouping
of container instances
Elastic Container Service (ECS)
The Flow
New code is
pushed to
Bitbucket.
The pipeline runs the Ant
scripts to build, tag, and
push the docker images.
It also updates the task
definition for the cluster.
Amazon ECS spins up a
new cluster based on the
new task definition.
New users are sent to the
new cluster. The old
cluster falls away as the
existing users fall away.
1 2 3 4
Let’s Build An App
“We will need to version the API at some point”
“OMG !!
We need it versioned NOW!”
Versioning Methods (for the client)
Version the URI
http://somesite.com/api/v3/user
A Custom Header
HTTP_API_VERSION: version=3
Content Negotiation
HTTP_ACCEPT:
application/vnd.some-api.v3+json
Custom Media Types
Media Type Naming
tree/subtree
i.e. application/json, image/png
Register With IANA:
http://www.iana.org/cgi-bin/
mediatypes.pl
Custom Media Type
vnd.some-api.v3+json
Versioning Methods (for the code)
Version in the code
Copy the code
Docker images
based on git tags
Versioning In The Code
Constantly adding conditionals in
the code.
Duplicate Code Duplication.
Every version exists in the one code
base.
Possible to accidentally change an
old version.
Ever-increasing code size
Copy The Entire Code Base
Duplicate code Duplication.
Possible to accidentally change an
old version.
Ever-increasing code size
Versioning With Docker And Git Tags
The repo deals with only one
version at a time
Other versions exist in the history.
Images are stand alone.
Much less likely to change an old
version.
Git is great. Tags are good!
OK! But How?
We have decided to use Content
Negotiation and multiple Docker
images, but how do we translate
the the Accept header to the
proper Docker version?
Configuring Nginx
The server block
server {
listen 80;
access_log /var/logs/access.log;
error_log /var/logs/error.log;
root /var/www;
location / {
index index.html index.htm index.php;
}
}
Configuring Nginx
The server block
server {
listen 80;
access_log /var/logs/access.log;
error_log /var/logs/error.log;
root /var/www;
location / {
index index.html index.htm index.php;
}
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param $document_root$fastcgi_script_name;
}
}
Configuring Nginx
The Upstream block
upstream php {
server unix:/run/php-fpm/php-fpm.sock;
}
server {
listen 80;
…
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param $document_root$fastcgi_script_name;
}
}
Configuring Nginx
Name Docker Containers
server {
listen 80;
…
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param $document_root$fastcgi_script_name;
}
}
Configuring Nginx
The Map Directive
map $accept_header $backend {
default ‘php_v1’;
‘application/vnd.some-site.v2+json’ ‘php_v2’;
‘application/vnd.some-site.v3+json’ ‘php_v3’;
}
server {
listen 80;
…
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass $backend;
fastcgi_index index.php;
fastcgi_param $document_root$fastcgi_script_name;
}
}
Configuring Nginx
The Map Directive (with include)
map $accept_header $backend {
default ‘php_v1’;
include /var/version_maps/*
}
server {
listen 80;
…
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass $backend;
fastcgi_index index.php;
fastcgi_param $document_root$fastcgi_script_name;
}
}
Semantic Versioning
Major.Minor.Patch
i.e 3.4.1
Matching The Latest Major
v1 => 1.9.13
v2 => 2.8.7
v3 => 3.4.1
Sockets Don’t Like Dots
unix:/run/php-fpm/php-fpm-v341.sock
Configuring Nginx
The Map Directive (with sockets)
map $accept_header $backend {
default ‘unix:/run/php-fpm/php-fpm-v1913.sock’;
‘vnd.some-site.v2’ ‘unix:/run/php-fpm/php-fpm-v287.sock’;
‘vnd.some-site.v3’ ‘unix:/run/php-fpm/php-fpm-v341.sock’;
}
server {
listen 80;
…
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass $backend;
fastcgi_index index.php;
fastcgi_param $document_root$fastcgi_script_name;
}
}
Git Tags And Ant Scripts
Each release gets a version tag in Git.
(And ideally its own branch matching the
minor version).
Update The Ant Build Scripts to pull the Git
tags, loop through them, match major versions
to the LATEST minor/patch version, and create
map files based on this.
Update the php-fpm config to version the
socket.
Update the task definition with the new
tagged image version, and version the
shared socket volume
Put It All Together
Tag the code in Git
for release
Ant dynamically builds the
version map files, updates
the task definition and
pushes necessary images.
Amazon ECS spins up a
new Cluster based on the
updated task definition
and tagged images.
nginx uses the Accept
header to map the proper
php-fpm version container.
1 2 3 4
Other Concerns - ECS Is Atomic
Atomic! It either all works, or it fails.
There are many pieces to the Amazon
ECS puzzle. Piecing it all together can
sometimes be confusing. And it is easy
to forget something - especially in the
beginning.
Solution: Sadly, trial and error. And the
CloudWatch logs.
Other Concerns - The Shared Socket Volume
When we spin up a new “Cluster” the
source volume already exists! This
causes a failure!
Solution: dynamically update the shared
volume on each task definition version.
Other Concerns - Memory Limit
The Docker images are basically small
and manageable, but each one takes a
good bit of memory. What happens when
the EC2 instance runs out.
Solution: Amazon has Auto-Scaling
definitions. If properly configured, it will
automagically spin up a new instance.
Other Concerns - The Default Map Version
Since we did not have versioning in
the beginning, we had to use the
default (nginx map) as the version 1. So
how do we know if the request is actually
for version 1, or if it asking for a version
that does not exist.
Solution: The dreaded IF statements in
nginx.
Apps And API Versioning
Since (for the most part) you cannot
force users to update the app version,
sharing data across multiple versions of
the App can definitely be problematic.
Solution: Preplanning, case by case
solutions, and therapy.
Conclusion - It’s Almost Like A Dream
Special Thanks Goes To:
Docker
Docker-Compose
Ansible
Ansible Container
Ant
Git
Bitbucket Pipelines
Amazon EC2
Amazon Load Balancer
Amazon ECS
Amazon Auto-Scaling
Amazon CloudWatch
Nginx
Php (fpm)
Thank You!

More Related Content

What's hot

Tectonic Summit 2016: Kubernetes 1.5 and Beyond
Tectonic Summit 2016: Kubernetes 1.5 and BeyondTectonic Summit 2016: Kubernetes 1.5 and Beyond
Tectonic Summit 2016: Kubernetes 1.5 and Beyond
CoreOS
 
Kubernetes automation in production
Kubernetes automation in productionKubernetes automation in production
Kubernetes automation in production
Paul Bakker
 
Docker storage designing a platform for persistent data
Docker storage designing a platform for persistent dataDocker storage designing a platform for persistent data
Docker storage designing a platform for persistent data
Docker, Inc.
 
DockerCon EU 2015: Trading Bitcoin with Docker
DockerCon EU 2015: Trading Bitcoin with DockerDockerCon EU 2015: Trading Bitcoin with Docker
DockerCon EU 2015: Trading Bitcoin with Docker
Docker, Inc.
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
Red Hat Developers
 
Kubernetes 101 Workshop
Kubernetes 101 WorkshopKubernetes 101 Workshop
Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)
DoiT International
 
KubeCon EU 2016: Killing containers to make weather beautiful
KubeCon EU 2016: Killing containers to make weather beautifulKubeCon EU 2016: Killing containers to make weather beautiful
KubeCon EU 2016: Killing containers to make weather beautiful
KubeAcademy
 
KubeCon EU 2016: Multi-Tenant Kubernetes
KubeCon EU 2016: Multi-Tenant KubernetesKubeCon EU 2016: Multi-Tenant Kubernetes
KubeCon EU 2016: Multi-Tenant Kubernetes
KubeAcademy
 
Docker on docker leveraging kubernetes in docker ee
Docker on docker leveraging kubernetes in docker eeDocker on docker leveraging kubernetes in docker ee
Docker on docker leveraging kubernetes in docker ee
Docker, Inc.
 
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
Docker, Inc.
 
Zero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetesZero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetes
Arjan Schaaf
 
Tectonic Summit 2016: The Origins of Kubernetes
Tectonic Summit 2016: The Origins of KubernetesTectonic Summit 2016: The Origins of Kubernetes
Tectonic Summit 2016: The Origins of Kubernetes
CoreOS
 
Automatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes ClusterAutomatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes Cluster
HungWei Chiu
 
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
devopsdaysaustin
 
KubeCon EU 2016: "rktnetes": what's new with container runtimes and Kubernetes
KubeCon EU 2016: "rktnetes": what's new with container runtimes and KubernetesKubeCon EU 2016: "rktnetes": what's new with container runtimes and Kubernetes
KubeCon EU 2016: "rktnetes": what's new with container runtimes and Kubernetes
KubeAcademy
 
Managing Docker Containers In A Cluster - Introducing Kubernetes
Managing Docker Containers In A Cluster - Introducing KubernetesManaging Docker Containers In A Cluster - Introducing Kubernetes
Managing Docker Containers In A Cluster - Introducing Kubernetes
Marc Sluiter
 
KubeCon EU 2016: ITNW (If This Now What): Orchestrating an Enterprise
KubeCon EU 2016: ITNW (If This Now What): Orchestrating an EnterpriseKubeCon EU 2016: ITNW (If This Now What): Orchestrating an Enterprise
KubeCon EU 2016: ITNW (If This Now What): Orchestrating an Enterprise
KubeAcademy
 
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Edureka!
 
Kubernetes and the hybrid cloud with Skupper | DevNation tech talk
Kubernetes and the hybrid cloud with Skupper | DevNation tech talkKubernetes and the hybrid cloud with Skupper | DevNation tech talk
Kubernetes and the hybrid cloud with Skupper | DevNation tech talk
Red Hat Developers
 

What's hot (20)

Tectonic Summit 2016: Kubernetes 1.5 and Beyond
Tectonic Summit 2016: Kubernetes 1.5 and BeyondTectonic Summit 2016: Kubernetes 1.5 and Beyond
Tectonic Summit 2016: Kubernetes 1.5 and Beyond
 
Kubernetes automation in production
Kubernetes automation in productionKubernetes automation in production
Kubernetes automation in production
 
Docker storage designing a platform for persistent data
Docker storage designing a platform for persistent dataDocker storage designing a platform for persistent data
Docker storage designing a platform for persistent data
 
DockerCon EU 2015: Trading Bitcoin with Docker
DockerCon EU 2015: Trading Bitcoin with DockerDockerCon EU 2015: Trading Bitcoin with Docker
DockerCon EU 2015: Trading Bitcoin with Docker
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
 
Kubernetes 101 Workshop
Kubernetes 101 WorkshopKubernetes 101 Workshop
Kubernetes 101 Workshop
 
Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)
 
KubeCon EU 2016: Killing containers to make weather beautiful
KubeCon EU 2016: Killing containers to make weather beautifulKubeCon EU 2016: Killing containers to make weather beautiful
KubeCon EU 2016: Killing containers to make weather beautiful
 
KubeCon EU 2016: Multi-Tenant Kubernetes
KubeCon EU 2016: Multi-Tenant KubernetesKubeCon EU 2016: Multi-Tenant Kubernetes
KubeCon EU 2016: Multi-Tenant Kubernetes
 
Docker on docker leveraging kubernetes in docker ee
Docker on docker leveraging kubernetes in docker eeDocker on docker leveraging kubernetes in docker ee
Docker on docker leveraging kubernetes in docker ee
 
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
 
Zero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetesZero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetes
 
Tectonic Summit 2016: The Origins of Kubernetes
Tectonic Summit 2016: The Origins of KubernetesTectonic Summit 2016: The Origins of Kubernetes
Tectonic Summit 2016: The Origins of Kubernetes
 
Automatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes ClusterAutomatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes Cluster
 
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
 
KubeCon EU 2016: "rktnetes": what's new with container runtimes and Kubernetes
KubeCon EU 2016: "rktnetes": what's new with container runtimes and KubernetesKubeCon EU 2016: "rktnetes": what's new with container runtimes and Kubernetes
KubeCon EU 2016: "rktnetes": what's new with container runtimes and Kubernetes
 
Managing Docker Containers In A Cluster - Introducing Kubernetes
Managing Docker Containers In A Cluster - Introducing KubernetesManaging Docker Containers In A Cluster - Introducing Kubernetes
Managing Docker Containers In A Cluster - Introducing Kubernetes
 
KubeCon EU 2016: ITNW (If This Now What): Orchestrating an Enterprise
KubeCon EU 2016: ITNW (If This Now What): Orchestrating an EnterpriseKubeCon EU 2016: ITNW (If This Now What): Orchestrating an Enterprise
KubeCon EU 2016: ITNW (If This Now What): Orchestrating an Enterprise
 
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
 
Kubernetes and the hybrid cloud with Skupper | DevNation tech talk
Kubernetes and the hybrid cloud with Skupper | DevNation tech talkKubernetes and the hybrid cloud with Skupper | DevNation tech talk
Kubernetes and the hybrid cloud with Skupper | DevNation tech talk
 

Similar to Api versioning w_docker_and_nginx

Build optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and DockerBuild optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and Docker
Dmytro Patkovskyi
 
Deep Dive into AWS Fargate
Deep Dive into AWS FargateDeep Dive into AWS Fargate
Deep Dive into AWS Fargate
Amazon Web Services
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment
Arun prasath
 
Experiences with AWS immutable deploys and job processing
Experiences with AWS immutable deploys and job processingExperiences with AWS immutable deploys and job processing
Experiences with AWS immutable deploys and job processing
Docker, Inc.
 
Using Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous DeliveryUsing Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous Delivery
Carlos Sanchez
 
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2daysUsing Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Carlos Sanchez
 
Developer Experience Cloud Native - From Code Gen to Git Commit without a CI/...
Developer Experience Cloud Native - From Code Gen to Git Commit without a CI/...Developer Experience Cloud Native - From Code Gen to Git Commit without a CI/...
Developer Experience Cloud Native - From Code Gen to Git Commit without a CI/...
Michael Hofmann
 
CI/CD on AWS: Deploy Everything All the Time | AWS Public Sector Summit 2016
CI/CD on AWS: Deploy Everything All the Time | AWS Public Sector Summit 2016CI/CD on AWS: Deploy Everything All the Time | AWS Public Sector Summit 2016
CI/CD on AWS: Deploy Everything All the Time | AWS Public Sector Summit 2016
Amazon Web Services
 
Advanced Container Scheduling
Advanced Container SchedulingAdvanced Container Scheduling
Advanced Container Scheduling
Amazon Web Services
 
Accelerate your development with Docker
Accelerate your development with DockerAccelerate your development with Docker
Accelerate your development with Docker
Andrey Hristov
 
Accelerate your software development with Docker
Accelerate your software development with DockerAccelerate your software development with Docker
Accelerate your software development with Docker
Andrey Hristov
 
Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.
Henryk Konsek
 
AWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul Maddox
AWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul MaddoxAWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul Maddox
AWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul Maddox
AWS Riyadh User Group
 
Docker intro
Docker introDocker intro
Docker intro
Oleg Z
 
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UKStorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
Hao Fan
 
Ci with jenkins docker and mssql belgium
Ci with jenkins docker and mssql belgiumCi with jenkins docker and mssql belgium
Ci with jenkins docker and mssql belgium
Chris Adkin
 
Docker 101
Docker 101 Docker 101
Docker 101
Kevin Nord
 
Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
Dongwon Kim
 
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other ThingsI Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
Michael Lange
 

Similar to Api versioning w_docker_and_nginx (20)

Build optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and DockerBuild optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and Docker
 
Deep Dive into AWS Fargate
Deep Dive into AWS FargateDeep Dive into AWS Fargate
Deep Dive into AWS Fargate
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment
 
Experiences with AWS immutable deploys and job processing
Experiences with AWS immutable deploys and job processingExperiences with AWS immutable deploys and job processing
Experiences with AWS immutable deploys and job processing
 
Using Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous DeliveryUsing Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous Delivery
 
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2daysUsing Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
 
Developer Experience Cloud Native - From Code Gen to Git Commit without a CI/...
Developer Experience Cloud Native - From Code Gen to Git Commit without a CI/...Developer Experience Cloud Native - From Code Gen to Git Commit without a CI/...
Developer Experience Cloud Native - From Code Gen to Git Commit without a CI/...
 
CI/CD on AWS: Deploy Everything All the Time | AWS Public Sector Summit 2016
CI/CD on AWS: Deploy Everything All the Time | AWS Public Sector Summit 2016CI/CD on AWS: Deploy Everything All the Time | AWS Public Sector Summit 2016
CI/CD on AWS: Deploy Everything All the Time | AWS Public Sector Summit 2016
 
Advanced Container Scheduling
Advanced Container SchedulingAdvanced Container Scheduling
Advanced Container Scheduling
 
Accelerate your development with Docker
Accelerate your development with DockerAccelerate your development with Docker
Accelerate your development with Docker
 
Accelerate your software development with Docker
Accelerate your software development with DockerAccelerate your software development with Docker
Accelerate your software development with Docker
 
Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.
 
AWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul Maddox
AWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul MaddoxAWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul Maddox
AWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul Maddox
 
Docker intro
Docker introDocker intro
Docker intro
 
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UKStorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Ci with jenkins docker and mssql belgium
Ci with jenkins docker and mssql belgiumCi with jenkins docker and mssql belgium
Ci with jenkins docker and mssql belgium
 
Docker 101
Docker 101 Docker 101
Docker 101
 
Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
 
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other ThingsI Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
 

Recently uploaded

7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
Danica Gill
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
Toptal Tech
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
uehowe
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
hackersuli
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
Trish Parr
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Florence Consulting
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
AanSulistiyo
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
uehowe
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
zyfovom
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
cuobya
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
cuobya
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
SEO Article Boost
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
cuobya
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
uehowe
 
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
bseovas
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
fovkoyb
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
vmemo1
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
saathvikreddy2003
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
wolfsoftcompanyco
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
ysasp1
 

Recently uploaded (20)

7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
 
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
 

Api versioning w_docker_and_nginx

  • 1. API Versioning 1.0.501 With Docker And Nginx Using every tool in the box
  • 2. We divided the project into several different services. [Web Server (nginx), PHP (php-fpm), Redis, Mysql (for local development)] We established an internal repository of base images using Ansible (and Ansible Container). We used Docker compose to do the final configurations and put them all together. Dockerize The Project
  • 3. CI And Deployment We used Apache Ant to automate running tests, run metrics on the code, and build and push images. We used multiple build.xml files. One for each environment (development, Staging, Production). We used Bitbucket Pipelines to call the Ant scripts and deploy.
  • 4. ECS A container management service that supports Docker containers CloudWatch a monitoring service for AWS cloud resources  ELB Automatically distributes incoming application traffic EC2 Secure and resizable compute capacity in the cloud. The Amazon Tools
  • 5. Task Definitions A set of rules and configurations for container instances AWS CLI A unified tool to manage your AWS services ECR A fully-managed  Docker container registry Clusters a logical grouping of container instances Elastic Container Service (ECS)
  • 6. The Flow New code is pushed to Bitbucket. The pipeline runs the Ant scripts to build, tag, and push the docker images. It also updates the task definition for the cluster. Amazon ECS spins up a new cluster based on the new task definition. New users are sent to the new cluster. The old cluster falls away as the existing users fall away. 1 2 3 4
  • 8. “We will need to version the API at some point”
  • 9. “OMG !! We need it versioned NOW!”
  • 10. Versioning Methods (for the client) Version the URI http://somesite.com/api/v3/user A Custom Header HTTP_API_VERSION: version=3 Content Negotiation HTTP_ACCEPT: application/vnd.some-api.v3+json
  • 11. Custom Media Types Media Type Naming tree/subtree i.e. application/json, image/png Register With IANA: http://www.iana.org/cgi-bin/ mediatypes.pl Custom Media Type vnd.some-api.v3+json
  • 12. Versioning Methods (for the code) Version in the code Copy the code Docker images based on git tags
  • 13. Versioning In The Code Constantly adding conditionals in the code. Duplicate Code Duplication. Every version exists in the one code base. Possible to accidentally change an old version. Ever-increasing code size
  • 14. Copy The Entire Code Base Duplicate code Duplication. Possible to accidentally change an old version. Ever-increasing code size
  • 15. Versioning With Docker And Git Tags The repo deals with only one version at a time Other versions exist in the history. Images are stand alone. Much less likely to change an old version. Git is great. Tags are good!
  • 16. OK! But How? We have decided to use Content Negotiation and multiple Docker images, but how do we translate the the Accept header to the proper Docker version?
  • 17. Configuring Nginx The server block server { listen 80; access_log /var/logs/access.log; error_log /var/logs/error.log; root /var/www; location / { index index.html index.htm index.php; } }
  • 18. Configuring Nginx The server block server { listen 80; access_log /var/logs/access.log; error_log /var/logs/error.log; root /var/www; location / { index index.html index.htm index.php; } location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param $document_root$fastcgi_script_name; } }
  • 19. Configuring Nginx The Upstream block upstream php { server unix:/run/php-fpm/php-fpm.sock; } server { listen 80; … location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass php; fastcgi_index index.php; fastcgi_param $document_root$fastcgi_script_name; } }
  • 20. Configuring Nginx Name Docker Containers server { listen 80; … location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param $document_root$fastcgi_script_name; } }
  • 21. Configuring Nginx The Map Directive map $accept_header $backend { default ‘php_v1’; ‘application/vnd.some-site.v2+json’ ‘php_v2’; ‘application/vnd.some-site.v3+json’ ‘php_v3’; } server { listen 80; … location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass $backend; fastcgi_index index.php; fastcgi_param $document_root$fastcgi_script_name; } }
  • 22. Configuring Nginx The Map Directive (with include) map $accept_header $backend { default ‘php_v1’; include /var/version_maps/* } server { listen 80; … location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass $backend; fastcgi_index index.php; fastcgi_param $document_root$fastcgi_script_name; } }
  • 23. Semantic Versioning Major.Minor.Patch i.e 3.4.1 Matching The Latest Major v1 => 1.9.13 v2 => 2.8.7 v3 => 3.4.1 Sockets Don’t Like Dots unix:/run/php-fpm/php-fpm-v341.sock
  • 24. Configuring Nginx The Map Directive (with sockets) map $accept_header $backend { default ‘unix:/run/php-fpm/php-fpm-v1913.sock’; ‘vnd.some-site.v2’ ‘unix:/run/php-fpm/php-fpm-v287.sock’; ‘vnd.some-site.v3’ ‘unix:/run/php-fpm/php-fpm-v341.sock’; } server { listen 80; … location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass $backend; fastcgi_index index.php; fastcgi_param $document_root$fastcgi_script_name; } }
  • 25. Git Tags And Ant Scripts Each release gets a version tag in Git. (And ideally its own branch matching the minor version). Update The Ant Build Scripts to pull the Git tags, loop through them, match major versions to the LATEST minor/patch version, and create map files based on this. Update the php-fpm config to version the socket. Update the task definition with the new tagged image version, and version the shared socket volume
  • 26. Put It All Together Tag the code in Git for release Ant dynamically builds the version map files, updates the task definition and pushes necessary images. Amazon ECS spins up a new Cluster based on the updated task definition and tagged images. nginx uses the Accept header to map the proper php-fpm version container. 1 2 3 4
  • 27. Other Concerns - ECS Is Atomic Atomic! It either all works, or it fails. There are many pieces to the Amazon ECS puzzle. Piecing it all together can sometimes be confusing. And it is easy to forget something - especially in the beginning. Solution: Sadly, trial and error. And the CloudWatch logs.
  • 28. Other Concerns - The Shared Socket Volume When we spin up a new “Cluster” the source volume already exists! This causes a failure! Solution: dynamically update the shared volume on each task definition version.
  • 29. Other Concerns - Memory Limit The Docker images are basically small and manageable, but each one takes a good bit of memory. What happens when the EC2 instance runs out. Solution: Amazon has Auto-Scaling definitions. If properly configured, it will automagically spin up a new instance.
  • 30. Other Concerns - The Default Map Version Since we did not have versioning in the beginning, we had to use the default (nginx map) as the version 1. So how do we know if the request is actually for version 1, or if it asking for a version that does not exist. Solution: The dreaded IF statements in nginx.
  • 31. Apps And API Versioning Since (for the most part) you cannot force users to update the app version, sharing data across multiple versions of the App can definitely be problematic. Solution: Preplanning, case by case solutions, and therapy.
  • 32. Conclusion - It’s Almost Like A Dream
  • 33. Special Thanks Goes To: Docker Docker-Compose Ansible Ansible Container Ant Git Bitbucket Pipelines Amazon EC2 Amazon Load Balancer Amazon ECS Amazon Auto-Scaling Amazon CloudWatch Nginx Php (fpm)