42
Scalable Magento Development with Containers Speaker Tran Hiep - GEM company

#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Embed Size (px)

Citation preview

Page 1: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Scalable Magento Development with Containers

Speaker Tran Hiep - GEM company

Page 2: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Challenges In Magento Development

Page 3: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Hosting Magento is simple. Right?

Page 4: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Hosting Magento is simple. Right? Nope!

Page 5: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Challenge #1: Knowledge Transfer«I don’t know how to configure Nginx. My leader always does that. But he is currently on vacation. -> Knowledge Monopolies

Page 6: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Challenge #2: Parallelization«Don’t touch the integration environment the next days – we are going to test feature xyz!»

-> Parallelization

Page 7: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Challenge #3: Operations«How could that have ever worked on the integration environment?!»

-> Operations

Page 8: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Challenge #3: Operations Keeping environments in sync is hard.

Page 9: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Challenge #4: Scaling«Just a little something for the current sprint, Manager: We need a new integration and production for the new project. asap!»

- > Scaling

Page 10: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Introduction to Docker

Container virtualization made easy

Page 11: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

What is Docker?Docker automates the deployment of applications inside containers

Based on Linux technologies

Avoids the overhead of classical virtual machines

Small and portable containers

Ideal for application packaging

Page 12: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Solving the Challenges1.Knowledge Monopolies

2.Parallelization

3.Operations

4.Scaling

Page 13: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Solving Knowledge MonopoliesDocker allows you to

Split your infrastructure components into immutable units of execution by using standard Docker images such as Nginx, PHP and MySQL

Make your software configuration transparent and traceable with Dockerfiles

Combine all your software dependencies into a single docker-compose.yml file

Page 14: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Leveraging Docker Standard ImagesDocker provides a long list of standard images that are maintained by Docker or the software authors

Operating System Images● Alpine● Ubuntu● Debian● CentOS● …

Software components● PHP● MySQL● Nginx● Redis● …

Page 15: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Docker Standard ImagesSoftware components

PHP

MySQL

Nginx

Redis

...

Page 16: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Infrastructure definition with Dockerfiles1.Base image

2.Setup commands

3.Expose ports

4.Entry point

FROM ubuntu:latest

RUN apt-get update && apt-get install nginx

EXPOSE 80 443

CMD ["nginx", "-g", "daemon off;"]

Page 17: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Running a Default Nginx Container$ docker run –p 8080:80 nginx:1.9

Page 18: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Customization via Docker VolumesCustomizing dockers container with volumes:

$ docker run -p 8080:80 -v `pwd`/custom-content:/usr/share/nginx/html nginx:1.9

Page 19: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Docker ComposeMulti-container orchestration

Define infrastructure setups

YAML-based config format

Define

Images

Ports

Volumes

version: '2'

services:web:

image: nginx:stable-alpineports: 8080:80volumes_from: php:rophp:image: php:7.0-fpmvolumes: ./web:/var/www/html

Page 20: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Solving Knowledge MonopoliesAutomate the environment setup with Docker Compose

Page 21: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Solving Knowledge MonopoliesAutomate the environment setup with Docker Compose

docker-compose.yml docker-compose.yml

Page 22: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Solving ParallelizationEnable Parallelization

Combination of tools and processes:

Docker Compose

Git

Composer

Git-flow

Cloud hosting

-> Develop and test features in parallel

Combine infrastructure and software

Branch on feature levelCreate feature instances for testing on-the-fly

Page 23: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Enable ParallelizationGet rid of bottlenecks

Page 24: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Enable ParallelizationGet rid of bottlenecks ... by creating feature instances

Page 25: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Enable ParallelizationCreate feature-instance:

Page 26: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Solving OperationsEase Operations

Docker and Docker Compose will reduce operation efforts:

Better quality. All environments look the same

Easier patching. Download the latest Docker images and restart

Easier handling. All projects can be controlled by the same commands

Easier handover. Between development and operations team(s)

Page 27: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Ease Operations: Deployment & Patching1.Copy the new project version to production

2.Pull the latest Docker images

3.Run the new project version

docker-compose.yml docker-compose.yml

Page 28: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Solving ScalingScaling can mean different things:

More Load

More Features

More Businesses

Page 29: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

ScalingWhat can you do to scale?

Add more developers and testers to your team

Optimize the infrastructure and code

Add more RAM, CPU and storage to your existing servers

Add new servers to your production environment

Page 30: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Complexity with Automation

Page 31: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Complexity without Automation

Page 32: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Scaling with DockerMore Load: Scale horizontally or vertically

More Features: We can now parallelize our development

More Businesses: Copy an existing project and customize it

Still not easy. But easier than without it!

Page 33: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

CombiningInfrastructure & Code

Project structure of a dockerized Magento shop

Page 34: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Combining Code + Infrastructure- src

- app

- bin

- vendor

- pub

- composer.json

- index.php

- env- bin

- config

- nginx

- php

- docker-compose.dev.yml

- docker-compose.staging.yml

- docker-compose.prod.yml

Code

Infrastructure

Page 35: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Handling different environments- src

- env- config

- mysql

- nginx

- php-dev

- php-prod

- docker-compose.dev.yml

- docker-compose.prod.yml

Configs for other environmentsshould also be tracked in thesame project, e.g

● The production config of your PHP container should not contain Xdebug

● Usage of a central MySQL cluster on production

Page 36: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Handling different environmentsUsing a different Docker Compose file:

> docker-compose -f docker-compose.prod.yml up -d

> docker-compose -f docker-compose.dev.yml up -d

Page 37: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Development EnvironmentThe dockerized development process works on Linux, OS X & Windows.

All you need is:

– Docker Machine (only for Mac and Windows)

– Docker & Docker Compose

– Git + PHP + Composer

+ An editor or IDE of your choice

Page 38: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Docker for LinuxInstall Docker:

> curl -fsSL https://get.docker.com/ | sh

and Docker Compose:

> curl -L https://github.com/docker/compose/releases/download/1.7.0-

rc1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-

compose chmod +x /usr/local/bin/docker-compose

Page 39: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Docker for Windows and MacInstall the Docker Toolbox to use Docker on Mac or Windows

Page 40: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

DemoDockerizing Magento 2

Page 41: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

Docker Compose Examples

● https://github.com/fballiano/docker-magento2

● https://github.com/meanbee/docker-magento2

Page 42: #3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers

ReferencesAuthor : Andreas Koch

https://imagine.magento.com/sites/default/files/Scalable-Magento-Development-with-Docker.pdf