workshop: snap from zero to hero

24
Snaps: from Zero to Hero Dal pacchetto, all’immagine Marco Trevisan [email protected] CC BY-SA 3.0

Upload: marco-trevisan

Post on 21-Jan-2018

77 views

Category:

Technology


7 download

TRANSCRIPT

Page 1: Workshop: snap from zero to hero

Snaps: from Zero to Hero

Dal pacchetto, all’immagine

Marco [email protected]

CC BY-SA 3.0

Page 2: Workshop: snap from zero to hero

classic

kernel

snappy

os

appapp

kernel config

os writable files

app writable area

app writable areaany package can

write to any file

read-only snaps

writable spaces per snap

filesystem

Page 3: Workshop: snap from zero to hero

versioned root writable area(for services)

$SNAP_DATA

common root writable area(for services)

$SNAP_COMMON

versioned user writable area

$SNAP_USER_DATA

/tmp (per service and app)/tmp (per service and

app)/tmp

(per service and app process)

snap code & assets(squashfs, RO bind-mounted in /snap/<snap_name>/<version>)

$SNAP

Service

common user writable area

$SNAP_USER_COMMON

Service CLI GUI

Page 4: Workshop: snap from zero to hero

versioned root writable area(for services)

$SNAP_DATA

common root writable area(for services)

$SNAP_COMMON

versioned user writable area

$SNAP_USER_DATA

/tmp (per service and app)/tmp (per service and

app)/tmp

(per service and app process)

~

/dev/<device>

/sys

/(from

core snap)

/var/lib/snapd/hostfs(/ from host)

snap code & assets(squashfs, RO bind-mounted in /snap/<snap_name>/<version>)

$SNAP

Service

common user writable area

$SNAP_USER_COMMON

Service CLI GUI

Page 5: Workshop: snap from zero to hero

Interazione tra snap

app snapapp snap

app writable area

app writable area

Le app sono confinate ed isolate

app snap

app writable area

app snap

app writable area

Page 6: Workshop: snap from zero to hero

Ubuntu Core: un sistema all-snaps!

Ed un sistema moderno per creare distribuzioni

Kernel snap

Core snap

Gadget snap

App snap

App snap

App snap

Content interface snap

● Integrità assicurata da un sistema in sola lettura squashfs● Non serve riflashare tutto quando cambia un componente

Page 7: Workshop: snap from zero to hero

alla prova di snapd

Page 8: Workshop: snap from zero to hero

Minimum system requirements

Processor Architecture

x86 or ARMv7+ (Cortex-A7 single core)

Memory

256MB

Flash Storage

512MB storage

Available Connectivity types

WiFi, Ethernet, USB, BT4.0 BLE, ..

Page 9: Workshop: snap from zero to hero

# Prerequisito: installa snapd nel sistema# O usa un immagine per KVM di Ubuntu-core# http://snapcraft.io

# Installa ed esegui il tuo primo snap$ snap find hello$ sudo snap install hello$ hello$ snap list

# Snap può fornire servizi e diversi binari$ hello$ hello.universe

Page 10: Workshop: snap from zero to hero

# Aggiorna gli snap nel sistema (automatico)$ sudo snap refresh

# Passa alla versione di “hello” di un altro# canale$ sudo snap refresh hello --beta$ hello

# Rimuove uno snap$ sudo snap remove hello

Page 11: Workshop: snap from zero to hero

# Uno snap più complesso!$ sudo snap install face-detection-demo --devmode --beta

# Apri http://localhost:8080 (service).# Attiva la webcam via web o da:$ face-detection-demo --enable-camera

# Il comando comunica (via Unix socket)# col servizio, che è collegato alla webcam# ed in ascolto sulla rete.

# Utilizza le altre opzioni, disponibili anche# nell’interfaccia web

Page 12: Workshop: snap from zero to hero

# Aggiorna all’ultima versione dell’app!$ sudo snap refresh face-detection-demo --devmode --edge

# L’interfaccia web non funziona più,# ed i dati son stati eliminati!# facciamo il revert per recuperare servizio (e dati!):$ sudo snap revert face-detection-demo --devmode

# La versione è blacklisted, non viene riscaricata$ sudo snap refresh face-detection-demo --devmode --edge$ sudo snap remove face-detection-demo

Page 13: Workshop: snap from zero to hero

Build your first snap

Page 14: Workshop: snap from zero to hero

Build snaps on classic, deploy on Ubuntu Core

Page 15: Workshop: snap from zero to hero

https://tutorials.ubuntu.com/

create-first-snap

build-a-nodejs-service

Page 16: Workshop: snap from zero to hero

# Creating this first (non trivial) snap!# Ensure you have snapcraft installed$ sudo apt install snapcraft

# Clone our source code$ git clone https://github.com/ubuntu/face-detection-demo --branch vanilla

# Hint: snapcraft.yaml is available at http://bit.ly/2d9UOKH

Page 17: Workshop: snap from zero to hero

# Creazione metadata$ cd face-detection-demo$ snapcraft init

# Apri e modifica lo snapcraft.yaml:name: face-detection-demoversion: ‘1.0’summary: Demo for Face Detection statisticsdescription: | This demo shows face detection statistics with fun heads.grade: develconfinement: devmode

Page 18: Workshop: snap from zero to hero

# Adding golang partparts: face-detection-backend: source: . plugin: go

go-importpath: github.com/ubuntu/face-detection-demo build-packages: - build-essential - libopencv-dev

Page 19: Workshop: snap from zero to hero

# Shipping backend assetsparts: face-detection-backend: […] assets-backend: source: . plugin: dump snap: [images, frontfacedetection.xml]

Page 20: Workshop: snap from zero to hero

# And finally, the website part!parts: face-detection-backend: […] assets-backend: […] website: source: https://github.com/ubuntu/face-detection-web.git plugin: bower organize: ‘*’: ‘www/’

Page 21: Workshop: snap from zero to hero

# First build and install$ snapcraft$ sudo snap install *.snap --devmode

# No http://localhost:8080 service or face-detection-demo CLI!-> We need to expose them explicitly

Page 22: Workshop: snap from zero to hero

# Exposing a command and a service:apps: tool: command: face-detection-cli service: command: face-detection-service daemon: simple restart-condition: always

# Rebuild, reinstall and profit!$ snapcraft$ sudo snap install *.snap --devmode$ face-detection-demo.tool --help

Page 23: Workshop: snap from zero to hero

# Simplifying command name:apps: face-detection-demo: command: face-detection-cli service: […]

# Rebuild, reinstall and check the new command name!$ snapcraft$ sudo snap install *.snap --devmode$ face-detection-demo --help# Head over to http://localhost:8080

Page 24: Workshop: snap from zero to hero

snapcraft.io/

developer.ubuntu.com/en/snappy

github.com/snapcore/snapd

github.com/snapcore/snapcraft

sudo snap install snap-codelabs# http://localhost:8123