Snaps: from Zero to Hero
Dal pacchetto, all’immagine
Marco Trevisan
marco@ubuntu.com
CC BY-SA 3.0
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
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
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
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
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
alla prova di snapd
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, ..
# 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
# 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
# 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
# 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
Build your first snap
Build snaps on classic, deploy on Ubuntu Core
https://tutorials.ubuntu.com/
create-first-snap
build-a-nodejs-service
# 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
# Creazione metadata
$ cd face-detection-demo
$ snapcraft init
# Apri e modifica lo snapcraft.yaml:
name: face-detection-demo
version: ‘1.0’
summary: Demo for Face Detection statistics
description: |
This demo shows face detection statistics
with fun heads.
grade: devel
confinement: devmode
# Adding golang part
parts:
face-detection-backend:
source: .
plugin: go
go-importpath: github.com/ubuntu/face-detection-demo
build-packages:
- build-essential
- libopencv-dev
# Shipping backend assets
parts:
face-detection-backend:
[…]
assets-backend:
source: .
plugin: dump
snap: [images, frontfacedetection.xml]
# 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/’
# 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
# 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
# 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
snapcraft.io/
developer.ubuntu.com/en/snappy
github.com/snapcore/snapd
github.com/snapcore/snapcraft
sudo snap install snap-codelabs
# http://localhost:8123

Workshop: snap from zero to hero

  • 1.
    Snaps: from Zeroto Hero Dal pacchetto, all’immagine Marco Trevisan marco@ubuntu.com CC BY-SA 3.0
  • 2.
    classic kernel snappy os appapp kernel config os writablefiles app writable area app writable areaany package can write to any file read-only snaps writable spaces per snap filesystem
  • 3.
    versioned root writablearea (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
  • 4.
    versioned root writablearea (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
  • 5.
    Interazione tra snap appsnapapp snap app writable area app writable area Le app sono confinate ed isolate app snap app writable area app snap app writable area
  • 6.
    Ubuntu Core: unsistema 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
  • 7.
  • 8.
    Minimum system requirements ProcessorArchitecture x86 or ARMv7+ (Cortex-A7 single core) Memory 256MB Flash Storage 512MB storage Available Connectivity types WiFi, Ethernet, USB, BT4.0 BLE, ..
  • 9.
    # Prerequisito: installasnapd 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
  • 10.
    # Aggiorna glisnap 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
  • 11.
    # Uno snappiù 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
  • 12.
    # Aggiorna all’ultimaversione 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
  • 13.
  • 14.
    Build snaps onclassic, deploy on Ubuntu Core
  • 15.
  • 16.
    # Creating thisfirst (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
  • 17.
    # Creazione metadata $cd face-detection-demo $ snapcraft init # Apri e modifica lo snapcraft.yaml: name: face-detection-demo version: ‘1.0’ summary: Demo for Face Detection statistics description: | This demo shows face detection statistics with fun heads. grade: devel confinement: devmode
  • 18.
    # Adding golangpart parts: face-detection-backend: source: . plugin: go go-importpath: github.com/ubuntu/face-detection-demo build-packages: - build-essential - libopencv-dev
  • 19.
    # Shipping backendassets parts: face-detection-backend: […] assets-backend: source: . plugin: dump snap: [images, frontfacedetection.xml]
  • 20.
    # 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/’
  • 21.
    # First buildand install $ snapcraft $ sudo snap install *.snap --devmode # No http://localhost:8080 service or face-detection-demo CLI! -> We need to expose them explicitly
  • 22.
    # Exposing acommand 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
  • 23.
    # Simplifying commandname: 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
  • 24.