SlideShare a Scribd company logo
Package a PyApp as a Flatpak Package:
An HTTP Server for Example
潘建宏 Jian-Hong Pan (StarNight)
@ PyCon APAC 2022 Lightning Talk
Who am I
潘建宏 / Jian-Hong Pan (StarNight)
Endless OS Foundation
You can find me at
● http://www.slideshare.net/chienhungpan/
● GitHub: starnight
● Email:
jhp [AT] endlessos.org
chienhung.pan [AT] gmail.com
Flatpak
Flatpak is a framework for distributing desktop applications across
various Linux distributions.
● Rootless install
● Sandboxed applications: Applications that are run with Flatpak
have limited access to the host environment.
● Desktop integration
● Delta updates
● Space efficiency: Flatpak deduplicates libraries (runtime) and other
files used by multiple applications
● Bundling: Allows application developers to ship almost any
dependency or library as part of their application.
● Branches: stable, beta
The Comparison Between Container and Flatpak
App1
Bins/Libs
Container Engine
App2
Bins/Libs
App3
Bins/Libs
Operating System
Containers
App1
Flatpak Runtimes provide
basic binaries and libraries
App2 App3
Operating System
Flatpaks
Install Flatpak
Some major Linux distributions, like Fodora, openSUSU and Endless OS
have already pre-installed flatpak.
● apt install flatpak flatpak-builder
● yum install flatpak flatpak-builder
● dnf install flatpak flatpak-builder
● pacman -S flatpak flatpak-builder
● apk add flatpak flatpak-builder
● …
Note: Not only x86(_64) platforms, but also arm64 and so on …
HTTP Server with Bottle
$ cat main.py
#!/bin/env python3
from bottle import Bottle, run
app = Bottle()
@app.route('/')
@app.route('/hello/<name>')
def hello(name='Stranger'):
return "Hello {}!".format(name)
run(app, host='localhost', port=8080)
$ cat requirements.txt
bottle
Now, Build as a Flatpak App
Flatpak’s Building Introduction
Get flatpak-pip-generator
Because the HTTP server is written in Python and depends on bottle, the
bottle must be installed as part of the flatpak app as well. So, we need
flatpak-builder-tools to generate the required module's meta
information for the flatpak’s manifest.
$ git clone https://github.com/flatpak/flatpak-builder-tools
$ pip install requirements-parser
PS. flatpak-builder-tools depends on requirements-parser
Generate Dependecy List
Use flatpak-pip-generator to generate the python3-requirements.json as
the module in the manifest io.github.starnight.http.yml.
$ ~/flatpak-builder-tools/pip/flatpak-pip-generator --requirements-file=requirements.txt
…
Running: "pip3 download --exists-action=i --dest
/tmp/pip-generator-python3-requirementsbfht6p35 -r requirements.txt"
Collecting bottle
Downloading bottle-0.12.23-py3-none-any.whl (90 kB)
…
Generating dependencies for bottle
Output saved to python3-requirements.json
$ cat python3-requirements.json
{
"name": "python3-bottle",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links="file://${PWD}"
--prefix=${FLATPAK_DEST} "bottle" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url":
"https://files.pythonhosted.org/packages/63/96/2713bb6e0ca10ee2b7be568d6e6d112cf0a1b604
e14879fe744f48ebbed6/bottle-0.12.23-py3-none-any.whl",
"sha256": "9f1c363257c590bd34db5fad4693a7f06ff4217e9ad18337451de69c25137127"
}
]
}
Have the manifest io.github.starnight.http.yml
$ cat io.github.starnight.http.yml
app-id: io.github.starnight.http
runtime: org.freedesktop.Platform
runtime-version: '22.08'
sdk: org.freedesktop.Sdk
command: main.py
finish-args:
- --share=network
cleanup-commands:
- rm -rf /app/bin/__pycache__
(continue to right side)
modules:
- python3-requirements.json
- name: http
buildsystem: simple
build-commands:
- install -D main.py /app/bin/main.py
sources:
- type: file
path: main.py
The Runtime Environment
$ flatpak run --command=sh org.freedesktop.Sdk
[📦 org.freedesktop.Sdk ~]$ ls -l /bin/{python,pip}
-rwxr-xr-x 4 zack zack 221 Jan 1 1970 /bin/pip
lrwxrwxrwx 1 zack zack 7 Sep 3 20:34 /bin/python -> python3
$ flatpak run --command=sh org.freedesktop.Platform
[📦 org.freedesktop.Platform ~]$ ls -l /bin/python
lrwxrwxrwx 1 zack zack 7 Sep 3 20:35 /bin/python -> python3
Files in the Working Directory
$ ls -ltr
total 16
-rwxr-xr-x 1 zack zack 230 Sep 3 18:15 main.py
-rw-r--r-- 1 zack zack 7 Sep 3 18:15 requirements.txt
-rw-r--r-- 1 zack zack 564 Sep 3 18:31 python3-requirements.json
-rw-r--r-- 1 zack zack 417 Sep 3 20:03 io.github.starnight.http.yml
Original source files
Files for Flatpak packaging
Build the io.github.starnight.http as a flatpak app
$ flatpak-builder build-dir io.github.starnight.http.yml
Install the io.github.starnight.http flatpak app
● $ flatpak-builder build-dir 
--force-clean --user --install io.github.starnight.http.yml
List Installed Flatpaks
$ flatpak list --columns=name,application,version,branch,origin
Name Application ID Version Branch Origin
http io.github.starnight.http master http-origin
Freedesktop Platform org.freedesktop.Platform 22.08.0 22.08 flathub
Mesa org.freedesktop.Platform.GL.default mesa-22.1.7 22.08 flathub
Intel org.freedesktop.Platform.VAAPI.Intel 22.08 flathub
openh264 org.freedesktop.Platform.openh264 2.1.0 2.0 flathub
openh264 org.freedesktop.Platform.openh264 2.1.0 2.3.0 flathub
Freedesktop SDK org.freedesktop.Sdk 22.08.0 22.08 flathub
Check the io.github.starnight.http Flatpak App
$ flatpak info io.github.starnight.http
ID: io.github.starnight.http
Ref: app/io.github.starnight.http/x86_64/master
Arch: x86_64
Branch: master
Origin: http-origin
Collection:
Installation: user
Installed: 459.8 kB
Runtime: org.freedesktop.Platform/x86_64/22.08
Sdk: org.freedesktop.Sdk/x86_64/22.08
Commit: b2c495a50e9b586dd07065246cb935baed02a2402526966b23ce4561b17802e6
Subject: Export io.github.starnight.http
Date: 2022-09-03 12:36:39 +0000
Run the io.github.starnight.http Flatpak App
$ flatpak run io.github.starnight.http
Bottle v0.12.23 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
127.0.0.1 - - [03/Sep/2022 20:43:40] "GET / HTTP/1.1" 200 15
127.0.0.1 - - [03/Sep/2022 20:43:40] "GET /favicon.ico HTTP/1.1" 404 742
$ flatpak run --command=sh io.github.starnight.http
[📦 io.github.starnight.http ~]$ ls /app/bin/
bottle.py main.py
More like a Desktop Application
The Idea is …
We need .desktop as the desktop launcher and an icon.
1. User clicks the launcher.
2. Execute the HTTP server.
3. Open the browser and browse http://localhost:8080 automatically.
We can use the XDG feature to lauch the browser with the
command “xdg-open http://localhost:8080”.
$ cat run.sh
#!/usr/bin/sh
main.py &
xdg-open http://localhost:8080
Desktop Launcher
$ cat io.github.starnight.http.desktop
[Desktop Entry]
Name=flatpak-http
Exec=run.sh
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
# TRANSLATORS: Do NOT translate or transliterate this text!
# This is an icon file name.
Icon=io.github.starnight.http
Icon
Choose an SVG icon and save it as io.github.starnight.http.svg.
Source: https://www.pngrepo.com/svg/340417/http
Modify the manifest io.github.starnight.http.yml
● The command becomes run.sh
● Install the desktop launcher io.github.starnight.http.desktop, the
icon io.github.starnight.http.svg and the script run.sh into proper
lcoation.
$ cat io.github.starnight.http.yml
app-id: io.github.starnight.http
runtime: org.freedesktop.Platform
runtime-version: '22.08'
sdk: org.freedesktop.Sdk
command: run.sh
finish-args:
- --share=network
cleanup-commands:
- rm -rf /app/bin/__pycache__
modules:
- python3-requirements.json
- name: http
buildsystem: simple
build-commands:
- install -D main.py /app/bin/main.py
- install -D run.sh /app/bin/run.sh
- mkdir -p /app/share/applications
- install -D io.github.starnight.http.desktop /app/share/applications/io.github.starnight.http.desktop
- mkdir -p /app/share/icons/hicolor/scalable/apps
- install -D io.github.starnight.http.svg /app/share/icons/hicolor/scalable/apps/
sources:
- type: file
path: main.py
- type: file
path: run.sh
- type: file
path: io.github.starnight.http.desktop
- type: file
path: io.github.starnight.http.svg
Build & Run Again
$ flatpak-builder build-dir --user --install --force-clean io.github.starnight.http.yml
$ flatpak run io.github.starnight.http
Reference
● Flatpak’s documents
○ Basic concepts
○ Building your first Flatpak
○ Manifests
○ Sandbox Permissions
○ Python
● Flathub
● Have an HTTP Server in Flatpak
Thanks for Your Attention ~

More Related Content

Similar to Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC 2022 Lightning Talk

Docker as an every day work tool
Docker as an every day work toolDocker as an every day work tool
Docker as an every day work tool
Przemyslaw Koltermann
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpack
KAI CHU CHUNG
 
Istio Playground
Istio PlaygroundIstio Playground
Istio Playground
QAware GmbH
 
Building a data warehouse with Pentaho and Docker
Building a data warehouse with Pentaho and DockerBuilding a data warehouse with Pentaho and Docker
Building a data warehouse with Pentaho and Docker
Wellington Marinho
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
biicode
 
Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6
LetsConnect
 
Docker to the Rescue of an Ops Team
Docker to the Rescue of an Ops TeamDocker to the Rescue of an Ops Team
Docker to the Rescue of an Ops Team
Docker, Inc.
 
Docker to the Rescue of an Ops Team
Docker to the Rescue of an Ops TeamDocker to the Rescue of an Ops Team
Docker to the Rescue of an Ops Team
Rachid Zarouali
 
Check the version with fixes. Link in description
Check the version with fixes. Link in descriptionCheck the version with fixes. Link in description
Check the version with fixes. Link in description
Przemyslaw Koltermann
 
Jump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & GithubJump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & Github
hubx
 
Continuous Delivery w projekcie Open Source - Marcin Stachniuk - DevCrowd 2017
Continuous Delivery w projekcie Open Source - Marcin Stachniuk - DevCrowd 2017Continuous Delivery w projekcie Open Source - Marcin Stachniuk - DevCrowd 2017
Continuous Delivery w projekcie Open Source - Marcin Stachniuk - DevCrowd 2017
MarcinStachniuk
 
Kubernetes Basis: Pods, Deployments, and Services
Kubernetes Basis: Pods, Deployments, and ServicesKubernetes Basis: Pods, Deployments, and Services
Kubernetes Basis: Pods, Deployments, and Services
Jian-Kai Wang
 
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison DowdneySetting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Weaveworks
 
Using Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutionsUsing Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutions
Sander van der Burg
 
Scaling Development Environments with Docker
Scaling Development Environments with DockerScaling Development Environments with Docker
Scaling Development Environments with Docker
Docker, Inc.
 
DCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker Captains
Docker, Inc.
 
Heroku pycon
Heroku pyconHeroku pycon
Heroku pycon
Sabatino Severino
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
皓鈞 張
 
Using docker to develop NAS applications
Using docker to develop NAS applicationsUsing docker to develop NAS applications
Using docker to develop NAS applications
Terry Chen
 
Sandboxing WebKitGTK (GUADEC 2019)
Sandboxing WebKitGTK (GUADEC 2019)Sandboxing WebKitGTK (GUADEC 2019)
Sandboxing WebKitGTK (GUADEC 2019)
Igalia
 

Similar to Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC 2022 Lightning Talk (20)

Docker as an every day work tool
Docker as an every day work toolDocker as an every day work tool
Docker as an every day work tool
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpack
 
Istio Playground
Istio PlaygroundIstio Playground
Istio Playground
 
Building a data warehouse with Pentaho and Docker
Building a data warehouse with Pentaho and DockerBuilding a data warehouse with Pentaho and Docker
Building a data warehouse with Pentaho and Docker
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6
 
Docker to the Rescue of an Ops Team
Docker to the Rescue of an Ops TeamDocker to the Rescue of an Ops Team
Docker to the Rescue of an Ops Team
 
Docker to the Rescue of an Ops Team
Docker to the Rescue of an Ops TeamDocker to the Rescue of an Ops Team
Docker to the Rescue of an Ops Team
 
Check the version with fixes. Link in description
Check the version with fixes. Link in descriptionCheck the version with fixes. Link in description
Check the version with fixes. Link in description
 
Jump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & GithubJump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & Github
 
Continuous Delivery w projekcie Open Source - Marcin Stachniuk - DevCrowd 2017
Continuous Delivery w projekcie Open Source - Marcin Stachniuk - DevCrowd 2017Continuous Delivery w projekcie Open Source - Marcin Stachniuk - DevCrowd 2017
Continuous Delivery w projekcie Open Source - Marcin Stachniuk - DevCrowd 2017
 
Kubernetes Basis: Pods, Deployments, and Services
Kubernetes Basis: Pods, Deployments, and ServicesKubernetes Basis: Pods, Deployments, and Services
Kubernetes Basis: Pods, Deployments, and Services
 
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison DowdneySetting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
 
Using Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutionsUsing Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutions
 
Scaling Development Environments with Docker
Scaling Development Environments with DockerScaling Development Environments with Docker
Scaling Development Environments with Docker
 
DCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker Captains
 
Heroku pycon
Heroku pyconHeroku pycon
Heroku pycon
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Using docker to develop NAS applications
Using docker to develop NAS applicationsUsing docker to develop NAS applications
Using docker to develop NAS applications
 
Sandboxing WebKitGTK (GUADEC 2019)
Sandboxing WebKitGTK (GUADEC 2019)Sandboxing WebKitGTK (GUADEC 2019)
Sandboxing WebKitGTK (GUADEC 2019)
 

More from Jian-Hong Pan

國稅局,我也好想用電腦報稅
國稅局,我也好想用電腦報稅國稅局,我也好想用電腦報稅
國稅局,我也好想用電腦報稅
Jian-Hong Pan
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
Jian-Hong Pan
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
Jian-Hong Pan
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Jian-Hong Pan
 
A Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiA Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry Pi
Jian-Hong Pan
 
Have a Simple Modbus Server
Have a Simple Modbus ServerHave a Simple Modbus Server
Have a Simple Modbus Server
Jian-Hong Pan
 
Software Packaging for Cross OS Distribution
Software Packaging for Cross OS DistributionSoftware Packaging for Cross OS Distribution
Software Packaging for Cross OS Distribution
Jian-Hong Pan
 
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Jian-Hong Pan
 
LoRaWAN class module and subsystem
LoRaWAN class module and subsystemLoRaWAN class module and subsystem
LoRaWAN class module and subsystem
Jian-Hong Pan
 
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoTLet's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Jian-Hong Pan
 
The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017
Jian-Hong Pan
 
Build a Micro HTTP Server for Embedded System
Build a Micro HTTP Server for Embedded SystemBuild a Micro HTTP Server for Embedded System
Build a Micro HTTP Server for Embedded System
Jian-Hong Pan
 
Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016
Jian-Hong Pan
 
Bind Python and C @ COSCUP 2015
Bind Python and C @ COSCUP 2015Bind Python and C @ COSCUP 2015
Bind Python and C @ COSCUP 2015
Jian-Hong Pan
 
Find the bottleneck of your system
Find the bottleneck of your systemFind the bottleneck of your system
Find the bottleneck of your system
Jian-Hong Pan
 
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDevLearn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Jian-Hong Pan
 
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code MeetupDebug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Jian-Hong Pan
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevJian-Hong Pan
 
The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014
Jian-Hong Pan
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
Jian-Hong Pan
 

More from Jian-Hong Pan (20)

國稅局,我也好想用電腦報稅
國稅局,我也好想用電腦報稅國稅局,我也好想用電腦報稅
國稅局,我也好想用電腦報稅
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
A Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiA Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry Pi
 
Have a Simple Modbus Server
Have a Simple Modbus ServerHave a Simple Modbus Server
Have a Simple Modbus Server
 
Software Packaging for Cross OS Distribution
Software Packaging for Cross OS DistributionSoftware Packaging for Cross OS Distribution
Software Packaging for Cross OS Distribution
 
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
 
LoRaWAN class module and subsystem
LoRaWAN class module and subsystemLoRaWAN class module and subsystem
LoRaWAN class module and subsystem
 
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoTLet's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
 
The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017
 
Build a Micro HTTP Server for Embedded System
Build a Micro HTTP Server for Embedded SystemBuild a Micro HTTP Server for Embedded System
Build a Micro HTTP Server for Embedded System
 
Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016
 
Bind Python and C @ COSCUP 2015
Bind Python and C @ COSCUP 2015Bind Python and C @ COSCUP 2015
Bind Python and C @ COSCUP 2015
 
Find the bottleneck of your system
Find the bottleneck of your systemFind the bottleneck of your system
Find the bottleneck of your system
 
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDevLearn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
 
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code MeetupDebug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
 
The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 

Recently uploaded

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 

Recently uploaded (20)

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 

Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC 2022 Lightning Talk

  • 1. Package a PyApp as a Flatpak Package: An HTTP Server for Example 潘建宏 Jian-Hong Pan (StarNight) @ PyCon APAC 2022 Lightning Talk
  • 2. Who am I 潘建宏 / Jian-Hong Pan (StarNight) Endless OS Foundation You can find me at ● http://www.slideshare.net/chienhungpan/ ● GitHub: starnight ● Email: jhp [AT] endlessos.org chienhung.pan [AT] gmail.com
  • 3. Flatpak Flatpak is a framework for distributing desktop applications across various Linux distributions. ● Rootless install ● Sandboxed applications: Applications that are run with Flatpak have limited access to the host environment. ● Desktop integration ● Delta updates ● Space efficiency: Flatpak deduplicates libraries (runtime) and other files used by multiple applications ● Bundling: Allows application developers to ship almost any dependency or library as part of their application. ● Branches: stable, beta
  • 4. The Comparison Between Container and Flatpak App1 Bins/Libs Container Engine App2 Bins/Libs App3 Bins/Libs Operating System Containers App1 Flatpak Runtimes provide basic binaries and libraries App2 App3 Operating System Flatpaks
  • 5. Install Flatpak Some major Linux distributions, like Fodora, openSUSU and Endless OS have already pre-installed flatpak. ● apt install flatpak flatpak-builder ● yum install flatpak flatpak-builder ● dnf install flatpak flatpak-builder ● pacman -S flatpak flatpak-builder ● apk add flatpak flatpak-builder ● … Note: Not only x86(_64) platforms, but also arm64 and so on …
  • 6. HTTP Server with Bottle $ cat main.py #!/bin/env python3 from bottle import Bottle, run app = Bottle() @app.route('/') @app.route('/hello/<name>') def hello(name='Stranger'): return "Hello {}!".format(name) run(app, host='localhost', port=8080) $ cat requirements.txt bottle
  • 7. Now, Build as a Flatpak App Flatpak’s Building Introduction
  • 8. Get flatpak-pip-generator Because the HTTP server is written in Python and depends on bottle, the bottle must be installed as part of the flatpak app as well. So, we need flatpak-builder-tools to generate the required module's meta information for the flatpak’s manifest. $ git clone https://github.com/flatpak/flatpak-builder-tools $ pip install requirements-parser PS. flatpak-builder-tools depends on requirements-parser
  • 9. Generate Dependecy List Use flatpak-pip-generator to generate the python3-requirements.json as the module in the manifest io.github.starnight.http.yml. $ ~/flatpak-builder-tools/pip/flatpak-pip-generator --requirements-file=requirements.txt … Running: "pip3 download --exists-action=i --dest /tmp/pip-generator-python3-requirementsbfht6p35 -r requirements.txt" Collecting bottle Downloading bottle-0.12.23-py3-none-any.whl (90 kB) … Generating dependencies for bottle Output saved to python3-requirements.json
  • 10. $ cat python3-requirements.json { "name": "python3-bottle", "buildsystem": "simple", "build-commands": [ "pip3 install --verbose --exists-action=i --no-index --find-links="file://${PWD}" --prefix=${FLATPAK_DEST} "bottle" --no-build-isolation" ], "sources": [ { "type": "file", "url": "https://files.pythonhosted.org/packages/63/96/2713bb6e0ca10ee2b7be568d6e6d112cf0a1b604 e14879fe744f48ebbed6/bottle-0.12.23-py3-none-any.whl", "sha256": "9f1c363257c590bd34db5fad4693a7f06ff4217e9ad18337451de69c25137127" } ] }
  • 11. Have the manifest io.github.starnight.http.yml $ cat io.github.starnight.http.yml app-id: io.github.starnight.http runtime: org.freedesktop.Platform runtime-version: '22.08' sdk: org.freedesktop.Sdk command: main.py finish-args: - --share=network cleanup-commands: - rm -rf /app/bin/__pycache__ (continue to right side) modules: - python3-requirements.json - name: http buildsystem: simple build-commands: - install -D main.py /app/bin/main.py sources: - type: file path: main.py
  • 12. The Runtime Environment $ flatpak run --command=sh org.freedesktop.Sdk [📦 org.freedesktop.Sdk ~]$ ls -l /bin/{python,pip} -rwxr-xr-x 4 zack zack 221 Jan 1 1970 /bin/pip lrwxrwxrwx 1 zack zack 7 Sep 3 20:34 /bin/python -> python3 $ flatpak run --command=sh org.freedesktop.Platform [📦 org.freedesktop.Platform ~]$ ls -l /bin/python lrwxrwxrwx 1 zack zack 7 Sep 3 20:35 /bin/python -> python3
  • 13. Files in the Working Directory $ ls -ltr total 16 -rwxr-xr-x 1 zack zack 230 Sep 3 18:15 main.py -rw-r--r-- 1 zack zack 7 Sep 3 18:15 requirements.txt -rw-r--r-- 1 zack zack 564 Sep 3 18:31 python3-requirements.json -rw-r--r-- 1 zack zack 417 Sep 3 20:03 io.github.starnight.http.yml Original source files Files for Flatpak packaging
  • 14. Build the io.github.starnight.http as a flatpak app $ flatpak-builder build-dir io.github.starnight.http.yml Install the io.github.starnight.http flatpak app ● $ flatpak-builder build-dir --force-clean --user --install io.github.starnight.http.yml
  • 15. List Installed Flatpaks $ flatpak list --columns=name,application,version,branch,origin Name Application ID Version Branch Origin http io.github.starnight.http master http-origin Freedesktop Platform org.freedesktop.Platform 22.08.0 22.08 flathub Mesa org.freedesktop.Platform.GL.default mesa-22.1.7 22.08 flathub Intel org.freedesktop.Platform.VAAPI.Intel 22.08 flathub openh264 org.freedesktop.Platform.openh264 2.1.0 2.0 flathub openh264 org.freedesktop.Platform.openh264 2.1.0 2.3.0 flathub Freedesktop SDK org.freedesktop.Sdk 22.08.0 22.08 flathub
  • 16. Check the io.github.starnight.http Flatpak App $ flatpak info io.github.starnight.http ID: io.github.starnight.http Ref: app/io.github.starnight.http/x86_64/master Arch: x86_64 Branch: master Origin: http-origin Collection: Installation: user Installed: 459.8 kB Runtime: org.freedesktop.Platform/x86_64/22.08 Sdk: org.freedesktop.Sdk/x86_64/22.08 Commit: b2c495a50e9b586dd07065246cb935baed02a2402526966b23ce4561b17802e6 Subject: Export io.github.starnight.http Date: 2022-09-03 12:36:39 +0000
  • 17. Run the io.github.starnight.http Flatpak App $ flatpak run io.github.starnight.http Bottle v0.12.23 server starting up (using WSGIRefServer())... Listening on http://localhost:8080/ Hit Ctrl-C to quit. 127.0.0.1 - - [03/Sep/2022 20:43:40] "GET / HTTP/1.1" 200 15 127.0.0.1 - - [03/Sep/2022 20:43:40] "GET /favicon.ico HTTP/1.1" 404 742 $ flatpak run --command=sh io.github.starnight.http [📦 io.github.starnight.http ~]$ ls /app/bin/ bottle.py main.py
  • 18. More like a Desktop Application
  • 19. The Idea is … We need .desktop as the desktop launcher and an icon. 1. User clicks the launcher. 2. Execute the HTTP server. 3. Open the browser and browse http://localhost:8080 automatically. We can use the XDG feature to lauch the browser with the command “xdg-open http://localhost:8080”. $ cat run.sh #!/usr/bin/sh main.py & xdg-open http://localhost:8080
  • 20. Desktop Launcher $ cat io.github.starnight.http.desktop [Desktop Entry] Name=flatpak-http Exec=run.sh Terminal=false Type=Application StartupNotify=true MimeType=text/plain; # TRANSLATORS: Do NOT translate or transliterate this text! # This is an icon file name. Icon=io.github.starnight.http
  • 21. Icon Choose an SVG icon and save it as io.github.starnight.http.svg. Source: https://www.pngrepo.com/svg/340417/http
  • 22. Modify the manifest io.github.starnight.http.yml ● The command becomes run.sh ● Install the desktop launcher io.github.starnight.http.desktop, the icon io.github.starnight.http.svg and the script run.sh into proper lcoation.
  • 23. $ cat io.github.starnight.http.yml app-id: io.github.starnight.http runtime: org.freedesktop.Platform runtime-version: '22.08' sdk: org.freedesktop.Sdk command: run.sh finish-args: - --share=network cleanup-commands: - rm -rf /app/bin/__pycache__
  • 24. modules: - python3-requirements.json - name: http buildsystem: simple build-commands: - install -D main.py /app/bin/main.py - install -D run.sh /app/bin/run.sh - mkdir -p /app/share/applications - install -D io.github.starnight.http.desktop /app/share/applications/io.github.starnight.http.desktop - mkdir -p /app/share/icons/hicolor/scalable/apps - install -D io.github.starnight.http.svg /app/share/icons/hicolor/scalable/apps/ sources: - type: file path: main.py - type: file path: run.sh - type: file path: io.github.starnight.http.desktop - type: file path: io.github.starnight.http.svg
  • 25. Build & Run Again $ flatpak-builder build-dir --user --install --force-clean io.github.starnight.http.yml $ flatpak run io.github.starnight.http
  • 26. Reference ● Flatpak’s documents ○ Basic concepts ○ Building your first Flatpak ○ Manifests ○ Sandbox Permissions ○ Python ● Flathub ● Have an HTTP Server in Flatpak
  • 27. Thanks for Your Attention ~