SlideShare a Scribd company logo
API Versioning 1.0.501
With Docker and Nginx
using every tool in the box
1
2
3
Dockerize The Project
1. Divide The Project
2. Base Images
3. Docker
Compose
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.
1
2
3
CI and Deployment
1. Ant Scripts
2. Multiple
Environments
3. Bitbucket
Pipelines
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.
Amazon has an extensive
set of tools and portals to
organise your deployments
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
Amazon has an extensive
set of tools and portals to
organise your deployments
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)
Step 1 Step 2 Step 3 Step 4
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 once existing
users finish.
Let’s Build An App
“We will need to version
the API at some point”
“OMG !!
We need the it versioned NOW!”
Version the URI
http://somesite.com/api/v3/user
A Custom Header
HTTP_API_VERSION: version=3
Content Negotiation
HTTP_ACCEPT: vnd.some-api.v3
Versioning Methods (for the client)
Version in the code
Copy the code
Docker images
based on git tags
Versioning Methods (for the code)
Constantly adding conditionals in the code.
Duplicate code Duplication.
Every version exists in the one code base.
Versioning In The Code
Possible to accidentally change an old version.
Ever-increasing code size
Duplicate code Duplication.
Copy The Entire Code Base
Possible to accidentally change an old version.
Ever-increasing code size
The repo deals with only one version at a time
Other versions exist in the history.
Versioning With Docker And Git Tags
Much less likely to change an old version.
Git is great. Tags are good!
Images are stand alone.
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?
OK. But How?
Configuring Nginx
The Server Block
server {
listen 80;
access_log /var/logs/access.log;
error_log /var/logs/error.log;
root /var/www/public_html;
location / {
index index.html index.htm index.php;
}
}
Configuring Nginx
server {
listen 80;
access_log /var/logs/access.log;
error_log /var/logs/error.log;
root /var/www/public_html;
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 SCRIPT_FILENAME /public_html$fastcgi_script_name;
}
}
The Server Block
Configuring Nginx
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 SCRIPT_FILENAME /public_html$fastcgi_script_name;
}
}
The Upstream Block
Configuring Nginx
server {
listen 80;
…
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name;
}
}
The Named Docker Containers
Configuring Nginx
map $accept_header $backend {
default ‘php_v1’;
‘vnd.some-site.v2’ ‘php_v2’;
‘vnd.some-site.v2’ ‘php_v3’;
}
server {
listen 80;
…
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass $backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name;
}
}
The Map Directive
Configuring Nginx
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 SCRIPT_FILENAME /public_html$fastcgi_script_name;
}
}
The Map Directive (with include)
Back To Configuring Nginx
map $accept_header $backend {
default ‘unix:/run/php-fpm/php-fpm-v1.sock’;
‘vnd.some-site.v2’ ‘unix:/run/php-fpm/php-fpm-v2.sock’;
‘vnd.some-site.v3’ ‘unix:/run/php-fpm/php-fpm-v3.sock’;
}
server {
listen 80;
…
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass $backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name;
}
}
The Map Directive
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.
Git Tags And Ant Scripts
Update the task definition with the new
tagged image version, and version the
shared socket volume
Step 1 Step 2 Step 3 Step 4
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.
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 - ECS Is Atomic
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 - The Shared Socket Volume
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
definition. If properly configured, it will
automagically spin up a new instance.
Other Concerns - Memory Limit
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.
Other Concerns - The Default Map Version
Conclusion - It’s Almost Like A Dream
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)
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)
Special Thanks Goes To:
Thank You
Lee Wilkins
Cool guy: coding,
cooking, carousing

More Related Content

What's hot

Building kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech TalkBuilding kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech Talk
Red Hat Developers
 
Scaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container ServiceScaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container Service
Ben Hall
 
How to Achieve Canary Deployment on Kubernetes
How to Achieve Canary Deployment on KubernetesHow to Achieve Canary Deployment on Kubernetes
How to Achieve Canary Deployment on Kubernetes
HanLing Shen
 
Kubernetes 101 Workshop
Kubernetes 101 WorkshopKubernetes 101 Workshop
Kubernetes Networking 101
Kubernetes Networking 101Kubernetes Networking 101
Kubernetes Networking 101
Weaveworks
 
Scaling jenkins with kubernetes
Scaling jenkins with kubernetesScaling jenkins with kubernetes
Scaling jenkins with kubernetes
Ami Mahloof
 
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
 
Scaling Docker with Kubernetes
Scaling Docker with KubernetesScaling Docker with Kubernetes
Scaling Docker with Kubernetes
Carlos Sanchez
 
On-Demand Image Resizing from Part of the monolith to Containerized Microserv...
On-Demand Image Resizing from Part of the monolith to Containerized Microserv...On-Demand Image Resizing from Part of the monolith to Containerized Microserv...
On-Demand Image Resizing from Part of the monolith to Containerized Microserv...
Docker, Inc.
 
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
 
Kubernetes best practices
Kubernetes best practicesKubernetes best practices
Kubernetes best practices
Bill Liu
 
Docker for Devs - John Zaccone, IBM
Docker for Devs - John Zaccone, IBMDocker for Devs - John Zaccone, IBM
Docker for Devs - John Zaccone, IBM
Docker, Inc.
 
Kubelet with no Kubernetes Masters | DevNation Tech Talk
Kubelet with no Kubernetes Masters | DevNation Tech TalkKubelet with no Kubernetes Masters | DevNation Tech Talk
Kubelet with no Kubernetes Masters | DevNation Tech Talk
Red Hat Developers
 
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
CI and CD at Scale: Scaling Jenkins with Docker and Apache MesosCI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
Carlos Sanchez
 
Zero to Continuous Delivery on Google Cloud
Zero to Continuous Delivery on Google CloudZero to Continuous Delivery on Google Cloud
Zero to Continuous Delivery on Google Cloud
James Heggs
 
Head First to Container&Kubernetes
Head First to Container&KubernetesHead First to Container&Kubernetes
Head First to Container&Kubernetes
HungWei Chiu
 
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and JenkinsContinuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Marcel Birkner
 
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
William Yeh
 
Kubernetes and Hybrid Deployments
Kubernetes and Hybrid DeploymentsKubernetes and Hybrid Deployments
Kubernetes and Hybrid Deployments
Sandeep Parikh
 
Using Docker For Development
Using Docker For DevelopmentUsing Docker For Development
Using Docker For Development
Laura Frank Tacho
 

What's hot (20)

Building kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech TalkBuilding kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech Talk
 
Scaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container ServiceScaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container Service
 
How to Achieve Canary Deployment on Kubernetes
How to Achieve Canary Deployment on KubernetesHow to Achieve Canary Deployment on Kubernetes
How to Achieve Canary Deployment on Kubernetes
 
Kubernetes 101 Workshop
Kubernetes 101 WorkshopKubernetes 101 Workshop
Kubernetes 101 Workshop
 
Kubernetes Networking 101
Kubernetes Networking 101Kubernetes Networking 101
Kubernetes Networking 101
 
Scaling jenkins with kubernetes
Scaling jenkins with kubernetesScaling jenkins with kubernetes
Scaling jenkins with kubernetes
 
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
 
Scaling Docker with Kubernetes
Scaling Docker with KubernetesScaling Docker with Kubernetes
Scaling Docker with Kubernetes
 
On-Demand Image Resizing from Part of the monolith to Containerized Microserv...
On-Demand Image Resizing from Part of the monolith to Containerized Microserv...On-Demand Image Resizing from Part of the monolith to Containerized Microserv...
On-Demand Image Resizing from Part of the monolith to Containerized Microserv...
 
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
 
Kubernetes best practices
Kubernetes best practicesKubernetes best practices
Kubernetes best practices
 
Docker for Devs - John Zaccone, IBM
Docker for Devs - John Zaccone, IBMDocker for Devs - John Zaccone, IBM
Docker for Devs - John Zaccone, IBM
 
Kubelet with no Kubernetes Masters | DevNation Tech Talk
Kubelet with no Kubernetes Masters | DevNation Tech TalkKubelet with no Kubernetes Masters | DevNation Tech Talk
Kubelet with no Kubernetes Masters | DevNation Tech Talk
 
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
CI and CD at Scale: Scaling Jenkins with Docker and Apache MesosCI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
 
Zero to Continuous Delivery on Google Cloud
Zero to Continuous Delivery on Google CloudZero to Continuous Delivery on Google Cloud
Zero to Continuous Delivery on Google Cloud
 
Head First to Container&Kubernetes
Head First to Container&KubernetesHead First to Container&Kubernetes
Head First to Container&Kubernetes
 
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and JenkinsContinuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
 
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
 
Kubernetes and Hybrid Deployments
Kubernetes and Hybrid DeploymentsKubernetes and Hybrid Deployments
Kubernetes and Hybrid Deployments
 
Using Docker For Development
Using Docker For DevelopmentUsing Docker For Development
Using Docker For Development
 

Similar to Api Versioning with 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
 
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
 
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
 
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
 
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
 
Deep Dive Azure Functions - Global Azure Bootcamp 2019
Deep Dive Azure Functions - Global Azure Bootcamp 2019Deep Dive Azure Functions - Global Azure Bootcamp 2019
Deep Dive Azure Functions - Global Azure Bootcamp 2019
Andrea Tosato
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
RightScale
 
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
 
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
Puppet
 
Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
Dongwon Kim
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
Hao Fan
 
Docker 101
Docker 101 Docker 101
Docker 101
Kevin Nord
 
Continuous Integration With Jenkins Docker SQL Server
Continuous Integration With Jenkins Docker SQL ServerContinuous Integration With Jenkins Docker SQL Server
Continuous Integration With Jenkins Docker SQL Server
Chris Adkin
 
Docker intro
Docker introDocker intro
Docker intro
Oleg Z
 
Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.
Henryk Konsek
 
Docker Oxford launch - Introduction to Docker
Docker Oxford launch - Introduction to DockerDocker Oxford launch - Introduction to Docker
Docker Oxford launch - Introduction to Docker
jonatanblue
 
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
 

Similar to Api Versioning with 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
 
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/...
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment
 
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
 
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
 
Deep Dive into AWS Fargate
Deep Dive into AWS FargateDeep Dive into AWS Fargate
Deep Dive into AWS Fargate
 
Deep Dive Azure Functions - Global Azure Bootcamp 2019
Deep Dive Azure Functions - Global Azure Bootcamp 2019Deep Dive Azure Functions - Global Azure Bootcamp 2019
Deep Dive Azure Functions - Global Azure Bootcamp 2019
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
 
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
 
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
 
Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Docker 101
Docker 101 Docker 101
Docker 101
 
Continuous Integration With Jenkins Docker SQL Server
Continuous Integration With Jenkins Docker SQL ServerContinuous Integration With Jenkins Docker SQL Server
Continuous Integration With Jenkins Docker SQL Server
 
Docker intro
Docker introDocker intro
Docker intro
 
Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.
 
Docker Oxford launch - Introduction to Docker
Docker Oxford launch - Introduction to DockerDocker Oxford launch - Introduction to Docker
Docker Oxford launch - Introduction to Docker
 
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
 

More from tech.kartenmacherei

Smoke tests - what why how - PHP Srbija
Smoke tests - what why how - PHP SrbijaSmoke tests - what why how - PHP Srbija
Smoke tests - what why how - PHP Srbija
tech.kartenmacherei
 
SmokeTests - What, Why & How - ConFoo 2019
SmokeTests - What, Why & How - ConFoo 2019SmokeTests - What, Why & How - ConFoo 2019
SmokeTests - What, Why & How - ConFoo 2019
tech.kartenmacherei
 
PHPUnit in 4 parts - ConFoo 2019
PHPUnit in 4 parts - ConFoo 2019PHPUnit in 4 parts - ConFoo 2019
PHPUnit in 4 parts - ConFoo 2019
tech.kartenmacherei
 
An Ode To Boring Technology
An Ode To Boring TechnologyAn Ode To Boring Technology
An Ode To Boring Technology
tech.kartenmacherei
 
Learning to Drive - A story about app development
Learning to Drive - A story about app developmentLearning to Drive - A story about app development
Learning to Drive - A story about app development
tech.kartenmacherei
 
SmokeTests
SmokeTestsSmokeTests
Smoke Tests @ DevOps-Hamburg 06.02.2017
Smoke Tests @ DevOps-Hamburg 06.02.2017Smoke Tests @ DevOps-Hamburg 06.02.2017
Smoke Tests @ DevOps-Hamburg 06.02.2017
tech.kartenmacherei
 
Don't fear the Walking Dead @ IPC 2016
Don't fear the Walking Dead @ IPC 2016Don't fear the Walking Dead @ IPC 2016
Don't fear the Walking Dead @ IPC 2016
tech.kartenmacherei
 
99% is not enough
99% is not enough99% is not enough
99% is not enough
tech.kartenmacherei
 
Don't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHHDon't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHH
tech.kartenmacherei
 

More from tech.kartenmacherei (10)

Smoke tests - what why how - PHP Srbija
Smoke tests - what why how - PHP SrbijaSmoke tests - what why how - PHP Srbija
Smoke tests - what why how - PHP Srbija
 
SmokeTests - What, Why & How - ConFoo 2019
SmokeTests - What, Why & How - ConFoo 2019SmokeTests - What, Why & How - ConFoo 2019
SmokeTests - What, Why & How - ConFoo 2019
 
PHPUnit in 4 parts - ConFoo 2019
PHPUnit in 4 parts - ConFoo 2019PHPUnit in 4 parts - ConFoo 2019
PHPUnit in 4 parts - ConFoo 2019
 
An Ode To Boring Technology
An Ode To Boring TechnologyAn Ode To Boring Technology
An Ode To Boring Technology
 
Learning to Drive - A story about app development
Learning to Drive - A story about app developmentLearning to Drive - A story about app development
Learning to Drive - A story about app development
 
SmokeTests
SmokeTestsSmokeTests
SmokeTests
 
Smoke Tests @ DevOps-Hamburg 06.02.2017
Smoke Tests @ DevOps-Hamburg 06.02.2017Smoke Tests @ DevOps-Hamburg 06.02.2017
Smoke Tests @ DevOps-Hamburg 06.02.2017
 
Don't fear the Walking Dead @ IPC 2016
Don't fear the Walking Dead @ IPC 2016Don't fear the Walking Dead @ IPC 2016
Don't fear the Walking Dead @ IPC 2016
 
99% is not enough
99% is not enough99% is not enough
99% is not enough
 
Don't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHHDon't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHH
 

Recently uploaded

Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 

Recently uploaded (20)

Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 

Api Versioning with Docker and Nginx

  • 1. API Versioning 1.0.501 With Docker and Nginx using every tool in the box
  • 2. 1 2 3 Dockerize The Project 1. Divide The Project 2. Base Images 3. Docker Compose 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.
  • 3. 1 2 3 CI and Deployment 1. Ant Scripts 2. Multiple Environments 3. Bitbucket Pipelines 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. Amazon has an extensive set of tools and portals to organise your deployments 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. Amazon has an extensive set of tools and portals to organise your deployments 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. Step 1 Step 2 Step 3 Step 4 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 once existing users finish.
  • 8. “We will need to version the API at some point”
  • 9. “OMG !! We need the it versioned NOW!”
  • 10. Version the URI http://somesite.com/api/v3/user A Custom Header HTTP_API_VERSION: version=3 Content Negotiation HTTP_ACCEPT: vnd.some-api.v3 Versioning Methods (for the client)
  • 11. Version in the code Copy the code Docker images based on git tags Versioning Methods (for the code)
  • 12. Constantly adding conditionals in the code. Duplicate code Duplication. Every version exists in the one code base. Versioning In The Code Possible to accidentally change an old version. Ever-increasing code size
  • 13. Duplicate code Duplication. Copy The Entire Code Base Possible to accidentally change an old version. Ever-increasing code size
  • 14. The repo deals with only one version at a time Other versions exist in the history. Versioning With Docker And Git Tags Much less likely to change an old version. Git is great. Tags are good! Images are stand alone.
  • 15. 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? OK. But How?
  • 16. Configuring Nginx The Server Block server { listen 80; access_log /var/logs/access.log; error_log /var/logs/error.log; root /var/www/public_html; location / { index index.html index.htm index.php; } }
  • 17. Configuring Nginx server { listen 80; access_log /var/logs/access.log; error_log /var/logs/error.log; root /var/www/public_html; 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 SCRIPT_FILENAME /public_html$fastcgi_script_name; } } The Server Block
  • 18. Configuring Nginx 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 SCRIPT_FILENAME /public_html$fastcgi_script_name; } } The Upstream Block
  • 19. Configuring Nginx server { listen 80; … location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name; } } The Named Docker Containers
  • 20. Configuring Nginx map $accept_header $backend { default ‘php_v1’; ‘vnd.some-site.v2’ ‘php_v2’; ‘vnd.some-site.v2’ ‘php_v3’; } server { listen 80; … location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass $backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name; } } The Map Directive
  • 21. Configuring Nginx 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 SCRIPT_FILENAME /public_html$fastcgi_script_name; } } The Map Directive (with include)
  • 22. Back To Configuring Nginx map $accept_header $backend { default ‘unix:/run/php-fpm/php-fpm-v1.sock’; ‘vnd.some-site.v2’ ‘unix:/run/php-fpm/php-fpm-v2.sock’; ‘vnd.some-site.v3’ ‘unix:/run/php-fpm/php-fpm-v3.sock’; } server { listen 80; … location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass $backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name; } } The Map Directive
  • 23. 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. Git Tags And Ant Scripts Update the task definition with the new tagged image version, and version the shared socket volume
  • 24. Step 1 Step 2 Step 3 Step 4 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.
  • 25. 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 - ECS Is Atomic
  • 26. 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 - The Shared Socket Volume
  • 27. 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 definition. If properly configured, it will automagically spin up a new instance. Other Concerns - Memory Limit
  • 28. 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. Other Concerns - The Default Map Version
  • 29. Conclusion - It’s Almost Like A Dream
  • 30. 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) 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) Special Thanks Goes To:
  • 32. Lee Wilkins Cool guy: coding, cooking, carousing