From 4e518eebde62524943ef4fba54b9c3a8d84db30b Mon Sep 17 00:00:00 2001 From: Siggi Skulason Date: Thu, 17 Feb 2022 20:42:25 +0000 Subject: [PATCH] fix: update snap packaging (#61) * fix: updates to enable snap support - Add support for defining provision watcher directory - Adding auto-scan script to snap - Adding support for Consul token to auto-scan script - Other minor changes See also: https://github.com/edgexfoundry/device-rfid-llrp-go/pull/52 Signed-off-by: Siggi Skulason --- README.md | 55 ++-------- bin/auto-configure.sh | 20 +++- internal/driver/config.go | 3 + internal/driver/driver.go | 11 +- snap/README.md | 99 +++++++++-------- snap/local/hooks/cmd/install/install.go | 63 ++++++----- snap/local/hooks/const.go | 19 ++++ snap/local/hooks/go.mod | 4 +- snap/local/hooks/go.sum | 4 +- snap/snapcraft.yaml | 139 +++++++++++++----------- 10 files changed, 230 insertions(+), 187 deletions(-) diff --git a/README.md b/README.md index 45d4858f..f4d1766c 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,16 @@ A ROAccessReport can be used to examine data read from one or more RFID tags see The [LLRP RFID Inventory Service][inventory_service] can be used to automatically configure this service and readers it manages. This repository also provides a higher-level abstraction for working with RFID tag by parsing ROAccessReports and generating higher-level tag-specific readings (e.g. TAG_APPEARED, TAG_MOVED, etc). ## Table of contents - + * [First Run](#first-run) * [Device Discovery](#device-discovery) * [Device Profiles, Custom LLRP Messages, and Service Limitations](#device-profiles-custom-llrp-messages-and-service-limitations) * [Connection Management](#connection-management) * [Example Scripts](#example-scripts) * [Testing](#testing) -* [Snap Development and Testing](#snap-development-and-testing) * [Footnotes](#footnotes) + ## First Run **Build Native** ```bash @@ -35,7 +35,8 @@ make docker - [Snap](https://snapcraft.io/edgexfoundry) **Run device-rfid-llrp** -- [Run via Snap](#snap-development-and-testing) +- Snap + - For the snap, refer to the [snap](snap) directory. - Docker - Use [compose-builder](https://github.com/edgexfoundry/edgex-compose/tree/jakarta/compose-builder) @@ -111,6 +112,13 @@ The easiest way of doing this is via the following script: ```bash ./bin/auto-configure.sh ``` + +This script requires access to Consul. If running with security enabled, then a Consul token is required. In that case it should be passed as an argument to the script, i.e: + +```bash +./bin/auto-configure.sh a7910d82-69ae-ea21-214d-fd1326e68545 +``` + What this command does is check your local machine's network interfaces to see which ones are both online and a physical device (instead of virtual). It uses that information to fill in the `DiscoverySubnets` field in Consul for you. @@ -542,47 +550,6 @@ The following are particularly useful: [test_helper]: internal/llrp/test_helpers.go -## Snap Development and Testing -The Snap directory consists of the `snapcraft.yaml` file and the initialization file `install` for building a snap package for this Service. -### Build Device RFID LLRP Snap Packages -Execute the following commands from the project's root directory. If you try to build elsewhere, it will fail with a `source not found` error message. -- `snapcraft clean` -- `snapcraft` - -On success, this creates a `*.snap` package under the root directory. -The package name format is `{snapName}_{versionNumber}_{architecture}.snap`, e.g. - - `edgex-device-llrp_0.0.0-20201014+39fc566_amd64.snap` - -Always delete the old snap package before rebuilding via `rm oldsnap.snap` & `snapcraft clean`. - -To debug snap build issues, run `snapcraft --debug`. - -If snapcraft encounters an error, it will open a shell within the virtualised build environment. -### Install Device RFID LLRP Snap Packages -- `sudo snap install --devmode --dangerous *.snap` - -Use `snapcraft list` to verify the package was installed. -### Test Device RFID LLRP Snap Packages -The service registers itself with consul at initialization, -which requires Consul and other EdgeX Snap packages. - -Make sure they are installed and running (`snap install edgexfoundry`), -then start the service with `sudo snap start edgex-device-llrp` -and verify there are no errors in the logs: `sudo snap logs edgex-device-llrp`. - -Consul UI can also be used to verify if the service has started without any errors `http://localhost:8500` - -Follow [First Run](#first-run) section to auto-configure subnet & trigger device discovery. -As part of testing, registered devices can be checked via EdgeX Core-Metadata API - `http://localhost:59881/api/v2/device/service/name/device-rfid-llrp` - -#### Here are other helpful commands: -- List installed Snap packages: `snap list` -- View the Snap service status: `systemctl status snap.edgex-device-rfid-llrp.device-rfid-llrp-go.service` -- View System logs: `journalctl -xe` -- Stop the Snap service: `sudo snap stop edgex-device-rfid-llrp` -- Remove the Snap package: `sudo snap remove edgex-device-rfid-llrp` - ## Footnotes ### Notes on configuration.toml - Modifying the `configuration.toml` file will require you to rebuild the docker image diff --git a/bin/auto-configure.sh b/bin/auto-configure.sh index 97b5080a..30fabc71 100755 --- a/bin/auto-configure.sh +++ b/bin/auto-configure.sh @@ -41,10 +41,12 @@ err() { echo -e "${red}${bold}Failed!${clear}" exit 1 } - + +CONSUL_TOKEN=${1:-""} CONSUL_URL=${CONSUL_URL:-http://localhost:8500} url="${CONSUL_URL}/v1/kv/edgex/devices/2.0/device-rfid-llrp/AppCustom/DiscoverySubnets" + ### Dependencies Check # Note: trailing ${red} is to colorize red all potential error output from the following commands printf "${bold}%${spacing}s${clear}: ...\n${red}" "Dependencies Check" @@ -57,7 +59,13 @@ echo -e "${prev_line}${green}Success${clear}" ### Consul Check # Note: trailing ${red} is to colorize red all potential error output from the following commands printf "${bold}%${spacing}s${clear}: ...\n${red}" "Consul Check" -code=$(curl -X GET -w "%{http_code}" -o /dev/null -s "${url}" || echo $?) + +if [ -z $CONSUL_TOKEN ]; then + code=$(curl -X GET -w "%{http_code}" -o /dev/null -s "${url}" || echo $?) +else + code=$(curl -X GET -H "X-Consul-Token:$CONSUL_TOKEN" -w "%{http_code}" -o /dev/null -s "${url}" || echo $?) +fi + if [ $((code)) -ne 200 ]; then echo -e "${red}${bold}Failed!${normal} curl returned a status code of '${bold}$((code))'${normal}" # Special message for error code 7 @@ -85,6 +93,7 @@ ifaces=$( -execdir grep -q 'up' "{}/operstate" \; `# ensure interface is online (operstate == up)` \ -printf '%f|' `# print them separated by | for regex matching` ) + if [ -z "${ifaces}" ]; then echo "Error, no online physical network interfaces detected.${clear}" exit 1 @@ -138,7 +147,12 @@ echo -e "${prev_line}${clear}${subnets}" ### Configure Consul printf "${bold}%${spacing}s${clear}: ...\n${red}" "Configure" -code=$(curl -X PUT --data "${subnets}" -w "%{http_code}" -o /dev/null -s "${url}" || echo $?) +if [ -z $CONSUL_TOKEN ]; then + code=$(curl -X PUT --data "${subnets}" -w "%{http_code}" -o /dev/null -s "${url}" || echo $?) +else + code=$(curl -X PUT -H "X-Consul-Token:$CONSUL_TOKEN" --data "${subnets}" -w "%{http_code}" -o /dev/null -s "${url}" || echo $?) +fi + if [ $((code)) -ne 200 ]; then echo -e "${red}${bold}Failed!${normal} curl returned a status code of '${bold}${code}'${clear}" exit $((code)) diff --git a/internal/driver/config.go b/internal/driver/config.go index a0d559ee..2ec5ef96 100644 --- a/internal/driver/config.go +++ b/internal/driver/config.go @@ -20,6 +20,9 @@ type CustomConfig struct { // MaxDiscoverDurationSeconds is the maximum amount of seconds for a discovery to run. It is important // to have this configured in the case of larger subnets such as /16 and /8 MaxDiscoverDurationSeconds int + + // Location of Provision Watchers + ProvisionWatcherDir string } // ServiceConfig a struct that wraps CustomConfig which holds the values for driver configuration diff --git a/internal/driver/driver.go b/internal/driver/driver.go index c4731f48..553a6d07 100644 --- a/internal/driver/driver.go +++ b/internal/driver/driver.go @@ -53,7 +53,6 @@ const ( // enable this by default, otherwise discovery will not work. registerProvisionWatchers = true - provisionWatcherFolder = "res/provision_watchers" // discoverDebounceDuration is the amount of time to wait for additional changes to discover // configuration before auto-triggering a discovery @@ -712,7 +711,17 @@ func getAddr(protocols protocolMap) (net.Addr, error) { "unable to create addr for tcp protocol (%q, %q)", host, port) } +// todo: remove this method once the Device SDK has been updated as per https://github.com/edgexfoundry/device-sdk-go/issues/1100 func (d *Driver) addProvisionWatchers() error { + + // this setting is a workaround for the fact that there is no standard way to define this directory using the SDK + // the snap needs to be able to change the location of the provision watchers + provisionWatcherFolder := d.config.AppCustom.ProvisionWatcherDir + if provisionWatcherFolder == "" { + provisionWatcherFolder = "res/provision_watchers" + } + d.lc.Infof("Adding provision watchers from %s", provisionWatcherFolder) + files, err := ioutil.ReadDir(provisionWatcherFolder) if err != nil { return err diff --git a/snap/README.md b/snap/README.md index ae7e62ff..21640340 100644 --- a/snap/README.md +++ b/snap/README.md @@ -28,12 +28,6 @@ The latest stable version of the snap can be installed using: $ sudo snap install edgex-device-rfid-llrp ``` -The 2.0 (Ireland) release of the snap can be installed using: - -```bash -$ sudo snap install edgex-device-rfid-llrp --channel=2.0 -``` - The latest development version of the snap can be installed using: ```bash @@ -69,40 +63,51 @@ ensures that as well as starting the service now, it will be automatically start $ sudo snap start --enable edgex-device-rfid-llrp.device-rfid-llrp ``` -### Using a content interface to set device configuration +## Subnet setup -The `device-config` content interface allows another snap to seed this device -snap with configuration files under the `$SNAP_DATA/config/device-rfid-llrp/res` directory. +The `DiscoverySubnets` setting needs to be provided before a device discovery can occur. This can be done in a number of ways: -Note that the `device-config` content interface does NOT support seeding of the Secret Store Token because that file is expected at a different path. +- Using `snap set` to set your local subnet information. Example: -To use, create a new snap with a directory containing the configuration files. -Your `snapcraft.yaml` file then needs to define a slot with read access to the directory you are sharing. + ```bash + $ sudo snap set edgex-device-rfid-llrp env.app-custom.discovery-subnets="192.168.10.0/24" + + $ curl -X POST http://localhost:59989/api/v2/discovery + ``` -``` -slots: - device-config: - interface: content - content: device-config - read: - - $SNAP/config -``` + **NOTE:** This will only work after [this issue](https://github.com/edgexfoundry/app-functions-sdk-go/issues/1043) is resolved. -where `$SNAP/config` is configuration directory your snap is providing to the device snap. +- Using a [content interface](#using-a-content-interface-to-set-device-configuration) to set device configuration -Then connect the plug in the device snap to the slot in your snap, which will replace the configuration in the device snap. Do this with: -```bash -$ sudo snap connect edgex-device-rfid-llrp:device-config your-snap:device-config -``` +- Using the `auto-configure` command. + + This command finds all local network interfaces which are online and non-virtual and sets the value of `DiscoverySubnets` +in Consul. When running with security enabled, it requires a Consul token, so it needs to be run as follows: -This needs to be done before the device service is started for the first time. Once you have set the configuration the device service can be started and it will then be configured using the settings you provided: + ```bash + # get Consul ACL token + CONSUL_TOKEN=$(sudo cat /var/snap/edgexfoundry/current/secrets/consul-acl-token/bootstrap_token.json | jq ".SecretID" | tr -d '"') + echo $CONSUL_TOKEN -```bash -$ sudo snap start edgex-device-rfid-llrp.device-rfid-llrp -``` + # start the device service and connect the interfaces required for network interface discovery + sudo snap start edgex-device-rfid-llrp.device-rfid-llrp + sudo snap connect edgex-device-rfid-llrp:network-control + sudo snap connect edgex-device-rfid-llrp:network-observe + + # run the nework interface discovery, providing the Consul token + edgex-device-rfid-llrp.auto-configure $CONSUL_TOKEN + ``` + + +### Using a content interface to set device configuration + +The `device-config` content interface allows another snap to seed this snap with configuration directories under `$SNAP_DATA/config/device-rfid-llrp`. + +Note that the `device-config` content interface does NOT support seeding of the Secret Store Token because that file is expected at a different path. + +Please refer to [edgex-config-provider](https://github.com/canonical/edgex-config-provider), for an example and further instructions. -**Note** - content interfaces from snaps installed from the Snap Store that have the same publisher connect automatically. For more information on snap content interfaces please refer to the snapcraft.io [Content Interface](https://snapcraft.io/docs/content-interface) documentation. ### Autostart By default, the edgex-device-rfid-llrp disables its service on install, as the expectation is that the default profile configuration files will be customized, and thus this behavior allows the profile `configuration.toml` files in $SNAP_DATA to be modified before the service is first started. @@ -124,7 +129,6 @@ the overrides will be picked up when the services are first started. The following syntax is used to specify service-specific configuration overrides: - ``` env.. ``` @@ -145,28 +149,33 @@ For details on the mapping of configuration options to Config options, please re ``` [Service] -service.boot-timeout // Service.BootTimeout -service.health-check-interval // Service.HealthCheckInterval -service.host // Service.Host -service.server-bind-addr // Service.ServerBindAddr -service.port // Service.Port -service.protocol // Service.Protocol -service.max-result-count // Service.MaxResultCount -service.max-request-size // Service.MaxRequestSize -service.startup-msg // Service.StartupMsg -service.request-timeout // Service.RequestTimeout +service.health-check-interval // Service.HealthCheckInterval +service.host // Service.Host +service.server-bind-addr // Service.ServerBindAddr +service.port // Service.Port +service.max-result-count // Service.MaxResultCount +service.max-request-size // Service.MaxRequestSize +service.startup-msg // Service.StartupMsg +service.request-timeout // Service.RequestTimeout [SecretStore] secret-store.secrets-file // SecretStore.SecretsFile secret-store.disable-scrub-secrets-file // SecretStore.DisableScrubSecretsFile [Clients.core-data] -clients.core-data.port // Clients.core-data.Port +clients.core-data.port // Clients.core-data.Port [Clients.core-metadata] -clients.core-metadata.port // Clients.core-metadata.Port +clients.core-metadata.port // Clients.core-metadata.Port [Device] -device.update-last-connected // Device.UpdateLastConnected -device.use-message-bus // Device.UseMessageBus +device.update-last-connected // Device.UpdateLastConnected +device.use-message-bus // Device.UseMessageBus + +[AppCustom] +app-custom.discovery-subnets // AppCustom.DiscoverySubnets +app-custom.probe-async-limit // AppCustom.ProbeAsyncLimit +app-custom.probe-timeout-seconds // AppCustom.ProbeTimeoutSeconds +app-custom.scan-port // AppCustom.ScanPort +app-custom.max-discover-duration-seconds // AppCustom.MaxDiscoverDurationSeconds ``` diff --git a/snap/local/hooks/cmd/install/install.go b/snap/local/hooks/cmd/install/install.go index 816cb351..01b4812e 100644 --- a/snap/local/hooks/cmd/install/install.go +++ b/snap/local/hooks/cmd/install/install.go @@ -28,50 +28,56 @@ import ( var cli *hooks.CtlCli = hooks.NewSnapCtl() -// installProfiles copies the profile configuration.toml files from $SNAP to $SNAP_DATA. -func installConfig() error { - var err error +const LLRP_RES = "/config/device-rfid-llrp/res" - path := "/config/device-rfid-llrp/res/configuration.toml" - destFile := hooks.SnapData + path - srcFile := hooks.Snap + path +func installFile(path string) error { + destFile := hooks.SnapData + LLRP_RES + path + srcFile := hooks.Snap + LLRP_RES + path - if err = os.MkdirAll(filepath.Dir(destFile), 0755); err != nil { + err := os.MkdirAll(filepath.Dir(destFile), 0755) + if err != nil { return err } + err = hooks.CopyFile(srcFile, destFile) - if err = hooks.CopyFile(srcFile, destFile); err != nil { - return err - } + return err + +} +// installProfiles copies the profile configuration.toml files from $SNAP to $SNAP_DATA. +func installConfig() error { + return installFile("/configuration.toml") +} + +func installProvisionWatchers() error { + + profs := [...]string{"impinj", "llrp"} + + for _, v := range profs { + path := fmt.Sprintf("/provision_watchers/%s.provision.watcher.json", v) + err := installFile(path) + if err != nil { + return err + } + } return nil } func installDevices() error { //No device files - - return nil + return os.MkdirAll(hooks.SnapData+LLRP_RES+"/devices", 0755) } func installDevProfiles() error { - var err error profs := [...]string{"device", "impinj"} - for _, v := range profs { - path := fmt.Sprintf("/config/device-rfid-llrp/res/profiles/llrp.%s.profile.yaml", v) - destFile := hooks.SnapData + path - srcFile := hooks.Snap + path - - if err := os.MkdirAll(filepath.Dir(destFile), 0755); err != nil { - return err - } - - if err = hooks.CopyFile(srcFile, destFile); err != nil { + path := fmt.Sprintf("/profiles/llrp.%s.profile.yaml", v) + err := installFile(path) + if err != nil { return err } } - return nil } @@ -79,9 +85,8 @@ func main() { var err error if err = hooks.Init(false, "edgex-device-rfid-llrp"); err != nil { - fmt.Println(fmt.Sprintf("edgex-device-rfid-llrp::install: initialization failure: %v", err)) + fmt.Printf("edgex-device-rfid-llrp::install: initialization failure: %v\n", err) os.Exit(1) - } err = installConfig() @@ -101,4 +106,10 @@ func main() { hooks.Error(fmt.Sprintf("edgex-device-rfid-llrp:install: %v", err)) os.Exit(1) } + + err = installProvisionWatchers() + if err != nil { + hooks.Error(fmt.Sprintf("edgex-device-rfid-llrp:install: %v", err)) + os.Exit(1) + } } diff --git a/snap/local/hooks/const.go b/snap/local/hooks/const.go index 16706b26..3ec4c8ea 100644 --- a/snap/local/hooks/const.go +++ b/snap/local/hooks/const.go @@ -30,4 +30,23 @@ var ConfToEnv = map[string]string{ // [Device] "device.update-last-connected": "DEVICE_UPDATELASTCONNECTED", "device.use-message-bus": "DEVICE_USEMESSAGEBUS", + + // [AppCustom] + // List of IPv4 subnets to perform LLRP discovery process on, in CIDR format (X.X.X.X/Y) + // separated by commas ex: "192.168.1.0/24,10.0.0.0/24" + "app-custom.discovery-subnets": "APPCUSTOM_DISCOVERYSUBNETS", + + // Maximum simultaneous network probes + "app-custom.probe-async-limit": "APPCUSTOM_PROBEASYNCLIMIT", + + // Maximum amount of seconds to wait for each IP probe before timing out. + // This will also be the minimum time the discovery process can take. + "app-custom.probe-timeout-seconds": "APPCUSTOM_PROBETIMEOUTSECONDS", // ProbeTimeoutSeconds = 2 + + // Port to scan for LLRP devices on + "app-custom.scan-port": "APPCUSTOM_SCANPORT", + + // Maximum amount of seconds the discovery process is allowed to run before it will be cancelled. + // It is especially important to have this configured in the case of larger subnets such as /16 and /8 + "app-custom.max-discover-duration-seconds": "APPCUSTOM_MAXDISCOVERDURATIONSECONDS", } diff --git a/snap/local/hooks/go.mod b/snap/local/hooks/go.mod index 6e504d9e..22814299 100644 --- a/snap/local/hooks/go.mod +++ b/snap/local/hooks/go.mod @@ -1,5 +1,5 @@ module github.com/edgexfoundry/device-rfid-llrp-go/hooks -require github.com/canonical/edgex-snap-hooks/v2 v2.0.7 - go 1.17 + +require github.com/canonical/edgex-snap-hooks/v2 v2.1.3 diff --git a/snap/local/hooks/go.sum b/snap/local/hooks/go.sum index 947b67e6..039e14dc 100644 --- a/snap/local/hooks/go.sum +++ b/snap/local/hooks/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v2 v2.0.7 h1:R3a8PfMffUYJsY8uw7Rosu/KURkB55tTuO8YwETV5zY= -github.com/canonical/edgex-snap-hooks/v2 v2.0.7/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= +github.com/canonical/edgex-snap-hooks/v2 v2.1.3 h1:mcV/atn6k6sN6Uik+lSQGEZi4Q6r96epgBW+u6AGZ3Y= +github.com/canonical/edgex-snap-hooks/v2 v2.1.3/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 4af11955..3f56688f 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,16 +1,8 @@ name: edgex-device-rfid-llrp -base: core18 -adopt-info: version +base: core20 +adopt-info: metadata license: Apache-2.0 -summary: EdgeX Device LLRP Micro Service -title: EdgeX Device LLRP Micro Service -description: | - The EdgeX Device LLRP service for connecting LLRP based RFID devices to EdgeX. - Initially the daemon in the snap is disabled - a device profile must be - provisioned externally with core-metadata or provided to device-rfid-llrp inside - "$SNAP_DATA/config/device-rfid-llrp/res" before starting. - -# TODO: add armhf when the project supports this + architectures: - build-on: amd64 - build-on: arm64 @@ -18,7 +10,10 @@ architectures: grade: stable confinement: strict -# delhi: 0, edinburgh: 1, fuji: 2, geneva/hanoi: 3, ireland: 4 +# 1: edinburgh +# 2: fuji +# 3: geneva, hanoi +# 4: ireland, jakarta epoch: 4 slots: @@ -29,41 +24,39 @@ slots: write: [$SNAP_DATA/device-rfid-llrp] apps: + auto-configure: + adapter: none + command: bin/auto-configure.sh + command-chain: + - snap/command-chain/snapcraft-runner + plugs: + - network + - network-observe # required for /operstate + - network-control # required for "ip" + device-rfid-llrp: adapter: full command: bin/device-rfid-llrp $CONFIG_PRO_ARG $CONF_ARG $REGISTRY_ARG command-chain: - bin/startup-env-var.sh environment: - CONFIG_PRO_ARG: "--cp=consul.http://localhost:8500" + CONFIG_PRO_ARG: "--cp=consul://localhost:8500" CONF_ARG: "--confdir=$SNAP_DATA/config/device-rfid-llrp/res" REGISTRY_ARG: "--registry" DEVICE_PROFILESDIR: "$SNAP_DATA/config/device-rfid-llrp/res/profiles" - # DEVICE_DEVICESDIR: "$SNAP_DATA/config/device-rfid-llrp/res/devices" + DEVICE_DEVICESDIR: "$SNAP_DATA/config/device-rfid-llrp/res/devices" SECRETSTORE_TOKENFILE: $SNAP_DATA/device-rfid-llrp/secrets-token.json + APPCUSTOM_PROVISIONWATCHERDIR: $SNAP_DATA/config/device-rfid-llrp/res/provision_watchers daemon: simple - passthrough: - install-mode: disable + install-mode: disable plugs: [network, network-bind] plugs: device-config: interface: content - content: device-config - target: $SNAP_DATA/config/device-rfid-llrp/res + target: $SNAP_DATA/config/device-rfid-llrp parts: - version: - plugin: nil - source: snap/local - override-pull: | - cd $SNAPCRAFT_PROJECT_DIR - GIT_VERSION=$(git describe --tags --abbrev=0 | sed 's/v//') - if [ -z "$GIT_VERSION" ]; then - GIT_VERSION="0.0.0" - fi - snapcraftctl set-version ${GIT_VERSION} - hooks: source: snap/local/hooks plugin: make @@ -76,6 +69,7 @@ parts: install -DT ./cmd/install/install "$SNAPCRAFT_PART_INSTALL/snap/hooks/install" device-rfid-llrp: + after: [metadata] source: . plugin: make build-packages: [git, libzmq3-dev, pkg-config] @@ -85,43 +79,60 @@ parts: override-build: | cd $SNAPCRAFT_PART_SRC - # The makefile uses a VERSION file to set the Version string. - # This file needs to be generated here - GIT_VERSION=$(git describe --tags --abbrev=0 | sed 's/v//') - if [ -z "$GIT_VERSION" ]; then - GIT_VERSION="0.0.0" - fi - echo $GIT_VERSION > ./VERSION + # the version is needed for the build + cat ./VERSION - go mod tidy + make tidy make build - # copy device-rfid-llrp - install -DT "./cmd/device-rfid-llrp" "$SNAPCRAFT_PART_INSTALL/bin/device-rfid-llrp" - - install -d "$SNAPCRAFT_PART_INSTALL/config/device-rfid-llrp/res/" - install -DT "./cmd/res/configuration.toml" \ - "$SNAPCRAFT_PART_INSTALL/config/device-rfid-llrp/res/configuration.toml" - - install -d "$SNAPCRAFT_PART_INSTALL/config/device-rfid-llrp/res/profiles/" - for fpath in ./cmd/res/profiles/*.yaml; do - fname=$(basename "$fpath") - install -DT "./cmd/res/profiles/${fname}" \ - "$SNAPCRAFT_PART_INSTALL/config/device-rfid-llrp/res/profiles/${fname}" - done - - install -d "$SNAPCRAFT_PART_INSTALL/config/device-rfid-llrp/res/provision_watchers/" - for fpath in ./cmd/res/provision_watchers/*.json; do - fname=$(basename "$fpath") - install -DT "./cmd/res/provision_watchers/${fname}" \ - "$SNAPCRAFT_PART_INSTALL/config/device-rfid-llrp/res/provision_watchers/${fname}" - done - - install -DT "./Attribution.txt" \ - "$SNAPCRAFT_PART_INSTALL/usr/share/doc/device-rfid-llrp/Attribution.txt" - install -DT "./LICENSE" \ - "$SNAPCRAFT_PART_INSTALL/usr/share/doc/device-rfid-llrp/LICENSE" - - config-common: + install -DT ./cmd/device-rfid-llrp "$SNAPCRAFT_PART_INSTALL/bin/device-rfid-llrp" + install -DT ./Attribution.txt "$SNAPCRAFT_PART_INSTALL/usr/share/doc/device-rfid-llrp/Attribution.txt" + install -DT ./LICENSE "$SNAPCRAFT_PART_INSTALL/usr/share/doc/device-rfid-llrp/LICENSE" + + LLRP_RES_DIR="$SNAPCRAFT_PART_INSTALL/config/device-rfid-llrp/res/" + mkdir -p "$LLRP_RES_DIR/profiles" + mkdir -p "$LLRP_RES_DIR/devices" + mkdir -p "$LLRP_RES_DIR/provision_watchers" + cp ./cmd/res/configuration.toml "$LLRP_RES_DIR/" + cp ./cmd/res/profiles/*.yaml "$LLRP_RES_DIR/profiles/" + cp ./cmd/res/provision_watchers/*.json "$LLRP_RES_DIR/provision_watchers/" + + + runtime-helpers: plugin: dump source: snap/local/runtime-helpers + + metadata: + plugin: nil + source: https://github.com/canonical/edgex-snap-metadata.git + source-branch: appstream + source-depth: 1 + override-build: | + # install the icon at the default internal path + install -DT edgex-snap-icon.png \ + $SNAPCRAFT_PART_INSTALL/meta/gui/icon.png + # change to this project's repo to get the version + cd $SNAPCRAFT_PROJECT_DIR + if git describe ; then + VERSION=$(git describe --tags --abbrev=0 | sed 's/v//') + else + VERSION="0.0.0" + fi + + # write version to file for the build + echo $VERSION > ./VERSION + # set the version of this snap + snapcraftctl set-version $VERSION + parse-info: [edgex-device-rfid-llrp.metainfo.xml] + + + # copy auto-configure.sh to /bin and make sure curl is installed + auto-configure: + plugin: dump + source: bin/ + stage: + - bin/auto-configure.sh + organize: + auto-configure.sh: bin/auto-configure.sh + stage-packages: + - curl