Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snap): Add snap packaging #30

Merged
merged 29 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fbae2df
feat(snap): initial packaging
farshidtz May 18, 2022
862b54a
feat(snap): fix installation and runtime issues
farshidtz May 19, 2022
a30f13e
feat(snap): add interfaces for confinement
farshidtz May 19, 2022
e81ae1c
fix(snap): move header file to runtime-helpers
farshidtz May 19, 2022
f6542a3
fix(snap): add rtsp to auto start, strip binaries
farshidtz May 20, 2022
bdfb580
fix: correct location for header file, refactor
farshidtz May 20, 2022
b80c245
docs(snap): clarify auto connection
farshidtz May 20, 2022
36ec5bb
docs: add general usb camera example
farshidtz May 20, 2022
13faad9
Merge remote-tracking branch 'upstream/main' into snap
farshidtz May 20, 2022
21b1265
style: add newlines
farshidtz May 23, 2022
81273f7
docs(snap): improve addon service instructions
farshidtz May 23, 2022
330d9cc
docs(snap): improve camera interface instrcutionns
farshidtz May 23, 2022
554a70a
docs(snap): add comments to libpulse
farshidtz May 23, 2022
c4eb13c
docs(snap): move development details to docs and PR description
farshidtz May 24, 2022
a19e9f5
fix(snap): append libpulse to library paths
farshidtz May 24, 2022
cf5febe
docs: Revert "docs: add general usb camera example"
farshidtz May 25, 2022
dd2391e
feat: switch to core22
farshidtz May 25, 2022
bc793f9
fix: install example device config
farshidtz May 27, 2022
e9b21ae
Merge remote-tracking branch 'upstream/main' into snap
farshidtz May 27, 2022
1f03470
docs: package rtsp-simple-server's licence
farshidtz May 27, 2022
97d9f59
docs: add comment to explain the copy workaround
farshidtz May 27, 2022
4df80ee
fix: add missing curl build dependency
farshidtz May 27, 2022
4eccf07
fix: Add scripts to call compiled hooks
farshidtz Jun 28, 2022
1eaa599
refactor: upgrade to edgex-snap-hooks and local snap refactoring
farshidtz Jun 29, 2022
91b64af
build: go mod tidy
farshidtz Jun 30, 2022
47482b0
test(snap): Add Github workflow for snap testing
farshidtz Jun 30, 2022
ad82447
fix: write VERSION file to stage directory instead of to source
farshidtz Jun 30, 2022
52d4126
test: switch to v2 of build/test actions
farshidtz Jun 30, 2022
4c4ab6a
docs: remove license field
farshidtz Jul 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ LintOutput.json
device-usb-camera
run

#VERSION
VERSION

# snap files
*.snap
*.assert
prime/
stage/
parts/
squashfs-root/
coverage.out
VERSION
farshidtz marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions cmd/res/devices/general.usb.camera.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[DeviceList]]
Name = "example-camera"
ProfileName = "USB-Camera-General"
Description = "Example Camera"
Labels = [ "device-usb-camera-example" ]
[DeviceList.Protocols]
[DeviceList.Protocols.USB]
Path = "/dev/video0"
AutoStreaming = "false"
farshidtz marked this conversation as resolved.
Show resolved Hide resolved
85 changes: 85 additions & 0 deletions snap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# EdgeX USB Camera Device Service Snap
[![edgex-device-usb-camera](https://snapcraft.io/edgex-device-usb-camera/badge.svg)](https://snapcraft.io/edgex-device-usb-camera)

This directory contains the snap packaging of the EdgeX USB Camera device service.

The snap is built automatically and published on the Snap Store as [edgex-device-usb-camera].

For usage instructions, please refer to Device Camera section in [Getting Started using Snaps][docs].

## Build from source
Execute the following command from the top-level directory of this repo:
```
snapcraft
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention that building this snap remains "challenging" and at least offer some options. I don't think the given option "just works".

Copy link
Member Author

@farshidtz farshidtz Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained in another comment, we have been able to build it without problems locally and on CI servers. If there are any OS-specific challenges related to using snapcraft to build core22-based snaps, it should be raised on snapcraft issue trackers.

This will create a snap package file with `.snap` extension. It can be installed locally by setting the `--dangerous` flag:
```bash
sudo snap install --dangerous <snap-file>
```

The [snapcraft overview](https://snapcraft.io/docs/snapcraft-overview) provides additional details.

### Obtain a Secret Store token
<!-- The `edgex-secretstore-token` snap slot makes it possible to automatically receive a token from a locally installed platform snap.-->
farshidtz marked this conversation as resolved.
Show resolved Hide resolved

If the snap is built and installed locally, the interface will not auto-connect. You can check the status of the connections by running the `snap connections edgex-device-usb-camera` command.

Notes:
- The auto connection will not happen right now because the snap publisher isn't same as the `edgexfoundry` platrform snap (i.e. Canonical).
farshidtz marked this conversation as resolved.
Show resolved Hide resolved
- The service isn't yet included in the secrets list of the platform snap.
Add the device service to list of services which have tokens generated for them:
```
# Additional secret store tokens
farshidtz marked this conversation as resolved.
Show resolved Hide resolved
EXISTING=$(snap get edgexfoundry apps.security-secretstore-setup.config.add-secretstore-tokens)
snap set edgexfoundry apps.security-secretstore-setup.config.add-secretstore-tokens="$EXISTING,device-usb-camera"

# Additional known secrets
EXISTING=$(snap get edgexfoundry apps.security-secretstore-setup.config.add-known-secrets)
snap set edgexfoundry apps.security-secretstore-setup.config.add-known-secrets="$EXISTING,redisdb[device-usb-camera]"

# Additional registry ACL roles
EXISTING=$(snap get edgexfoundry apps.security-bootstrapper.config.add-registry-acl-roles)
snap set edgexfoundry apps.security-bootstrapper.config.add-registry-acl-roles="$EXISTING,device-usb-camera"

# Run the bootstrappers:
snap start edgexfoundry.security-secretstore-setup
snap start edgexfoundry.security-consul-bootstrapper
farshidtz marked this conversation as resolved.
Show resolved Hide resolved
```

To manually connect and obtain a token:
farshidtz marked this conversation as resolved.
Show resolved Hide resolved
```bash
sudo snap connect edgexfoundry:edgex-secretstore-token edgex-device-usb-camera:edgex-secretstore-token
```

Please refer [here][secret-store-token] for further information.

### Connect the camera interface
The `camera` interface is currently not automatically connected. To connect manually:
farshidtz marked this conversation as resolved.
Show resolved Hide resolved
```
snap connect edgex-device-usb-camera:camera :camera
```

[edgex-device-usb-camera]: https://snapcraft.io/edgex-device-usb-camera
[docs]: https://docs.edgexfoundry.org/2.2/getting-started/Ch-GettingStartedSnapUsers/#device-usb-camera
[secret-store-token]: https://docs.edgexfoundry.org/2.2/getting-started/Ch-GettingStartedSnapUsers/#secret-store-token

# Issues
The snap is 115 MB, exactly same as the docker image.

It may be possible to reduce the size by removing extra shared library object files.
farshidtz marked this conversation as resolved.
Show resolved Hide resolved

See:
```
./device-usb-camera$ du -a -d 1 squashfs-root/usr/lib/x86_64-linux-gnu/ | sort -n -r | head -n 10
297884 squashfs-root/usr/lib/x86_64-linux-gnu/
89352 squashfs-root/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1
43020 squashfs-root/usr/lib/x86_64-linux-gnu/dri
27392 squashfs-root/usr/lib/x86_64-linux-gnu/libicudata.so.66.1
15732 squashfs-root/usr/lib/x86_64-linux-gnu/libx265.so.179
14208 squashfs-root/usr/lib/x86_64-linux-gnu/libavcodec.so.58.54.100
14196 squashfs-root/usr/lib/x86_64-linux-gnu/libcodec2.so.0.9
9380 squashfs-root/usr/lib/x86_64-linux-gnu/librsvg-2.so.2.47.0
4808 squashfs-root/usr/lib/x86_64-linux-gnu/libflite_cmu_time_awb.so.2.1
4712 squashfs-root/usr/lib/x86_64-linux-gnu/libflite_cmu_us_rms.so.2.1
```
Loading