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 #177

Conversation

MonicaisHer
Copy link
Contributor

@MonicaisHer MonicaisHer commented Apr 21, 2022

For details on the new scheme for setting environment variables, please refer to edgexfoundry/edgex-go#3986.
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-rest-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-rest --channel="edge/pr-177"
  1. Enable config and set a global config value:
$ snap set edgex-device-rest config-enabled=true
$ snap set edgex-device-rest config.service-startupmsg="testing injection"

$ snap start edgex-device-rest
Started.

$ snap logs -n=all edgex-device-rest | grep "testing injection"
...
  1. Set a app-specific value:
$ snap set edgex-device-rest apps.device-rest.config.service-port=11111

$ snap restart edgex-device-rest
Restarted.

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

New Dependency Instructions (If applicable)

@MonicaisHer MonicaisHer marked this pull request as ready for review April 21, 2022 11:48
@MonicaisHer MonicaisHer marked this pull request as draft April 22, 2022 06:28
@MonicaisHer MonicaisHer marked this pull request as ready for review April 22, 2022 06:30
@MonicaisHer MonicaisHer marked this pull request as ready for review April 26, 2022 08:21
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.

Looks good. Thanks.

$ snap install edgex-device-rest --channel="edge/pr-177"
edgex-device-rest (edge/pr-177) 2.0.1-dev.14 from Canonical✓ installed

$ snap set edgex-device-rest config.service-startupmsg="testing injection"
error: cannot perform the following tasks:
- Run configure hook of "edgex-device-rest" snap (run hook "configure": 
-----
edgex-device-rest.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!!
-----)
# the above error was expected

$ snap set edgex-device-rest config-enabled=true
$ snap set edgex-device-rest config.service-startupmsg="testing injection"
$ snap start edgex-device-rest
Started.
$  snap logs -n=all edgex-device-rest | grep "testing injection"
2022-04-26T10:51:16+02:00 edgex-device-rest.device-rest[46017]: level=INFO ts=2022-04-26T08:51:16.959910144Z app=device-rest source=variables.go:352 msg="Variables override of 'Service.StartupMsg' by environment variable: SERVICE_STARTUPMSG=testing injection"
2022-04-26T10:51:17+02:00 edgex-device-rest.device-rest[46017]: level=INFO ts=2022-04-26T08:51:17.25412312Z app=device-rest source=message.go:55 msg="testing injection"


$ snap set edgex-device-rest apps.device-rest.config.service-port=11111
$ snap restart edgex-device-rest
Restarted.
$ snap logs -n=all edgex-device-rest | grep "11111"
2022-04-26T10:51:36+02:00 edgex-device-rest.device-rest[46210]: level=INFO ts=2022-04-26T08:51:36.016478222Z app=device-rest source=variables.go:352 msg="Variables override of 'Service.Port' by environment variable: SERVICE_PORT=11111"
2022-04-26T10:51:36+02:00 edgex-device-rest.device-rest[46210]: level=INFO ts=2022-04-26T08:51:36.028125377Z app=device-rest source=variables.go:352 msg="Variables override of 'Service.Port' by environment variable: SERVICE_PORT=11111"
2022-04-26T10:51:36+02:00 edgex-device-rest.device-rest[46210]: level=INFO ts=2022-04-26T08:51:36.054827968Z app=device-rest source=httpserver.go:123 msg="Web server starting (localhost:11111)"

@lenny-goodell lenny-goodell merged commit b5c3ad0 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.

3 participants