infrastructure = code - 1 year later

23
Infrastructure = Code 1 year later Christian Ortner FINDOLOGIC GmbH

Upload: christian-ortner

Post on 23-Jan-2018

50 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Infrastructure = code - 1 year later

Infrastructure = Code1 year later

Christian OrtnerFINDOLOGIC GmbH

Page 2: Infrastructure = code - 1 year later

Y though?

● Automate setup / deployment

● Reduce human error

● Fail, fix, test, repeat

Page 3: Infrastructure = code - 1 year later

The DevOps Good

● Dev and Ops are inseparable these days

● Installing Dependencies, configuring stack

● Reduce friction and latency

● Understand deployment complexity

● No more local changes on servers

Page 4: Infrastructure = code - 1 year later

Our stack

Page 5: Infrastructure = code - 1 year later

Prod

Page 6: Infrastructure = code - 1 year later

Ansible

---

- hosts: webservers

tasks:

- name: ensure apache is at the latest version

yum: name=httpd state=latest

- name: write the apache config file

template: src=/srv/httpd.j2 dest=/etc/httpd.conf

notify:

- restart apache

- name: ensure apache is running (and enable it at boot)

service: name=httpd state=started enabled=yes

handlers:

- name: restart apache

service: name=httpd state=restarted

Page 7: Infrastructure = code - 1 year later

Docker

FROM php:7-apache

MAINTAINER Georg M. Sorst <[email protected]>

COPY index.php /var/www/html/

Page 8: Infrastructure = code - 1 year later

Vagrant

Vagrant.configure(2) do |config|

config.vm.box = "ubuntu/xenial64"

config.vm.network "forwarded_port", guest: 80, host: 8080

config.vm.provision "ansible" do |ansible|

ansible.playbook = "playbook.yml"

end

end

Page 9: Infrastructure = code - 1 year later

Test 0.1

Page 10: Infrastructure = code - 1 year later

Dev

Page 11: Infrastructure = code - 1 year later

Test

Page 12: Infrastructure = code - 1 year later

1 year later

● Much learning

● Server Setup from 2 days to 20 minutes

● For fun and profit

Page 13: Infrastructure = code - 1 year later

The Ansible good

● There’s a role for that

● Frequent updates

● Automated testing

Page 14: Infrastructure = code - 1 year later

Integration testing

HTTP

Page 15: Infrastructure = code - 1 year later

Integration testing

HTTP

Page 16: Infrastructure = code - 1 year later

Integration testing

HTTP

Page 17: Infrastructure = code - 1 year later

- name: Upload mock data copy: src: test/mock.json dest: /tmp/mock.json

- name: Provide mock data using a web server container docker_container: image: tobilg/mini-webserver name: mock_server volumes: - '/tmp:/app/public:ro' state: started become: yes

- name: Get IP from web server container command: docker inspect --format '{% raw %}{{ .NetworkSettings.IPAddress }}{% endraw %}' mock_server register: mock_server_server_ip_address

- name: Start application under test docker_container: image: findologic/my-app env: data_url: '{{ mock_server_ip_address }}:80'

Page 18: Infrastructure = code - 1 year later

- name: Ensure that mock data was fetched command: docker logs mock_server become: yes register: mock_server_logs failed_when: 'mock.json' not in mock_server_logs.stdout

- name: Check that app uses mock data uri: url: http://localhost register: app_output failed_when: 'something' not in app_output.content

- name: Destroy web server container docker_container: name: mock_server state: absent become: yes

Page 19: Infrastructure = code - 1 year later

The Bad

● Docker in Docker in Docker

● Migrating existing servers

● better start fresh

● Test, fail, fix cycle is slow

● tag tasks to speed up

● printf debugging

Page 20: Infrastructure = code - 1 year later

The Bad

● Yaml syntax errors

● Networking, routing, repo access, VPN, SSL

Page 21: Infrastructure = code - 1 year later

The awesome

● Automated builds

● Integration testing

● Mock dependencies with Docker containers

● Takes some time to figure out

● Great test harness for Ansible roles

Page 22: Infrastructure = code - 1 year later

The LOL

{{ string }} * 1000000 -> buffer overflow wait_for, timeout < delay

Page 23: Infrastructure = code - 1 year later

Bottom line

● It’s fun

● It’s productive