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): use updated environment variable injection #365

Conversation

MonicaisHer
Copy link
Contributor

@MonicaisHer MonicaisHer commented Apr 20, 2022

For details on the new scheme for setting environment variables, please refer to edgexfoundry/edgex-go#3986.

Co-authored-by: Siggi Skulason [email protected]
Signed-off-by: Mengyi Wang [email protected]

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/device-mqtt-go/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?) N/A - they are in the imported module Add tests for snap config options canonical/edgex-snap-testing#53
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?)

Testing Instructions

  1. set up:
snap install edgexfoundry --edge
snap install edgex-device-mqtt --channel="edge/pr-365"
  1. Enable config and set a global config value:
$ snap set edgex-device-mqtt config-enabled=true
$ snap set edgex-device-mqtt config.service-startupmsg="testing injection"

$ snap start edgex-device-mqtt
Started.

$ snap logs -n=all edgex-device-mqtt | grep "testing injection"
2022-04-26T11:07:27+02:00 edgex-device-mqtt.device-mqtt[1750732]: ++ export 'SERVICE_STARTUPMSG=testing injection'
2022-04-26T11:07:27+02:00 edgex-device-mqtt.device-mqtt[1750732]: ++ SERVICE_STARTUPMSG='testing injection'
2022-04-26T11:07:28+02:00 edgex-device-mqtt.device-mqtt[1750732]: level=INFO ts=2022-04-26T09:07:28.360080301Z app=device-mqtt source=variables.go:352 msg="Variables override of 'Service.StartupMsg' by environment variable: SERVICE_STARTUPMSG=testing injection"
  1. Set a app-specific value:
$ snap set edgex-device-mqtt apps.device-mqtt.config.service-port=11111

$ snap restart edgex-device-mqtt
Restarted.

$ snap logs -n=all edgex-device-mqtt | grep "11111"
msg="Web server starting (localhost:11111)"

New Dependency Instructions (If applicable)

@MonicaisHer
Copy link
Contributor Author

@farshidtz Could you please review this? Thanks.

@MonicaisHer MonicaisHer force-pushed the EDGEX-421-integrate-env-var-injection-with-device-mqtt-snap branch from 4e97571 to d466526 Compare April 22, 2022 08:43
@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2022

Codecov Report

Merging #365 (119d050) into main (4d191eb) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #365   +/-   ##
=======================================
  Coverage   21.34%   21.34%           
=======================================
  Files           5        5           
  Lines         492      492           
=======================================
  Hits          105      105           
  Misses        374      374           
  Partials       13       13           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d191eb...119d050. Read the comment docs.

@MonicaisHer MonicaisHer force-pushed the EDGEX-421-integrate-env-var-injection-with-device-mqtt-snap branch from d466526 to c499bde Compare April 22, 2022 08:57
@MonicaisHer MonicaisHer marked this pull request as draft April 22, 2022 09:02
@MonicaisHer
Copy link
Contributor Author

MonicaisHer commented Apr 22, 2022

This PR will be ready for merge, once the new hook has been tagged and imported by this PR.

@MonicaisHer MonicaisHer marked this pull request as ready for review April 26, 2022 09:08
@MonicaisHer MonicaisHer requested a review from farshidtz April 26, 2022 09:30
Copy link
Member

@farshidtz farshidtz left a comment

Choose a reason for hiding this comment

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

Please upgrade edgex-snap-hooks to beta.5 and go mod tidy.

@MonicaisHer MonicaisHer requested a review from farshidtz April 26, 2022 09:39
Copy link
Member

@farshidtz farshidtz left a comment

Choose a reason for hiding this comment

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

Thanks. Works as expected:

$ snap install edgex-device-mqtt --channel="edge/pr-365"
edgex-device-mqtt (edge/pr-365) 2.2.0-dev.15 from Canonical✓ installed

# Verify error handling
$ snap set edgex-device-mqtt config.service-startupmsg="testing injection"
error: cannot perform the following tasks:
- Run configure hook of "edgex-device-mqtt" snap (run hook "configure": 
-----
edgex-device-mqtt.configure: could not process options: 'config.' and 'apps.' options are allowed only when config-enabled is true.

WARNING: Setting config-enabled=true will unset existing 'env.' options and ignore future sets!!
-----)

$ snap set edgex-device-mqtt config-enabled=true
$ snap set edgex-device-mqtt config.service.startupmsg="testing injection"
error: cannot perform the following tasks:
- Run configure hook of "edgex-device-mqtt" snap (run hook "configure": edgex-device-mqtt.configure: could not process options: error converting config key to environment variable key: config key must not contain dots: service.startupmsg)

# Test global config
$ snap set edgex-device-mqtt config.service-startupmsg="testing injection"
$ snap start edgex-device-mqtt
Started.
$ snap logs -n=all edgex-device-mqtt | grep "testing injection"
2022-04-26T11:42:18+02:00 edgex-device-mqtt.device-mqtt[54398]: ++ export 'SERVICE_STARTUPMSG=testing injection'
2022-04-26T11:42:18+02:00 edgex-device-mqtt.device-mqtt[54398]: ++ SERVICE_STARTUPMSG='testing injection'
2022-04-26T11:42:19+02:00 edgex-device-mqtt.device-mqtt[54398]: level=INFO ts=2022-04-26T09:42:19.024095794Z app=device-mqtt source=variables.go:352 msg="Variables override of 'Service.StartupMsg' by environment variable: SERVICE_STARTUPMSG=testing injection"

# test app-specific config
$ snap set edgex-device-mqtt apps.device-mqtt.config.service-port=11111
$ snap restart edgex-device-mqtt
Restarted.
$ snap logs -n=all edgex-device-mqtt | grep "11111"
2022-04-26T11:43:08+02:00 edgex-device-mqtt.device-mqtt[54629]: ++ export SERVICE_PORT=11111
2022-04-26T11:43:08+02:00 edgex-device-mqtt.device-mqtt[54629]: ++ SERVICE_PORT=11111
2022-04-26T11:43:08+02:00 edgex-device-mqtt.device-mqtt[54629]: level=INFO ts=2022-04-26T09:43:08.378704974Z app=device-mqtt source=variables.go:352 msg="Variables override of 'Service.Port' by environment variable: SERVICE_PORT=11111"

# check the env file
$ cat /var/snap/edgex-device-mqtt/current/config/device-mqtt/res/device-mqtt.env 
export SERVICE_STARTUPMSG="testing injection"
export SERVICE_PORT="11111"

@lenny-goodell lenny-goodell merged commit cac5c8a into edgexfoundry:main Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants