mirror of
https://github.com/danielgormly/drone-plugin-kube.git
synced 2026-06-04 10:14:53 +08:00
testing release
This commit is contained in:
@@ -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`.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user