mirror of
https://github.com/danielgormly/drone-plugin-kube.git
synced 2026-06-04 18:23:48 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 438081953b | |||
| f9f8d9aa49 | |||
| cd888d5ff8 | |||
| ddac2b3969 |
@@ -14,10 +14,9 @@ See [example/Role.yaml](example/Role.yaml), [example/ServiceAccount.yaml](exampl
|
||||
- The watching process is not currently reliable i.e. it doesn't properly wait for new deployments to become live. Not entirely sure how this should behave but I think behind a flag would make sense. PRs welcome.
|
||||
|
||||
## Development notes
|
||||
- Kubernetes client is a little confusing with dependencies but does work with go.mod as seen [here](https://github.com/kubernetes/client-go/blob/master/INSTALL.md#add-client-go-as-a-dependency)
|
||||
- [kubernetes/client-go installation notes](https://github.com/kubernetes/client-go/blob/master/INSTALL.md)
|
||||
- [Creating a Drone plugin in Go](https://docs.drone.io/plugins/tutorials/golang/)
|
||||
- [Client-go API Docs @ godoc.org](https://godoc.org/k8s.io/client-go/kubernetes)
|
||||
- [Creating a Drone plugin in Go](https://docs.drone.io/plugins/golang/)
|
||||
- [Client-go API Docs @ godoc.org](https://pkg.go.dev/k8s.io/client-go/kubernetes?tab=doc)
|
||||
- Testing with minikube (OSX: `brew cask install minikube`)
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
@@ -5,5 +5,6 @@ set -eou pipefail
|
||||
rm -rf build/kubano
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o build/kubano
|
||||
|
||||
docker build -t danielgormly/drone-plugin-kube:0.1.0 build
|
||||
docker push danielgormly/drone-plugin-kube:0.1.0
|
||||
docker build -t danielgormly/drone-plugin-kube:0.2.0 -t danielgormly/drone-plugin-kube:latest build
|
||||
docker push danielgormly/drone-plugin-kube:0.2.0
|
||||
docker push danielgormly/drone-plugin-kube:latest
|
||||
|
||||
@@ -15,7 +15,7 @@ Create or update deployment
|
||||
```yaml
|
||||
pipeline:
|
||||
- name: Deploy app
|
||||
image: danielgormly/drone-plugin-kube:0.0.1
|
||||
image: danielgormly/drone-plugin-kube:0.2.0
|
||||
settings:
|
||||
template: path/to/deployment.yaml # relative to repo root
|
||||
ca: LS0tLS1... # BASE64 encoded string of the K8s CA cert
|
||||
@@ -29,7 +29,7 @@ Create or update config-map from a single file
|
||||
```diff
|
||||
pipeline:
|
||||
- name: Deploy app
|
||||
image: danielgormly/drone-plugin-kube:0.0.1
|
||||
image: danielgormly/drone-plugin-kube:0.2.0
|
||||
settings:
|
||||
- template: path/to/deployment.yaml
|
||||
+ template: path/to/config-map.yaml
|
||||
@@ -42,23 +42,75 @@ pipeline:
|
||||
|
||||
# Parameter Reference
|
||||
|
||||
ca
|
||||
: Base-64 encoded string of the K8s CA cert
|
||||
| Value | Key |
|
||||
|------------------|------------------------------------------------------------------------------------------------------------------------------|
|
||||
| ca | Base-64 encoded string of the K8s CA cert |
|
||||
| server | https://10.0.0.20:6443 |
|
||||
| namespace | Namespace to deploy to |
|
||||
| kubernetes_token | Kubernetes service account token (Not base64 encoded) |
|
||||
| template | Path to Kubernetes yaml based definition file (Configmap or Deployment). Relative to Git basedir. |
|
||||
| configmap_file | Path to file containing data to inject in configmap (They configmap key that contains the data will be the filename) |
|
||||
| * | Other parameters will be made available for interpolation within yaml templates (upper-case will be converted to lower-case) |
|
||||
|
||||
server
|
||||
: https://10.0.0.20:6443
|
||||
## Template Substitution
|
||||
|
||||
namespace
|
||||
: Namespace to deploy to
|
||||
You can substitute values in the deployment template files. But first you have to define the variables.
|
||||
|
||||
kubernetes_token
|
||||
: Kubernetes service account token (Not base64 encoded)
|
||||
```yaml {4-5}
|
||||
- name: Deploy K8s - Workload
|
||||
image: danielgormly/drone-plugin-kube:0.0.2
|
||||
settings:
|
||||
build_number: ${DRONE_BUILD_NUMBER}
|
||||
template: deployment.yaml
|
||||
ca:
|
||||
from_secret: k8s_cert
|
||||
server:
|
||||
from_secret: k8s_server
|
||||
token:
|
||||
from_secret: k8s_token
|
||||
```
|
||||
|
||||
template
|
||||
: Path to Kubernetes yaml based definition file (Configmap or Deployment)
|
||||
You can substitute the following values between ```{{ }}``` in your deployment template.
|
||||
Example `deployment.yaml`:
|
||||
|
||||
configmap_file
|
||||
: path to file containing data to inject in configmap (They configmap key that contains the data will be the filename)
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
namespace: wiki
|
||||
labels:
|
||||
app: wiki
|
||||
name: wiki
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: wiki
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: wiki
|
||||
spec:
|
||||
containers:
|
||||
- image: registry.example.com/wiki:{{ build_number }}
|
||||
imagePullPolicy: Always
|
||||
name: wiki
|
||||
```
|
||||
|
||||
`*`
|
||||
: Other parameters will be made available for interpolation within yaml templates (upper-case will be converted to lower-case)
|
||||
### Template Reference
|
||||
|
||||
| Key | Value |
|
||||
|---------------|----------------------------------------------------------------------------------|
|
||||
| repo.owner | repository owner |
|
||||
| repo.name | repository name |
|
||||
| build.status | build status type enumeration, either `success` or `failure` |
|
||||
| build.event | build event type enumeration, one of `push`, `pull_request`, `tag`, `deployment` |
|
||||
| build.number | build number |
|
||||
| build.commit | git sha for current commit |
|
||||
| build.branch | git branch for current commit |
|
||||
| build.tag | git tag for current commit |
|
||||
| build.ref | git ref for current commit |
|
||||
| build.author | git author for current commit |
|
||||
| build.link | link the the build results in drone |
|
||||
| build.created | unix timestamp for build creation |
|
||||
| build.started | unix timestamp for build started |
|
||||
|
||||
@@ -19,7 +19,7 @@ func main() {
|
||||
},
|
||||
}
|
||||
fmt.Printf(os.Getenv("PLUGIN_SKIP_TLS"))
|
||||
fmt.Println("danielgormly/drone-plugin-kube@0.1.0 https://github.com/danielgormly/drone-plugin-kube")
|
||||
fmt.Println("danielgormly/drone-plugin-kube@0.2.0 https://github.com/danielgormly/drone-plugin-kube")
|
||||
err := plugin.Exec()
|
||||
if err != nil {
|
||||
log.Fatalf("⛔️ Fatal error: \n%s", err)
|
||||
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
export PLUGIN_TEMPLATE=test/service.template.yaml
|
||||
export PLUGIN_NAME=drone-kube-test
|
||||
export PLUGIN_NAMESPACE=default
|
||||
|
||||
go build -o build/kubano
|
||||
export $(cat .env | xargs) && ./build/kubano
|
||||
|
||||
# docker run --env-file=.env drone-kubano
|
||||
@@ -0,0 +1,14 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wiki-http
|
||||
namespace: default
|
||||
spec:
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
protocol: TCP
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: wiki
|
||||
type: ClusterIP
|
||||
Reference in New Issue
Block a user