diff --git a/README.md b/README.md index a31a2df..df17886 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Add the following [build step](https://docs.drone.io/user-guide/pipeline/steps/) ## deployment templates -Deployment config files are first interpreted by **aymerick/raymond** ([handlebarsjs](http://handlebarsjs.com/) equivalent). You can use all available raymond expressions, [DRONE_*](https://docs.drone.io/reference/environ/), PLUGIN_* environment variables. Use `{{VARIABLE}}` to add interpolated expressions. See [example/deployment.template.yaml](/example/deployment.template.yaml) for a complete example. +Deployment config files are first interpreted by **aymerick/raymond** ([handlebarsjs](http://handlebarsjs.com/) equivalent). You can use all available raymond expressions and anything you put in settings prefixed with the PLUGIN_* environment variables e.g. `{{PLUGIN.NAMESPACE}}`. See [example/deployment.template.yaml](/example/deployment.template.yaml) for a complete example. #### Adding a service account to Kubernetes that can manage deployments See [example/Role.yaml](), `/example/ServiceAccount.yaml`, `/example/RoleBinding.yaml`. diff --git a/example/deployment.template.yaml b/example/deployment.template.yaml index 7c1ea1d..09ea34b 100644 --- a/example/deployment.template.yaml +++ b/example/deployment.template.yaml @@ -1,20 +1,20 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{PLUGIN_NAME}} + name: {{name}} spec: selector: matchLabels: - app: {{PLUGIN_NAME}} + app: {{name}} replicas: 1 template: metadata: labels: - app: {{PLUGIN_NAME}} + app: {{name}} spec: containers: - name: nginx - image: 10.0.0.24:443/image:{{DRONE_COMMIT_SHA}} + image: 10.0.0.24:443/image:{{name}} ports: - containerPort: 80 imagePullSecrets: diff --git a/plugin.go b/plugin.go index bba8894..e661d66 100644 --- a/plugin.go +++ b/plugin.go @@ -1,10 +1,12 @@ package main import ( + "fmt" "io/ioutil" "log" "os" "regexp" + "strings" "github.com/aymerick/raymond" ) @@ -44,14 +46,17 @@ func (p Plugin) Exec() error { } // Make map of environment variables set by Drone ctx := make(map[string]string) - droneEnv := os.Environ() - for _, value := range droneEnv { - re := regexp.MustCompile(`^(DRONE_.*|PLUGIN_.*)=(.*)`) + pluginEnv := os.Environ() + for _, value := range pluginEnv { + re := regexp.MustCompile(`^PLUGIN_(.*)=(.*)`) if re.MatchString(value) { matches := re.FindStringSubmatch(value) - ctx[matches[1]] = matches[2] + key := strings.ToLower(matches[1]) + ctx[key] = matches[2] } } + // TODO: Remove in first release + fmt.Printf("%#v", ctx) // Grab template from filesystem raw, err := ioutil.ReadFile(p.Template) if err != nil { @@ -60,15 +65,16 @@ func (p Plugin) Exec() error { } // Parse template depYaml, err := raymond.Render(string(raw), ctx) + fmt.Printf("%s", depYaml) if err != nil { panic(err) } // Connect to Kubernetes - clientset, err := p.CreateKubeClient() + // clientset, err := p.CreateKubeClient() if err != nil { log.Fatal(err.Error()) } - deployment := CreateDeploymentObj(depYaml) - UpdateDeployment(clientset, p.KubeConfig.Namespace, deployment) + // deployment := CreateDeploymentObj(depYaml) + // UpdateDeployment(clientset, p.KubeConfig.Namespace, deployment) return err }