Skip to content

Commit

Permalink
Merge pull request #4186 from farshidtz/snap-refactor-merge-hooks
Browse files Browse the repository at this point in the history
refactor(snap): Merge snap hook packages
  • Loading branch information
cloudxxx8 authored Oct 7, 2022
2 parents 07636ef + 822255d commit 47dc433
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 48 deletions.
3 changes: 3 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec $SNAP/bin/helper-go configure
3 changes: 3 additions & 0 deletions snap/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec $SNAP/bin/helper-go install
8 changes: 8 additions & 0 deletions snap/local/helper-go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build:
go build -ldflags="-s -w" -o helper-go

tidy:
go mod tidy

clean:
rm -f helper-go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ func checkSecurityConfig(services []string) ([]string, error) {
}

func configure() {
// process the EdgeX >=2.2 app options
processAppOptions()

var debug = false
var err error
var startServices []string
Expand Down
6 changes: 3 additions & 3 deletions snap/local/hooks/go.mod → snap/local/helper-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/canonical/edgex-go/hooks

require github.com/canonical/edgex-snap-hooks/v2 v2.4.1
module github.com/edgexfoundry/edgex-go/snap/local/helper-go

go 1.18

require github.com/canonical/edgex-snap-hooks/v2 v2.4.1
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
hooks "github.com/canonical/edgex-snap-hooks/v2"
)

var cli *hooks.CtlCli = hooks.NewSnapCtl()

const secretStoreAddTokensCfg = "env.security-secret-store.add-secretstore-tokens"
const secretStoreAddKnownSecretsCfg = "env.security-secret-store.add-known-secrets"
const consulAddRegistryACLRolesCfg = "env.security-bootstrapper.add-registry-acl-roles"
Expand Down Expand Up @@ -325,7 +323,7 @@ func installRedis() error {
return nil
}

func main() {
func install() {
var debug = false
var err error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@ import (
var cli *hooks.CtlCli = hooks.NewSnapCtl()

func main() {
// no subcommand, as called by snapd
if len(os.Args) == 1 {
// process the EdgeX >=2.2 snap options
processAppOptions()
// configure everything else, incl. the legacy snap options
configure()
return
}

subCommand := os.Args[1]
switch subCommand {
case "options":
// configure options
case "install": // snap install hook
install()
case "configure": // snap configure hook
configure()
case "options": // apply snap options to apps
options()
default:
panic("Unknown CLI sub-command: " + subCommand)
panic("Unknown subcommand: " + subCommand)
}
}
File renamed without changes.
24 changes: 0 additions & 24 deletions snap/local/hooks/Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions snap/local/runtime-helpers/bin/security-proxy-post-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export PATH="$SNAP/bin:$PATH"

# Several config options depend on resources that only exist after proxy
# setup. This re-applies the config options logic after deferred startup:
$SNAP/snap/hooks/configure options --service=security-proxy
$SNAP/bin/helper-go options --service=security-proxy

# Process the EdgeX >=2.2 snap options
$SNAP/snap/hooks/configure options --service=secrets-config
$SNAP/bin/helper-go options --service=secrets-config
7 changes: 3 additions & 4 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,14 @@ parts:
plugin: dump
source: snap/local/runtime-helpers

hooks:
source: snap/local/hooks
helper-go:
source: snap/local/helper-go
plugin: make
after: [go-build-helper]
override-build: |
cd $SNAPCRAFT_PART_SRC
make build
install -DT ./cmd/configure/configure "$SNAPCRAFT_PART_INSTALL/snap/hooks/configure"
install -DT ./cmd/install/install "$SNAPCRAFT_PART_INSTALL/snap/hooks/install"
install -DT ./helper-go $SNAPCRAFT_PART_INSTALL/bin/helper-go
consul:
plugin: nil
Expand Down

0 comments on commit 47dc433

Please sign in to comment.