From e7e56e71de8a74653da5fdde9d1973e2fc3ca4e8 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 13 Mar 2023 17:14:23 +0100 Subject: [PATCH 1/5] fix(snap): Install config files if config provider not connected Signed-off-by: Farshid Tavakolizadeh --- snap/local/helper-go/go.mod | 2 +- snap/local/helper-go/go.sum | 4 ++-- snap/local/helper-go/install.go | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/snap/local/helper-go/go.mod b/snap/local/helper-go/go.mod index 883c681e..c2331368 100644 --- a/snap/local/helper-go/go.mod +++ b/snap/local/helper-go/go.mod @@ -2,4 +2,4 @@ module github.com/edgexfoundry/device-virtual-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-20230313153812-9fa2de06febe diff --git a/snap/local/helper-go/go.sum b/snap/local/helper-go/go.sum index 81198834..69d8c3d3 100644 --- a/snap/local/helper-go/go.sum +++ b/snap/local/helper-go/go.sum @@ -1,5 +1,5 @@ -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-20230313153812-9fa2de06febe h1:K8n3V60fZ4JYJyMLI/HmmVd9wo5J5iYUWm4HoqR1P8o= +github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230313153812-9fa2de06febe/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY= 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= diff --git a/snap/local/helper-go/install.go b/snap/local/helper-go/install.go index 00b9a53e..a9181a99 100644 --- a/snap/local/helper-go/install.go +++ b/snap/local/helper-go/install.go @@ -20,6 +20,7 @@ import ( hooks "github.com/canonical/edgex-snap-hooks/v3" "github.com/canonical/edgex-snap-hooks/v3/env" "github.com/canonical/edgex-snap-hooks/v3/log" + "github.com/canonical/edgex-snap-hooks/v3/snapctl" ) func installConfig() error { @@ -38,7 +39,14 @@ func installConfig() error { func install() { log.SetComponentName("install") - if err := installConfig(); err != nil { - log.Fatalf("Error installing config files: %s", err) + // Install default config files only if no config provider is connected + isConnected, err := snapctl.IsConnected("device-virtual-config").Run() + if err != nil { + log.Fatalf("Error checking interface connection: %s", err) + } + if !isConnected { + if err := installConfig(); err != nil { + log.Fatalf("Error installing config files: %s", err) + } } } From 8c20a81451d58475166c968c4a821231ec79c87b Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 13 Mar 2023 17:16:09 +0100 Subject: [PATCH 2/5] fix(snap): Source config file from always readable directory Signed-off-by: Farshid Tavakolizadeh --- snap/local/bin/source-env-file.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/snap/local/bin/source-env-file.sh b/snap/local/bin/source-env-file.sh index 7c2dd66f..81914a5e 100755 --- a/snap/local/bin/source-env-file.sh +++ b/snap/local/bin/source-env-file.sh @@ -8,15 +8,14 @@ BINPATH="${ARGV[0]}" # binary name == service name/key SERVICE=$(basename "$BINPATH") -SERVICE_ENV="$SNAP_DATA/config/$SERVICE/res/$SERVICE.env" +ENV_FILE="$SNAP_DATA/config/$SERVICE/overrides.env" TAG="edgex-$SERVICE."$(basename "$0") -if [ -f "$SERVICE_ENV" ]; then - logger --tag=$TAG "sourcing $SERVICE_ENV" +if [ -f "$ENV_FILE" ]; then + logger --tag=$TAG "sourcing $ENV_FILE" set -o allexport - source "$SERVICE_ENV" set - set +o allexport + source "$ENV_FILE" set + set +o allexport fi exec "$@" - From 1fa5c9f5e2a7f631fc1e0ca6fd6412945aa5e337 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Tue, 14 Mar 2023 13:55:24 +0100 Subject: [PATCH 3/5] build(snap): Bump edgex-snap-hooks Signed-off-by: Farshid Tavakolizadeh --- snap/local/helper-go/go.mod | 2 +- snap/local/helper-go/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snap/local/helper-go/go.mod b/snap/local/helper-go/go.mod index c2331368..6d6096ee 100644 --- a/snap/local/helper-go/go.mod +++ b/snap/local/helper-go/go.mod @@ -2,4 +2,4 @@ module github.com/edgexfoundry/device-virtual-go/snap/local/helper-go go 1.18 -require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230313153812-9fa2de06febe +require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230314124606-41d5484d553c diff --git a/snap/local/helper-go/go.sum b/snap/local/helper-go/go.sum index 69d8c3d3..1cc33aba 100644 --- a/snap/local/helper-go/go.sum +++ b/snap/local/helper-go/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230313153812-9fa2de06febe h1:K8n3V60fZ4JYJyMLI/HmmVd9wo5J5iYUWm4HoqR1P8o= -github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230313153812-9fa2de06febe/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY= +github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230314124606-41d5484d553c h1:vczXWfkbZBAQpqU5R5qlCYX3h30NbOXVpoHSq8HZBn4= +github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230314124606-41d5484d553c/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY= 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= From deec1eaa4d3cef402d0d658292a0f698ca130a04 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Tue, 14 Mar 2023 13:59:38 +0100 Subject: [PATCH 4/5] refactor(snap): use constant for app name Signed-off-by: Farshid Tavakolizadeh --- snap/local/helper-go/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/local/helper-go/install.go b/snap/local/helper-go/install.go index a9181a99..2c42e53d 100644 --- a/snap/local/helper-go/install.go +++ b/snap/local/helper-go/install.go @@ -40,7 +40,7 @@ func install() { log.SetComponentName("install") // Install default config files only if no config provider is connected - isConnected, err := snapctl.IsConnected("device-virtual-config").Run() + isConnected, err := snapctl.IsConnected(app + "-config").Run() if err != nil { log.Fatalf("Error checking interface connection: %s", err) } From f4aa25c481686a6f2c13da3f17e831db9f91a5c8 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Wed, 15 Mar 2023 10:29:17 +0100 Subject: [PATCH 5/5] build(snap): Bump edgex-snap-hooks Signed-off-by: Farshid Tavakolizadeh --- snap/local/helper-go/go.mod | 2 +- snap/local/helper-go/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snap/local/helper-go/go.mod b/snap/local/helper-go/go.mod index 6d6096ee..46ce0c0c 100644 --- a/snap/local/helper-go/go.mod +++ b/snap/local/helper-go/go.mod @@ -2,4 +2,4 @@ module github.com/edgexfoundry/device-virtual-go/snap/local/helper-go go 1.18 -require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230314124606-41d5484d553c +require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230315092647-3e5be341fbd0 diff --git a/snap/local/helper-go/go.sum b/snap/local/helper-go/go.sum index 1cc33aba..6e2f75a7 100644 --- a/snap/local/helper-go/go.sum +++ b/snap/local/helper-go/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230314124606-41d5484d553c h1:vczXWfkbZBAQpqU5R5qlCYX3h30NbOXVpoHSq8HZBn4= -github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230314124606-41d5484d553c/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY= +github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230315092647-3e5be341fbd0 h1:JfHMf7jDblOMgFBbJpLI4srXjQolVDNJmsT8M6oumKY= +github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230315092647-3e5be341fbd0/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY= 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=