48
ℂ"Cpukdng"Fqemgt物窾ᤅ秇ୗ" Build Docker images with Ansible: A half-blood approach William Yeh""茆ᐽ߽ 2016-08-27 http://bit.ly/halfblood-docker

從 Ansible 到 Docker:混血模式 (Build Docker images with Ansible: A half-blood approach)

Embed Size (px)

Citation preview

Build Docker images with Ansible: A half-blood approach

William Yeh 2016-08-27

http://bit.ly/halfblood-docker

Docker is great, but…

Dare you fully migrate your apps to Docker?

Q1

Co-exist?

Q2

The Old Way The Docker Way

Build pipeline

Configuration management

Deployment pipeline

Build pipeline

Configuration management

Deployment pipeline

inconvenient…

Reuse old, and apply to new…

The Old Way The Docker Way

Build pipeline

Configuration management

Deployment pipeline

Build pipeline

Configuration management

Deployment pipeline

… with minimal effort

… smooth learning curve

… ease of maintenance

… graceful degradation

… be a good citizen

My proposal:

Should fits into Docker model.

Should be of good quality.

… be a good citizenin the Docker world

Nginx wrk Boom json-server

built via package manager C compiler Go compiler Node.js

runtime

http://bit.ly/

halfblood-dock

er

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

1. Use CM to build image.

Base image: williamyeh/ansible

playbook

1. Use CM to build image.2. Adapt for Dockerized app.

Major1. Process execution model.2. Storage model (embrace immutable infra, please).3. Network model.Ref. "Dockerized app " http://william-yeh.github.io/docker-workshop/slides/dockerize.html

Minor4. Log handling.5. Init/upstart/systemd handling.6. Wrapper scripts as new entrypoint, if necessary.

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.

Base image: williamyeh/ansible:mini-debian8

Minimal configuration:the Ansible body will be removed when mission completed.

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

Base image: williamyeh/ansible:mini-alpine3

Ref:1. " Docker image "

http://william-yeh.github.io/docker-mini/2. " Alpine Linux" http://school.soft-arch.net/courses/docker-part2/lectures/885446

use Alpine Linux in Ansible playbooks.

playbook

nginx

Background info

• Written in C

• Can be installed via OS-level package manager(apt, yum, apk, …)

nginx

Debian

UbuntuCentOS

RHEL

Fedora

Alpine

1. Use CM to build image.nginx

playbook

1. Use CM to build image.nginx

1. Use CM to build image.nginx

├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ │ │ └─482d24d32738 Virtual Size: 210.5 MB │ │ │ └─5b8665aa9bbc Virtual Size: 241.2 MB Tags: nginx-1:latest

1. Use CM to build image.nginx

nginx1. Use CM to build image.2. Adapt for Dockerized app.

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.

nginx

williamyeh/ansible:mini-debian8

williamyeh/ansible:debian8-onbuild

Base image:

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.

nginx

├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ ├─cb9b094476db Virtual Size: 125.1 MB Tags: williamyeh/ansible:mini-debian8 │ │ └─68b7807607da Virtual Size: 135.9 MB Tags: nginx-3:latest │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ └─482d24d32738 Virtual Size: 210.5 MB │ └─5b8665aa9bbc Virtual Size: 241.2 MB Tags: nginx-1:latest

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

nginx

williamyeh/ansible:mini-alpine3

williamyeh/ansible:mini-debian8

Base image:

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

nginx

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

nginx

├─<missing> Virtual Size: 4.8 MB Tags: alpine:3.4 │ │ │ └─c887641f2cdb Virtual Size: 4.8 MB Tags: williamyeh/ansible:mini-alpine3 │ └─b57f615a2cd9 Virtual Size: 6.8 MB Tags: nginx-4:latest │ ├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ ├─cb9b094476db Virtual Size: 125.1 MB Tags: williamyeh/ansible:mini-debian8 │ │ └─68b7807607da Virtual Size: 135.9 MB Tags: nginx-3:latest │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ └─482d24d32738 Virtual Size: 210.5 MB │ └─5b8665aa9bbc Virtual Size: 241.2 MB Tags: nginx-1:latest

Should be of good quality.… be a good citizen in the Docker world

wrk

Background info

• Written in C

• Need to be compiled with gcc (& make).

wrk

https://github.com/wg/wrkModern HTTP benchmarking tool

1. Use CM to build image.wrk

playbook

1. Use CM to build image.wrk

1. Use CM to build image.wrk

├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ │ │ └─482d24d32738 Virtual Size: 210.5 MB │ └─e755d268bd41 Virtual Size: 341.0 MB Tags: wrk-1:latest

1. Use CM to build image.wrk

wrk1. Use CM to build image.2. Adapt for Dockerized app.

N/A

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.

wrk

williamyeh/ansible:mini-debian8

williamyeh/ansible:debian8-onbuild

Base image:

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.

wrk

├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ ├─cb9b094476db Virtual Size: 125.1 MB Tags: williamyeh/ansible:mini-debian8 │ │ └─980aa6023fda Virtual Size: 164.3 MB Tags: wrk-3:latest │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ └─482d24d32738 Virtual Size: 210.5 MB │ └─e755d268bd41 Virtual Size: 341.0 MB Tags: wrk-1:latest

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

wrk

williamyeh/ansible:mini-alpine3

williamyeh/ansible:mini-debian8

Base image:

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

wrk

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

wrk

├─<missing> Virtual Size: 4.8 MB Tags: alpine:3.4 │ │ │ └─c887641f2cdb Virtual Size: 4.8 MB Tags: williamyeh/ansible:mini-alpine3 │ └─531aed862a98 Virtual Size: 9.1 MB Tags: wrk-4:latest │ ├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ ├─cb9b094476db Virtual Size: 125.1 MB Tags: williamyeh/ansible:mini-debian8 │ │ └─980aa6023fda Virtual Size: 164.3 MB Tags: wrk-3:latest │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ └─482d24d32738 Virtual Size: 210.5 MB │ └─e755d268bd41 Virtual Size: 341.0 MB Tags: wrk-1:latest

Should be of good quality.… be a good citizen in the Docker world

Should be of good quality.… be a good citizen in the Docker world

Boomjson-server

Background info

• Written in Go

• Need to be compiled.

• Written in Node.js

• Need to install Node.js runtime.

Boom

json-server

├─<missing> Virtual Size: 4.8 MB Tags: alpine:3.4 │ │ │ └─c887641f2cdb Virtual Size: 4.8 MB Tags: williamyeh/ansible:mini-alpine3 │ │ │ ├─fc72e24cae3c Virtual Size: 14.5 MB Tags: williamyeh/boom:latest │ ││ └─bfd0226b6d74 Virtual Size: 27.5 MB Tags: williamyeh/json-server:latest

https://github.com/William-Yeh/docker-boom https://github.com/William-Yeh/docker-json-server

Conclusion

… whether you’d like to dive into Docker (fully or partially)

“Infrastructure as Code” mindset

… having alternatives is good

Consider Plan B

1. Use CM to build image.2. Adapt for Dockerized app.3. Slim down the image.4. Pursue for minimal image.

Nginx wrk Boom json-server

built via package manager C compiler Go compiler Node.js

runtime

(near-) minimal size (MiB) 6.8 9.1 14.51 27.48

http://bit.ly/halfblood-docker