From 65eb050362f4f1a3493d13f332265893bf7398a2 Mon Sep 17 00:00:00 2001 From: kleph Date: Sun, 1 Mar 2020 01:28:04 +0100 Subject: [PATCH] [CI] Add stating environment --- .drone.yml | 59 ++++++++++++++++++++++++++++------ kube/beer-deployment.yaml | 4 ++- kube/beer-service.yaml | 3 +- kube/staging/beer-ingress.yaml | 17 ++++++++++ kube/staging/beer-service.yaml | 14 ++++++++ 5 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 kube/staging/beer-ingress.yaml create mode 100644 kube/staging/beer-service.yaml diff --git a/.drone.yml b/.drone.yml index 356e1f6..617882e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -57,6 +57,44 @@ steps: depends_on: - unit tests +--- +kind: pipeline +name: staging + +steps: +- name: deploy + image: sinlead/drone-kubectl + settings: + kubernetes_server: + from_secret: kubectl_uri + kubernetes_cert: + from_secret: kubectl_cert + kubernetes_token: + from_secret: kubectl_token + environment: + IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} + NAMESPACE: beer + LEVEL: staging + commands: + - echo "== pre deploy ($${LEVEL}) status:" + - kubectl get pods --namespace=beer + - kubectl get deployments --namespace=beer + - sed "s/__LEVEL__/$${LEVEL}/g" kube/beer-deployment.yaml > kube/beer-deployment-$${LEVEL}.yaml + - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml + - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml + - echo "applying" + - kubectl apply -f kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml --namespace=beer + - echo "== post deploy ($${LEVEL}) status:" + - kubectl get deployments --namespace=beer + - kubectl get pods --namespace=beer + when: + branch: + exclude: + - master + +depends_on: +- build + --- kind: pipeline name: deploy @@ -74,22 +112,23 @@ steps: environment: IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} NAMESPACE: beer + LEVEL: prod commands: - - echo "== pre deploy status:" + - echo "== pre deploy ($${LEVEL}) status:" - kubectl get pods --namespace=beer - kubectl get deployments --namespace=beer - - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment.yaml > kube/beer-deployment-prod.yaml - - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-prod.yaml > kube/beer-deployment-prod2.yaml + - sed "s/__LEVEL__/$${LEVEL}/g" kube/beer-deployment.yaml > kube/beer-deployment-$${LEVEL}.yaml + - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml + - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml - echo "applying" - - kubectl apply -f kube/beer-deployment-prod2.yaml --namespace=beer - - echo "== post deploy status:" + - kubectl apply -f kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml --namespace=beer + - echo "== post deploy ($${LEVEL}) status:" - kubectl get deployments --namespace=beer - kubectl get pods --namespace=beer + when: + branch: + include: + - master depends_on: - build - -when: - branch: - include: - - master diff --git a/kube/beer-deployment.yaml b/kube/beer-deployment.yaml index 5d4aa79..c8256f4 100644 --- a/kube/beer-deployment.yaml +++ b/kube/beer-deployment.yaml @@ -2,17 +2,19 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: beer-deployment + name: beer-deployment-__LEVEL__ namespace: __NAMESPACE__ spec: selector: matchLabels: app: beer + level: __LEVEL__ replicas: 1 template: metadata: labels: app: beer + level: __LEVEL__ spec: containers: - name: beer diff --git a/kube/beer-service.yaml b/kube/beer-service.yaml index 72c2a18..df06902 100644 --- a/kube/beer-service.yaml +++ b/kube/beer-service.yaml @@ -3,10 +3,11 @@ apiVersion: v1 kind: Service metadata: name: beer - namespace: beer + namespace: __NAMESPACE__ spec: selector: app: beer + level: __LEVEL__ ports: - protocol: TCP port: 80 diff --git a/kube/staging/beer-ingress.yaml b/kube/staging/beer-ingress.yaml new file mode 100644 index 0000000..1981cd7 --- /dev/null +++ b/kube/staging/beer-ingress.yaml @@ -0,0 +1,17 @@ +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + name: beer-ingress-staging + namespace: beer + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + rules: + - host: staging.beer.k3s.kleph.eu + http: + paths: + - path: / + backend: + serviceName: beer-staging + servicePort: 80 diff --git a/kube/staging/beer-service.yaml b/kube/staging/beer-service.yaml new file mode 100644 index 0000000..b8db663 --- /dev/null +++ b/kube/staging/beer-service.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: beer-staging + namespace: __NAMESPACE__ +spec: + selector: + app: beer + level: __LEVEL__ + ports: + - protocol: TCP + port: 80 + targetPort: 5000 -- 2.45.2