Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

Commit 2aeba37

Browse files
author
Zac
authoredSep 27, 2019
Merge pull request #1132 from akun1012/yangzongkun/p2-install-hooks-from-p2-preparer-manifest
refined p2-install-hook
2 parents 0645b06 + 4cab97f commit 2aeba37

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed
 

‎bin/p2-install-hook/main.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package main
22

33
import (
4-
"fmt"
54
"log"
65
"os"
76
"path/filepath"
87

98
"gopkg.in/alecthomas/kingpin.v2"
9+
"gopkg.in/yaml.v2"
1010

1111
"github.com/square/p2/pkg/artifact"
1212
"github.com/square/p2/pkg/auth"
@@ -15,6 +15,7 @@ import (
1515
p2manifest "github.com/square/p2/pkg/manifest"
1616
"github.com/square/p2/pkg/osversion"
1717
"github.com/square/p2/pkg/pods"
18+
"github.com/square/p2/pkg/preparer"
1819
"github.com/square/p2/pkg/types"
1920
"github.com/square/p2/pkg/uri"
2021
"github.com/square/p2/pkg/version"
@@ -23,7 +24,7 @@ import (
2324
var (
2425
manifestURI = kingpin.Arg("manifest", "a path or url to a pod manifest that will be installed and launched immediately").URL()
2526
registryURI = kingpin.Arg("registry", "a URL to the registry to download artifacts from").URL()
26-
isPreparerManifest = kingpin.Arg("isPreparerManifest", "to install hooks from a P2-Preparer manifest").Bool()
27+
isPreparerManifest = kingpin.Flag("is-preparer-manifest", "to install hooks from a P2-Preparer manifest").Bool()
2728
nodeName = kingpin.Flag("node-name", "the name of this node (default: hostname)").String()
2829
podRoot = kingpin.Flag("pod-root", "the root of the pods directory").Default(pods.DefaultPath).String()
2930
hookRoot = kingpin.Flag("hook-root", "the root of the hook scripts directory").Default(hooks.DefaultPath).String()
@@ -37,7 +38,7 @@ func main() {
3738
if *nodeName == "" {
3839
hostname, err := os.Hostname()
3940
if err != nil {
40-
log.Fatalf("error getting node name: %v", err)
41+
log.Fatalf("Error getting node name: %v", err)
4142
}
4243
*nodeName = hostname
4344
}
@@ -48,12 +49,19 @@ func main() {
4849
}
4950

5051
if *isPreparerManifest {
51-
config := manifest.GetConfig()
52-
hooksManifest, ok := config["hooks_manifest"]
53-
if ok {
54-
manifest = hooksManifest.(p2manifest.Manifest)
55-
} else {
56-
fmt.Printf("Error to read hooks manifest from P2-Preparer manifest: %v", manifest)
52+
preparerConfigBytes, err := yaml.Marshal(manifest.GetConfig())
53+
if err != nil {
54+
log.Printf("Unable to marshal preparer config: %v", err)
55+
}
56+
57+
preparerConfig, err := preparer.UnmarshalConfig(preparerConfigBytes)
58+
if err != nil {
59+
log.Printf("Could not properly unmarshal p2-preparer config from YAML: %v", err)
60+
}
61+
62+
manifest, err = p2manifest.FromBytes([]byte(preparerConfig.HooksManifest))
63+
if err != nil {
64+
log.Fatalf("Error to read hooks manifest from P2-Preparer manifest: %v", manifest)
5765
}
5866
}
5967

0 commit comments

Comments
 (0)
This repository has been archived.