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

build(snap): Upgrade snap base to core22, upgrade env file loading logic #4530

Merged
merged 3 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion snap/local/helper-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/edgexfoundry/edgex-go/snap/local/helper-go

go 1.18

require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab
require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230413215958-a96e2a6a0cc6
2 changes: 2 additions & 0 deletions snap/local/helper-go/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab h1:wpiKN0hX8tqeZNa4jPvgyrqP8ixm1Xu7lcQA3bypR7w=
github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY=
github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230413215958-a96e2a6a0cc6 h1:VTttaJT+dJBM94EU9c2fCewIv0y7m6PVI4D134Bk6d0=
github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230413215958-a96e2a6a0cc6/go.mod h1:qGZwprCZGZk2pA9BrleUtSrGrfHIaIz1356p8aqzuN4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
Expand Down
11 changes: 9 additions & 2 deletions snap/local/helper-go/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,15 @@ func install() {

var err error

if err = installConfFiles(); err != nil {
log.Fatalf("Error installing config files: %v", err)
// Install default config files only if no config provider is connected
isConnected, err := snapctl.IsConnected("edgex-config").Run()
if err != nil {
log.Fatalf("Error checking interface connection: %s", err)
}
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
if !isConnected {
if err = installConfFiles(); err != nil {
log.Fatalf("Error installing config files: %v", err)
}
}

if err = installSecretStore(); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/bin/bash -ex
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved

# convert cmdline to string array
ARGV=($@)
Expand All @@ -8,18 +8,15 @@ BINPATH="${ARGV[0]}"

# binary name == service name/key
SERVICE=$(basename "$BINPATH")
if [ -z $ENV_FILE ]; then
ENV_FILE="$SNAP_DATA/config/$SERVICE/res/$SERVICE.env"
fi
Comment on lines -11 to -13
Copy link
Member

@farshidtz farshidtz May 8, 2023

Choose a reason for hiding this comment

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

This removes the possibility of passing $ENV_FILE from outside. The security-consul-bootstrapper and security-bootstrapper-redis apps use a different path, set inside the snapcraft.yaml file.

ENV_FILE="$SNAP_DATA/config/$SERVICE/overrides.env"
TAG="edgex-$SERVICE."$(basename "$0")

if [ -f "$ENV_FILE" ]; then
logger --tag=$TAG "sourcing $ENV_FILE"
set -o allexport
source "$ENV_FILE" set
set +o allexport
else
logger --tag=$TAG --stderr "sourcing $ENV_FILE: not found!"
set +o allexport
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
fi

exec "$@"

Loading