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

Conversation

MonicaisHer
Copy link
Contributor

@MonicaisHer MonicaisHer commented Apr 22, 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/app-service-configurable/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-app-service-configurable --channel="edge/pr-407"
snap set edgex-app-service-configurable profile=rules-engine
  1. Enable config and set a global config value:
$ snap set edgex-app-service-configurable config-enabled=true
$ snap set edgex-app-service-configurable config.service-startupmsg="testing injection"

$ snap start edgex-app-service-configurable
Started.

$ snap logs -n=all edgex-app-service-configurable | grep "testing injection"
app=app-rules-engine source=service.go:203 msg="testing injection"
  1. Set a app-specific value:
$ snap set edgex-app-service-configurable apps.app-service-configurable.config.service-port=11111

$ snap restart edgex-app-service-configurable
Restarted.

$ snap logs -n=all edgex-app-service-configurable | grep "11111"
msg="Starting HTTP Web Server on address localhost:11111"

New Dependency Instructions (If applicable)

@MonicaisHer MonicaisHer marked this pull request as ready for review April 26, 2022 08:40
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. LGTM.

Validate the error handling:

$ snap set edgex-app-service-configurable config.service-startupmsg="testing injection"
error: cannot perform the following tasks:
- Run configure hook of "edgex-app-service-configurable" snap (run hook "configure": 
-----
edgex-app-service-configurable.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-app-service-configurable config-enabled=true
$ snap set edgex-app-service-configurable apps.app-service-configurable.config.service.port=11111
error: cannot perform the following tasks:
- Run configure hook of "edgex-app-service-configurable" snap (run hook "configure": edgex-app-service-configurable.configure: could not process options: error converting config key to environment variable key: config key must not contain dots: service.port)

Test:

$ snap set edgex-app-service-configurable config-enabled=true
$ snap set edgex-app-service-configurable config.service-startupmsg="testing injection"
$ snap start edgex-app-service-configurable 
Started.
$ snap logs -n=all edgex-app-service-configurable | grep "testing injection"
2022-04-26T11:19:13+02:00 edgex-app-service-configurable.app-service-configurable[50155]: level=INFO ts=2022-04-26T09:19:13.04886399Z app=app-rules-engine source=variables.go:352 msg="Variables override of 'Service.StartupMsg' by environment variable: SERVICE_STARTUPMSG=testing injection"
2022-04-26T11:19:13+02:00 edgex-app-service-configurable.app-service-configurable[50155]: level=INFO ts=2022-04-26T09:19:13.073178783Z app=app-rules-engine source=variables.go:352 msg="Variables override of 'Service.StartupMsg' by environment variable: SERVICE_STARTUPMSG=testing injection"
2022-04-26T11:19:13+02:00 edgex-app-service-configurable.app-service-configurable[50155]: level=INFO ts=2022-04-26T09:19:13.104004057Z app=app-rules-engine source=service.go:203 msg="testing injection"

$ snap set edgex-app-service-configurable apps.app-service-configurable.config.service-port=11111
$ snap restart edgex-app-service-configurable
Restarted.
$ snap logs -n=all edgex-app-service-configurable | grep "11111"
2022-04-26T11:19:49+02:00 edgex-app-service-configurable.app-service-configurable[50464]: level=INFO ts=2022-04-26T09:19:49.654567422Z app=app-rules-engine source=variables.go:352 msg="Variables override of 'Service.Port' by environment variable: SERVICE_PORT=11111"
2022-04-26T11:19:49+02:00 edgex-app-service-configurable.app-service-configurable[50464]: level=INFO ts=2022-04-26T09:19:49.669203327Z app=app-rules-engine source=variables.go:352 msg="Variables override of 'Service.Port' by environment variable: SERVICE_PORT=11111"
2022-04-26T11:19:49+02:00 edgex-app-service-configurable.app-service-configurable[50464]: level=INFO ts=2022-04-26T09:19:49.696564382Z app=app-rules-engine source=server.go:162 msg="Starting HTTP Web Server on address localhost:11111"

$ cat /var/snap/edgex-app-service-configurable/current/config/res/app-service-configurable.env 
export SERVICE_STARTUPMSG="testing injection"
export SERVICE_PORT="11111"

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