UKHomeOffice-attic / drone-kubernetes

Drone plugin to deploy artifacts to Kubernetes
Apache License 2.0
33 stars 6 forks source link

Enable using Build vars inside of the RCs #2

Closed ipedrazas closed 8 years ago

ipedrazas commented 8 years ago

When deploying an RC to Kubernetes, it would be good if the $BUILD_ID var could be used, so we deploy the RC with the image we're just building

ipedrazas commented 8 years ago

In reality, what we want to add to the RCs is the tag of the image, so, I've added that functionality.

You can do this:

apiVersion: v1
kind: ReplicationController
metadata:
  labels:
    name: nginx
  name: nginx
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
      - image: nginx:{{ .TAG }}
        name: nginx
        ports:
        - name: nginx
          containerPort: 8000

You need to define the tag in the drone file, the plugin will resolve that tag and set the value in the RC:

deploy:
  kubernetes:
    image: quay.io/ukhomeofficedigital/drone-kubernetes
    registry: quay.io
    replicationcontrollers:
      - kubernetes/app-rc.yaml
    services: []
    token: $$TOKEN
    apiserver: https://kubeapi-dev.dsp.notprod.homeoffice.gov.uk:6443
    namespace: default
    debug: false
    tag: v1.4.$$BUILD_NUMBER

But be aware that you have to use the same tag in the publish section:

publish:
  docker:
    registry: quay.io
    username: $$QUAY_USER
    password: $$QUAY_PASSWORD
    email: $$QUAY_EMAIL
    repo: quay.io/ukhomeofficedigital/deep-ui
    storage_driver: vfs
    tag:
      - latest
      - v1.4.$$BUILD_NUMBER
    when:
      branch: master

    branch: master