SlideShare uma empresa Scribd logo
1 de 52
Baixar para ler offline
IMPROVING WORDPRESS DEVELOPMENT AND
DEPLOYMENTS WITH DOCKER AND CI/CD
Brett G. Palmer
Twitter: @brettgpalmer
LinkedIn: brettgpalmer
Introductions
Career Background
• Independent Software Developer & Entrepreneur
• Promoting open source and technology
• Currently: Contractor for State of Utah - DTS/DWS
• Helping Migrate to Open Source Eligibility System
• WordPress Development last 7 years
• Organizer for SLC DevOps Days and DevOpsUT Meetup
3
Development Interests
• Enterprise Java Development - Spring Cloud
• Mobile Development
• Ionic Mobile Framework
• Chatbots for Alexa, Google Home, FB Messenger
• WordPress REST API integration
• WordPress Hosting and Deployments
4
Current Tech Interests
• Entrepreneur helping small businesses
• Mobile business apps
• Website hosting
• Software Recruiter
• Helping developers gain their independence
• Development training
• Programming, DevOps, Testing
5
Favorite Job
My Pets
What’s the
Problem?
WordPress Security Concerns
• Sucuri 2018 Reports
• 90% CMS sites were WordPress
• Under 5% for Magento, Joomla, Drupal, etc
• Enterprises avoid adopting WordPress
• Frequently affects small businesses
9
Common Reasons for Hacks
• Outdated WordPress Installs
• Unprotected Access to WordPress Admin
• Insecure/outdated plugins or themes
• Incorrect File Permissions
10
WordPress Deployment Errors
• Manual steps from testing to production
• Frequent errors with deployments
• “Works on my machine” syndrome
11
Intro Docker
and
Containers
Docker Containers Intro
• Standard unit of software
• Packages code and dependencies together
• Minimal amount necessary to run
• Run quickly and reliably
• Containers are ephemeral (disposable)
• Pets vs Cattle
How
Containers
are Helpful
How Containers Can Help
• WordPress updates are easier and more frequent
• Consistent deployments to Dev, Test, and Prod
• Lock down plugins and themes
• Containers are ephemeral (short lasting) - any changes
to running container are temporary.
16
Stateless Containers
for WordPress
Approach
The Approach
• Create consistent WordPress environment
• Dev, Test, and Prod
• Started 2 years ago and evolved as needed
• Many ways to solve the same problem
• More WP containers available today
18
Technologies Used
• Docker: creates WordPress containers
• Docker Compose: integrates dependent services
• Nginx: Reverse proxy and TLS/SSL certificates hosting
• WordPress Site Container (Primary)
• WP Offload Media Light Amazon S3 and Cloudfront
• MySQL Database
• PhpMyAdmin container (development only)
• Kubernetes (future deployments)
19
Solution: Three Containers
• WordPress Base Container
• WordPress CLI Container
• Nginx container
• WordPress Site Container (Primary)
20
Layered Diagram Here
Php:fpm Image
wp-base
wp-cli
wp-nginx
wp-site
Each layer inherits
from the image above
Primary container
Smaller layers == faster
deployments
WordPress Base Container
• Depends on php:fpm (FastCGI Process Manage)
• Installs PHP extensions and makes php settings
• Downloads WordPress version (e.g. 5.2.x)
• Unpacks WordPress and sets file permission
• Sets up Docker env variables
• WORDPRESS_DB_NAME, USER, PASSWORD, HOST
• WP_DEBUG settings
22
Dockerfile: Base Container
ENV WORDPRESS_VERSION 5.2.3
ENV WORDPRESS_SHA1 5efd37148788f3b14b295b2a9bf48a1a467aa303
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-$
{WORDPRESS_VERSION}.tar.gz 
&& echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - 
&& tar -xzf wordpress.tar.gz -C /usr/src/ 
&& rm wordpress.tar.gz 
&& chown -R www-data:www-data /usr/src/wordpress
# extract wordpress on build
RUN tar cf - --one-file-system -C /usr/src/wordpress . | tar xf -
23
WordPress CLI Container
• Depends on WordPress base container
• Downloads current wpcli tool
• Sets file permissions for utility
24
WordPress Nginx Container
• Depends on wp-stateless-cli image
• Downloads nginx libraries
• Sets configurations for nginx
• Sets permissions to run nginx
25
Dockerfile: Nginx Container
# install nginx
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
#########################################################################
#####################
# NGINX SETUP
#########################################################################
#####################
RUN rm -r /etc/nginx/sites-enabled/*
ADD default.conf /etc/nginx/sites-enabled/default.conf
ADD wordpress.conf /etc/nginx/global/wordpress.conf
ADD restrictions.conf /etc/nginx/global/restrictions.conf
26
WordPress Site Container
• Depends on wp-stateless-nginx image
• Sets memory, upload_max_filesize, etc
• Adds default and custom plugins to image
• Adds custom theme to image
27
Dockerfile: Site Container
RUN /plugins.sh /plugins/base
RUN /plugins.sh /plugins/security
# Delete Plugins script and plugin installation folder
RUN rm /plugins.sh && rm /plugins -r
# ADD OWN CUSTOM PLUGINS
ADD ./plugins/my-plugin /var/www/html/wp-content/plugins/my-plugin
##############################################################################################
# WORDPRESS Divid Theme Setup
##############################################################################################
COPY ./themes/Divi.zip /var/www/html/wp-content/themes
RUN unzip /var/www/html/wp-content/themes/Divi.zip -d /var/www/html/wp-content/themes 
&& chown -R www-data:www-data /var/www/html/wp-content/themes 
&& rm /var/www/html/wp-content/themes/Divi.zip
28
Developer Process
• Works with local wp-stateless-site repo
• Mounts local volume for development
• my-plugin directory
• my-theme directory
• Tests locally
• Commits changes into develop branch
• Push changes to remote Git server
29
Build Process
• Jenkins polls for repo changes
• Runs the build for wp-stateless-site
• Adds plugins
• Adds themes
• Pushes images to docker hub
• Pipeline runs script to deploy to test environment
• Runs automated selenium tests
30
Developer/Designer Workflow
Team Workflow
Docker Compose Deployment
Continuous
Integration/
Delivery/
Deployment
CI/CD Definitions
• Continuous Integration:
• Executes Build
• Runs unit and integration tests
• Continuous Delivery
• Insure software ready for deployment
• Tags artifacts
• Pushes to artifact repository (e.g. docker hub)
• Continuous Deployment (after all tests pass)
• Automated deployment of software to production
35
Continuous Integration and Continuous Delivery
Deployment Pipeline
• Jenkins polls for repo changes
• Runs the build for wp-stateless-site
• Adds plugins
• Adds themes
• Pushes images to docker hub
• Pipeline runs script to deploy to test environment
• Runs automated selenium tests
37
Blue/Green Deployments
• Blue environment is live
• Push new deployment to Green env
• Test Green environment
• Deployment verified switch to Green
• No downtime for customers
Blue/Green Deployment with No Downtime
Challenges
Stateless Vs Traditional
1. Image is ephemeral/immutable
(doesn’t change)
2. Software is built and deployed
3. All environments have exactly
same software
4. Production is not a testing
environment
42
1. Setup repeated for each
environment
2. Differences between
environments
3. Production is a testing
environment
Stateless WP Traditional WP
WordPress Development Evolution
• WordPress Headless CMS
• Gutenberg Blocks
• ReactJS
• More integration requires standardized
build and deployments
Database Persistence
• Containers should be ephemeral
• Databases are persistent and changing
• Docker volumes can work
• Recommended: Use DB services outside
of containers
K8s Deployment (Future)
Summary
Containers: Pros and Cons
• Pros
• Docker can improve WordPress Development and
Deployments
• Docker can help improve security
• Cons
• Lose some production flexibility
• Solution is not trivial
References
• WordPress Security Concerns
• https://sucuri.net/reports/2018-hacked-website-report/
• Docker Images
• https://cloud.docker.com/u/brettgpalmer/repository/
list
• Original Idea from Michael Haessig (2017)
• https://github.com/michaelhaessig/wordpress-
stateless
Technology References
• Jenkins CI
• https://hub.docker.com/_/jenkins/
• https://jenkins.io/
• CircleCI: https://circleci.com
• Travis CI:  https://travis-ci.com/
Technology References
• Docker/Docker Compose
• Kubernetes: https://kubernetes.io/docs/
home/
• php-fpm: https://php-fpm.org/
• Book: Continuous Delivery by Jez Humble &
David Farley
Q&A
CONTACT INFO
Brett G. Palmer
Email: bpalmer@palmersoftware.com
Twitter: @brettgpalmer
LinkedIn: brettgpalmer
• Meetups: DevOpsUT, Ionic, Tech Startups
• Skiing Favorites: Solitude, Snowbird,
anywhere
• Downtown SLC (M-Th) or Utah County

Mais conteúdo relacionado

Mais procurados

DCSF 19 Modernizing Insurance with Docker Enterprise: The Physicians Mutual ...
DCSF 19 Modernizing Insurance with Docker Enterprise:  The Physicians Mutual ...DCSF 19 Modernizing Insurance with Docker Enterprise:  The Physicians Mutual ...
DCSF 19 Modernizing Insurance with Docker Enterprise: The Physicians Mutual ...
Docker, Inc.
 
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWSAutomated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Bamdad Dashtban
 

Mais procurados (20)

Docker Registry V2
Docker Registry V2Docker Registry V2
Docker Registry V2
 
DCSF19 Container Security: Theory & Practice at Netflix
DCSF19 Container Security: Theory & Practice at NetflixDCSF19 Container Security: Theory & Practice at Netflix
DCSF19 Container Security: Theory & Practice at Netflix
 
JUC Europe 2015: Scaling Your Jenkins Master with Docker
JUC Europe 2015: Scaling Your Jenkins Master with DockerJUC Europe 2015: Scaling Your Jenkins Master with Docker
JUC Europe 2015: Scaling Your Jenkins Master with Docker
 
Developer Experience Cloud Native - Become Efficient and Achieve Parity
Developer Experience Cloud Native - Become Efficient and Achieve ParityDeveloper Experience Cloud Native - Become Efficient and Achieve Parity
Developer Experience Cloud Native - Become Efficient and Achieve Parity
 
Neues aus dem Docker-Universum
Neues aus dem Docker-UniversumNeues aus dem Docker-Universum
Neues aus dem Docker-Universum
 
DCSF 19 Modernizing Insurance with Docker Enterprise: The Physicians Mutual ...
DCSF 19 Modernizing Insurance with Docker Enterprise:  The Physicians Mutual ...DCSF 19 Modernizing Insurance with Docker Enterprise:  The Physicians Mutual ...
DCSF 19 Modernizing Insurance with Docker Enterprise: The Physicians Mutual ...
 
How Docker simplifies CI/CD
How Docker simplifies CI/CDHow Docker simplifies CI/CD
How Docker simplifies CI/CD
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
 
Shipping NodeJS with Docker and CoreOS
Shipping NodeJS with Docker and CoreOSShipping NodeJS with Docker and CoreOS
Shipping NodeJS with Docker and CoreOS
 
DockerCon SF 2015: Docker in the New York Times Newsroom
DockerCon SF 2015: Docker in the New York Times NewsroomDockerCon SF 2015: Docker in the New York Times Newsroom
DockerCon SF 2015: Docker in the New York Times Newsroom
 
Persistent storage tailored for containers
Persistent storage tailored for containersPersistent storage tailored for containers
Persistent storage tailored for containers
 
Node.js Rocks in Docker for Dev and Ops
Node.js Rocks in Docker for Dev and OpsNode.js Rocks in Docker for Dev and Ops
Node.js Rocks in Docker for Dev and Ops
 
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
 
SD DevOps Meet-up - Jenkins 2.0 and Pipeline-as-Code
SD DevOps Meet-up - Jenkins 2.0 and Pipeline-as-CodeSD DevOps Meet-up - Jenkins 2.0 and Pipeline-as-Code
SD DevOps Meet-up - Jenkins 2.0 and Pipeline-as-Code
 
Practical Container Security by Mrunal Patel and Thomas Cameron, Red Hat
Practical Container Security by Mrunal Patel and Thomas Cameron, Red HatPractical Container Security by Mrunal Patel and Thomas Cameron, Red Hat
Practical Container Security by Mrunal Patel and Thomas Cameron, Red Hat
 
Docker Registry + Basic Auth
Docker Registry + Basic AuthDocker Registry + Basic Auth
Docker Registry + Basic Auth
 
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWSAutomated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
 
Docker Meetup 08 03-2016
Docker Meetup 08 03-2016Docker Meetup 08 03-2016
Docker Meetup 08 03-2016
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for Testing
 
Drone CI
Drone CIDrone CI
Drone CI
 

Semelhante a Improving WordPress Development and Deployments with Docker

Docker Birthday #3 Slides - Overview
Docker Birthday #3 Slides - OverviewDocker Birthday #3 Slides - Overview
Docker Birthday #3 Slides - Overview
Chris Ciborowski
 
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
dotCloud
 

Semelhante a Improving WordPress Development and Deployments with Docker (20)

Containers, microservices and serverless for realists
Containers, microservices and serverless for realistsContainers, microservices and serverless for realists
Containers, microservices and serverless for realists
 
Containers and Microservices for Realists
Containers and Microservices for RealistsContainers and Microservices for Realists
Containers and Microservices for Realists
 
Containers and microservices for realists
Containers and microservices for realistsContainers and microservices for realists
Containers and microservices for realists
 
Preparing your dockerised application for production deployment
Preparing your dockerised application for production deploymentPreparing your dockerised application for production deployment
Preparing your dockerised application for production deployment
 
Docker for the enterprise
Docker for the enterpriseDocker for the enterprise
Docker for the enterprise
 
Morning Coffee - Windows Server 2016
Morning Coffee - Windows Server 2016Morning Coffee - Windows Server 2016
Morning Coffee - Windows Server 2016
 
Docker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker SlidesDocker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker Slides
 
Docker Birthday #3 Slides - Overview
Docker Birthday #3 Slides - OverviewDocker Birthday #3 Slides - Overview
Docker Birthday #3 Slides - Overview
 
321 codeincontainer brewbox
321 codeincontainer brewbox321 codeincontainer brewbox
321 codeincontainer brewbox
 
SQL Server in DevOps Town Hall Webinar
SQL Server in DevOps Town Hall WebinarSQL Server in DevOps Town Hall Webinar
SQL Server in DevOps Town Hall Webinar
 
Introduction to Containers - SQL Server and Docker
Introduction to Containers - SQL Server and DockerIntroduction to Containers - SQL Server and Docker
Introduction to Containers - SQL Server and Docker
 
Get acquainted with the new ASP.Net 5
Get acquainted with the new ASP.Net 5Get acquainted with the new ASP.Net 5
Get acquainted with the new ASP.Net 5
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Webinar Docker Tri Series
Webinar Docker Tri SeriesWebinar Docker Tri Series
Webinar Docker Tri Series
 
Docker presentation for sharing
Docker presentation   for sharingDocker presentation   for sharing
Docker presentation for sharing
 
Webinar : Docker in Production
Webinar : Docker in ProductionWebinar : Docker in Production
Webinar : Docker in Production
 
Dockers and kubernetes
Dockers and kubernetesDockers and kubernetes
Dockers and kubernetes
 
Docker & aPaaS: Enterprise Innovation and Trends for 2015
Docker & aPaaS: Enterprise Innovation and Trends for 2015Docker & aPaaS: Enterprise Innovation and Trends for 2015
Docker & aPaaS: Enterprise Innovation and Trends for 2015
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Improving WordPress Development and Deployments with Docker

  • 1. IMPROVING WORDPRESS DEVELOPMENT AND DEPLOYMENTS WITH DOCKER AND CI/CD Brett G. Palmer Twitter: @brettgpalmer LinkedIn: brettgpalmer
  • 3. Career Background • Independent Software Developer & Entrepreneur • Promoting open source and technology • Currently: Contractor for State of Utah - DTS/DWS • Helping Migrate to Open Source Eligibility System • WordPress Development last 7 years • Organizer for SLC DevOps Days and DevOpsUT Meetup 3
  • 4. Development Interests • Enterprise Java Development - Spring Cloud • Mobile Development • Ionic Mobile Framework • Chatbots for Alexa, Google Home, FB Messenger • WordPress REST API integration • WordPress Hosting and Deployments 4
  • 5. Current Tech Interests • Entrepreneur helping small businesses • Mobile business apps • Website hosting • Software Recruiter • Helping developers gain their independence • Development training • Programming, DevOps, Testing 5
  • 9. WordPress Security Concerns • Sucuri 2018 Reports • 90% CMS sites were WordPress • Under 5% for Magento, Joomla, Drupal, etc • Enterprises avoid adopting WordPress • Frequently affects small businesses 9
  • 10. Common Reasons for Hacks • Outdated WordPress Installs • Unprotected Access to WordPress Admin • Insecure/outdated plugins or themes • Incorrect File Permissions 10
  • 11. WordPress Deployment Errors • Manual steps from testing to production • Frequent errors with deployments • “Works on my machine” syndrome 11
  • 13. Docker Containers Intro • Standard unit of software • Packages code and dependencies together • Minimal amount necessary to run • Run quickly and reliably • Containers are ephemeral (disposable) • Pets vs Cattle
  • 14.
  • 16. How Containers Can Help • WordPress updates are easier and more frequent • Consistent deployments to Dev, Test, and Prod • Lock down plugins and themes • Containers are ephemeral (short lasting) - any changes to running container are temporary. 16
  • 18. The Approach • Create consistent WordPress environment • Dev, Test, and Prod • Started 2 years ago and evolved as needed • Many ways to solve the same problem • More WP containers available today 18
  • 19. Technologies Used • Docker: creates WordPress containers • Docker Compose: integrates dependent services • Nginx: Reverse proxy and TLS/SSL certificates hosting • WordPress Site Container (Primary) • WP Offload Media Light Amazon S3 and Cloudfront • MySQL Database • PhpMyAdmin container (development only) • Kubernetes (future deployments) 19
  • 20. Solution: Three Containers • WordPress Base Container • WordPress CLI Container • Nginx container • WordPress Site Container (Primary) 20
  • 21. Layered Diagram Here Php:fpm Image wp-base wp-cli wp-nginx wp-site Each layer inherits from the image above Primary container Smaller layers == faster deployments
  • 22. WordPress Base Container • Depends on php:fpm (FastCGI Process Manage) • Installs PHP extensions and makes php settings • Downloads WordPress version (e.g. 5.2.x) • Unpacks WordPress and sets file permission • Sets up Docker env variables • WORDPRESS_DB_NAME, USER, PASSWORD, HOST • WP_DEBUG settings 22
  • 23. Dockerfile: Base Container ENV WORDPRESS_VERSION 5.2.3 ENV WORDPRESS_SHA1 5efd37148788f3b14b295b2a9bf48a1a467aa303 # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-$ {WORDPRESS_VERSION}.tar.gz && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - && tar -xzf wordpress.tar.gz -C /usr/src/ && rm wordpress.tar.gz && chown -R www-data:www-data /usr/src/wordpress # extract wordpress on build RUN tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - 23
  • 24. WordPress CLI Container • Depends on WordPress base container • Downloads current wpcli tool • Sets file permissions for utility 24
  • 25. WordPress Nginx Container • Depends on wp-stateless-cli image • Downloads nginx libraries • Sets configurations for nginx • Sets permissions to run nginx 25
  • 26. Dockerfile: Nginx Container # install nginx RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/* ######################################################################### ##################### # NGINX SETUP ######################################################################### ##################### RUN rm -r /etc/nginx/sites-enabled/* ADD default.conf /etc/nginx/sites-enabled/default.conf ADD wordpress.conf /etc/nginx/global/wordpress.conf ADD restrictions.conf /etc/nginx/global/restrictions.conf 26
  • 27. WordPress Site Container • Depends on wp-stateless-nginx image • Sets memory, upload_max_filesize, etc • Adds default and custom plugins to image • Adds custom theme to image 27
  • 28. Dockerfile: Site Container RUN /plugins.sh /plugins/base RUN /plugins.sh /plugins/security # Delete Plugins script and plugin installation folder RUN rm /plugins.sh && rm /plugins -r # ADD OWN CUSTOM PLUGINS ADD ./plugins/my-plugin /var/www/html/wp-content/plugins/my-plugin ############################################################################################## # WORDPRESS Divid Theme Setup ############################################################################################## COPY ./themes/Divi.zip /var/www/html/wp-content/themes RUN unzip /var/www/html/wp-content/themes/Divi.zip -d /var/www/html/wp-content/themes && chown -R www-data:www-data /var/www/html/wp-content/themes && rm /var/www/html/wp-content/themes/Divi.zip 28
  • 29. Developer Process • Works with local wp-stateless-site repo • Mounts local volume for development • my-plugin directory • my-theme directory • Tests locally • Commits changes into develop branch • Push changes to remote Git server 29
  • 30. Build Process • Jenkins polls for repo changes • Runs the build for wp-stateless-site • Adds plugins • Adds themes • Pushes images to docker hub • Pipeline runs script to deploy to test environment • Runs automated selenium tests 30
  • 35. CI/CD Definitions • Continuous Integration: • Executes Build • Runs unit and integration tests • Continuous Delivery • Insure software ready for deployment • Tags artifacts • Pushes to artifact repository (e.g. docker hub) • Continuous Deployment (after all tests pass) • Automated deployment of software to production 35
  • 36. Continuous Integration and Continuous Delivery
  • 37. Deployment Pipeline • Jenkins polls for repo changes • Runs the build for wp-stateless-site • Adds plugins • Adds themes • Pushes images to docker hub • Pipeline runs script to deploy to test environment • Runs automated selenium tests 37
  • 38.
  • 39. Blue/Green Deployments • Blue environment is live • Push new deployment to Green env • Test Green environment • Deployment verified switch to Green • No downtime for customers
  • 42. Stateless Vs Traditional 1. Image is ephemeral/immutable (doesn’t change) 2. Software is built and deployed 3. All environments have exactly same software 4. Production is not a testing environment 42 1. Setup repeated for each environment 2. Differences between environments 3. Production is a testing environment Stateless WP Traditional WP
  • 43. WordPress Development Evolution • WordPress Headless CMS • Gutenberg Blocks • ReactJS • More integration requires standardized build and deployments
  • 44. Database Persistence • Containers should be ephemeral • Databases are persistent and changing • Docker volumes can work • Recommended: Use DB services outside of containers
  • 47. Containers: Pros and Cons • Pros • Docker can improve WordPress Development and Deployments • Docker can help improve security • Cons • Lose some production flexibility • Solution is not trivial
  • 48. References • WordPress Security Concerns • https://sucuri.net/reports/2018-hacked-website-report/ • Docker Images • https://cloud.docker.com/u/brettgpalmer/repository/ list • Original Idea from Michael Haessig (2017) • https://github.com/michaelhaessig/wordpress- stateless
  • 49. Technology References • Jenkins CI • https://hub.docker.com/_/jenkins/ • https://jenkins.io/ • CircleCI: https://circleci.com • Travis CI:  https://travis-ci.com/
  • 50. Technology References • Docker/Docker Compose • Kubernetes: https://kubernetes.io/docs/ home/ • php-fpm: https://php-fpm.org/ • Book: Continuous Delivery by Jez Humble & David Farley
  • 51. Q&A
  • 52. CONTACT INFO Brett G. Palmer Email: bpalmer@palmersoftware.com Twitter: @brettgpalmer LinkedIn: brettgpalmer • Meetups: DevOpsUT, Ionic, Tech Startups • Skiing Favorites: Solitude, Snowbird, anywhere • Downtown SLC (M-Th) or Utah County