-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
528 lines (365 loc) · 10.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
<!DOCTYPE html>
<html>
<head>
<title>From Dockerfiles to Ansible Container</title>
<meta charset="utf-8">
<style>
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
body { font-family: 'Droid Serif'; }
h1, h2, h3, h4 {
font-family: 'Yanone Kaffeesatz';
font-weight: normal;
}
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
.remark-slide-content { font-size: 1.6em; }
.remark-slide-content h1 { font-size: 2.4em; }
.remark-slide-content h2 { font-size: 2.0em; }
.remark-slide-content h3 { font-size: 1.6em; }
.remark-slide-content h4 { font-size: 1.2em; }
.remark-code { font-size: 0.977em; }
.remark-slide-number { font-size: 0.8em; }
.remark-slide-content ul { line-height: 1.4em; }
.small { font-size: 0.7em; }
.columns-3-ul ul { columns: 3; }
img { max-width: 100%; }
blockquote {
font-style: italic;
color: #777;
}
</style>
<script src="https://use.fontawesome.com/1a2bc43b60.js"></script>
</head>
<body>
<textarea id="source">
class: center, middle
# From Dockerfiles to Ansible Container
## Tomas Tomecek
---
# /whois "Tomáš Tomeček"
--
* hacker, developer, tinkerer, speaker, teacher
* contributing to *
* ~~ops~~ engineer
--
* Red Hat
* containerization team
???
* Ask who is dev and ops; initiate applause for ops.
---
# Agenda
1. Dockerfiles and docker-compose.
2. Ansible and Ansible Container.
3. Transition.
4. Ansible Container deep dive.
5. ~~demo~~
---
# Dockerfile
* A recipe to create container images.
--
* New file-format, different from standards like `json` and `yaml`.
--
* The format itself doesn't have a formal specification.
* [But has a pretty docs.](https://docs.docker.com/engine/reference/builder/)
???
* The only real implementation is part of dockerd.
* Not that easy to parse.
---
# Sample Dockerfile
```dockerfile
FROM registry.fedoraproject.org/fedora:26
RUN dnf install -y git python-pip gcc python-devel \
postgresql-devel redhat-rpm-config python2-pytest npm && \
npm install -g bower
ARG USER_ID=1000
RUN useradd -o -u ${USER_ID} django && \
mkdir -p /opt/app && \
chown django:django /opt/app
USER django
WORKDIR /opt/app
COPY ./requirements.txt /opt/app/
RUN pip install --user -r ./requirements.txt
COPY ./requirements-devel.txt /opt/app/
RUN ["pip", "install", "--user", "-r", "./requirements-devel.txt"]
```
???
* instruction syntax
* Dockerfile = metadata + content.
* backslash
* scripts
* run (can use only tools which are already in the container)
* layering (FS-changing insts create new layers)
* layers are immutable
* cache (often changing insts last)
* exec and command forms
---
# Sample Dockerfile (cont.)
```dockerfile
COPY ./install_static_data.sh /opt/app
COPY ./bower.json /opt/app
RUN ./install_static_data.sh
COPY . /opt/app/
USER root
RUN chown -R django:django .
USER django
# database needs to be set up before web can start serving requests
CMD sleep 7 && exec python /opt/app/manage.py runserver -v3 0.0.0.0:8000
```
---
# Ecosystem
* Service images from Docker Hub.
* Huge library
* Quality varies
* Freshness varies
???
* Some Docker Hub images are outdated and lack documentation.
--
* It's common to orchestrate with `docker-compose`
* hand-crafted docker-compose.yml
---
# Conclussion (the good)
* Wide usage.
* Good docs for the tooling.
* Docker Hub has a big collection of images.
* Actively developed.
* Easy to start.
---
# Conclussion (the bad)
* Can't easily parse dockerfiles.
* Development of Dockerfiles was kind-of frozen. (?)
* Dockerfiles are essentialy just shell scripts + metadata.
* You need to pick a vendor you trust for your images.
* Dockerfiles have some, old outstanding issues.
* Dockerfiles and `docker-compose` can only be used with docker containers.
???
* docker-compose
* Can't run commands easily in containers (e.g. database migration).
* Can't have dev/prod specific deployments within a single definition file.
* Service readiness checks are clunky.
* No variables.
* Start database migration after the database is up and accepting connections.
* `sleep` or poll
* can't provision vm, or a rkt container -- locked in to the docker platform
* dockerfiles are not trivial to master
* dockerfiles: caching, layering, COPY && chown && chmod, cannot remove metadata
* builder: mount during build
---
# Conclussion (the bad)
* Can't easily parse dockerfiles.
* Development of Dockerfiles was kind-of frozen. (?)
* Dockerfiles are essentialy just shell scripts + metadata.
* You need to pick a vendor you trust for your images.
* Dockerfiles have some, old outstanding issues.
* ~~Dockerfiles and `docker-compose` can only be used with docker containers.~~
* Docker platform and kubernetes
---
# More complex script example
--
```bash
RUN set -eux; \
\
# this "case" statement is generated via "update.sh"
%%ARCH-CASE%%; \
\
url="https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \
wget -O go.tgz "$url"; \
echo "${goRelSha256} *go.tgz" | sha256sum -c -; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz; \
\
if [ "$goRelArch" = 'src' ]; then \
echo >&2; \
echo >&2 'error: UNIMPLEMENTED'; \
echo >&2 'TODO install golang-any from jessie-backports for GOROOT_BOOTSTRAP (and uninstall after build)'; \
echo >&2; \
exit 1; \
fi; \
```
---
# More complex script example (cont.)
```bash
\
export PATH="/usr/local/go/bin:$PATH"; \
go version
```
Source: https://github.com/docker-library/golang/blob/master/Dockerfile-debian.template#L14
---
# Ansible
* Automation platform.
* No daemons — easy to set up.
* Machine and human friendly language — yaml.
* Powerful.
* Hundreds of modules.
???
* powerful thanks to jinja
---
# Ansible glossary
* Tasks
* Playbooks
* Plays
* Roles
---
# Transition
* Good
* Full Ansible power.
* You can utilize your (existing) Ansible roles.
* Those roles can deploy any artifacts.
* One consistent tool to manage whole infrastructure.
* Bad
* shell → Ansible
* You may need to learn new things. (is this actually bad?)
* Some Ansible tasks are more complex than Dockerfile instructions.
???
---
# COPY vs copy module
```dockerfile
COPY file /path/inside/image
```
vs.
```yaml
- name: Install file
copy:
src: file
dest: /path/inside/image
```
---
# COPY vs copy module
```dockerfile
COPY file /path/inside/image
*RUN chmod 0644 /path/inside/image && chown app /path/inside/image
```
vs.
```yaml
- name: Install file
copy:
src: file
dest: /path/inside/image
* owner: app
* mode: 0644
```
---
# Ansible Container tool
* `github.com/ansible/ansible-container`
* Building container images from Ansible roles.
* Utilize existing Ansible Galaxy roles.
* Complete management of containerized projects.
* Dev environment overrides.
* Adds a single layer on top of your base image by default.
* Dockerfile → Ansible Role converter.
* Doesn't require python in target image.
* Doesn't require ansible on your host.
???
* Not just images, deployable units!
* conductor container
---
# Workflow
1. `init`
2. `install`
3. `build`
4. `run`
5. `push`
6. `deploy`
---
# container.yml
* Single definition of the application.
* Build images.
* How to run in development.
* How to deploy to a production environment.
* ansible-container configuration
--
* https://github.com/chouseknecht/django-gulp-nginx/blob/master/container.yml
---
# container.yml
```yaml
defaults:
POSTGRES_USER: django
POSTGRES_PASSWORD: sesame
POSTGRES_DB: django
DJANGO_ROOT: /django
DJANGO_USER: django
DJANGO_PORT: 8080
DJANGO_VENV: /venv
NODE_USER: node
NODE_HOME: /node
NODE_ROOT: ''
GULP_DEV_PORT: 8080
```
---
# container.yml (cont.)
```yaml
services:
django:
from: 'centos:7'
roles:
- role: django-gunicorn
environment:
DATABASE_URL: 'pgsql://{{ POSTGRES_USER }}:{{ POSTGRES_PASSWORD }}@postgresql:5432/{{ POSTGRES_DB }}'
DJANGO_ROOT: '{{ DJANGO_ROOT }}'
DJANGO_VENV: '{{ DJANGO_VENV }}'
expose:
- '{{ DJANGO_PORT }}'
working_dir: '{{ DJANGO_ROOT }}'
links:
- postgresql
user: '{{ DJANGO_USER }}'
command: ['/usr/bin/dumb-init', '{{ DJANGO_VENV }}/bin/gunicorn', -w, '2', -b, '0.0.0.0:{{ DJANGO_PORT }}', 'project.wsgi:application']
entrypoint: [/usr/bin/entrypoint.sh]
```
---
# container.yml
## Development overrides
```yaml
django:
dev_overrides:
volumes:
- '$PWD:{{ DJANGO_ROOT }}'
command: [/usr/bin/dumb-init, '{{ DJANGO_VENV }}/bin/python', manage.py, runserver, '0.0.0.0:{{ DJANGO_PORT }}']
```
```yaml
nginx:
dev_overrides:
ports: []
command: /bin/false
```
---
class: center, middle
# We need your feedback!
???
* still work in progress
* who have already used ansible-container?
* what's your use case?
* how complicated your setup is?
* would you join the sig?
---
# Conclussion
* One tool can't fit everyone.
* Pick the one which suits you best.
* `ansible-container` aiming to hit [1.0](https://github.com/ansible/ansible-container/blob/develop/docs/rst/roadmaps/roadmap_1_0_0.rst) soon.
* `github.com/moby/buildkit`
* [Linux System Roles](https://github.com/linux-system-roles)
???
* purpose of AC is to leverage ansible even more for people who already invested in it
* dockerfiles have limitations
* upstream doesn't address them
* but they are aware
* ansible-container is young
---
# Thank you!
* <span class="fa fa-github-square"></span> [ansible/ansible-container](https://github.com/ansible/ansible-container)
* <span class="fa fa-github-square"></span> [ansible/ansible-container-demo](https://github.com/ansible/ansible-container-demo)
* `#ansible-container` channel on [irc.freenode.net](https://freenode.net/)
* [https://groups.google.com/forum/#!forum/ansible-container](https://groups.google.com/forum/#!forum/ansible-container)
* <span class="fa fa-github-square"></span> [TomasTomecek/open-source-summit-2017-talk](https://github.com/TomasTomecek/open-source-summit-2017-talk)
* <span class="fa fa-twitter-square"></span> @TomasTomec
</textarea>
<script src="remark.js">
</script>
<script>
var slideshow = remark.create({
ratio: '16:9',
highlightLines: true
});
</script>
</body>
</html>