Workshop: snap from zero to hero

  • View
    61

  • Download
    7

Embed Size (px)

Text of Workshop: snap from zero to hero

  1. 1. Snaps: from Zero to Hero Dal pacchetto, allimmagine Marco Trevisan marco@ubuntu.com CC BY-SA 3.0
  2. 2. 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
  3. 3. 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 Service common user writable area $SNAP_USER_COMMON Service CLI GUI
  4. 4. 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/ /sys / (from core snap) /var/lib/snapd/hostfs (/ from host) snap code & assets (squashfs, RO bind-mounted in /snap//) $SNAP Service common user writable area $SNAP_USER_COMMON Service CLI GUI
  5. 5. 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
  6. 6. 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
  7. 7. alla prova di snapd
  8. 8. 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, ..
  9. 9. # 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
  10. 10. # 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
  11. 11. # 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 # nellinterfaccia web
  12. 12. # Aggiorna allultima versione dellapp! $ sudo snap refresh face-detection-demo --devmode --edge # Linterfaccia 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. 13. Build your first snap
  14. 14. Build snaps on classic, deploy on Ubuntu Core
  15. 15. https://tutorials.ubuntu.com/ create-first-snap build-a-nodejs-service
  16. 16. # 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
  17. 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. 18. # Adding golang part parts: face-detection-backend: source: . plugin: go go-importpath: github.com/ubuntu/face-detection-demo build-packages: - build-essential - libopencv-dev
  19. 19. # Shipping backend assets parts: face-detection-backend: [] assets-backend: source: . plugin: dump snap: [images, frontfacedetection.xml]
  20. 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. 21. # 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
  22. 22. # 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
  23. 23. # 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
  24. 24. snapcraft.io/ developer.ubuntu.com/en/snappy github.com/snapcore/snapd github.com/snapcore/snapcraft sudo snap install snap-codelabs # http://localhost:8123