[CI] Add stating environment #6

Merged
kleph merged 1 commit from staging into master 2020-03-01 02:37:52 +01:00
5 changed files with 85 additions and 12 deletions
Showing only changes of commit 65eb050362 - Show all commits

View file

@ -57,6 +57,44 @@ steps:
depends_on: depends_on:
- unit tests - 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 kind: pipeline
name: deploy name: deploy
@ -74,22 +112,23 @@ steps:
environment: environment:
IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8}
NAMESPACE: beer NAMESPACE: beer
LEVEL: prod
commands: commands:
- echo "== pre deploy status:" - echo "== pre deploy ($${LEVEL}) status:"
- kubectl get pods --namespace=beer - kubectl get pods --namespace=beer
- kubectl get deployments --namespace=beer - kubectl get deployments --namespace=beer
- sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment.yaml > kube/beer-deployment-prod.yaml - sed "s/__LEVEL__/$${LEVEL}/g" kube/beer-deployment.yaml > kube/beer-deployment-$${LEVEL}.yaml
- sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-prod.yaml > kube/beer-deployment-prod2.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" - echo "applying"
- kubectl apply -f kube/beer-deployment-prod2.yaml --namespace=beer - kubectl apply -f kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml --namespace=beer
- echo "== post deploy status:" - echo "== post deploy ($${LEVEL}) status:"
- kubectl get deployments --namespace=beer - kubectl get deployments --namespace=beer
- kubectl get pods --namespace=beer - kubectl get pods --namespace=beer
when:
depends_on:
- build
when:
branch: branch:
include: include:
- master - master
depends_on:
- build

View file

@ -2,17 +2,19 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: beer-deployment name: beer-deployment-__LEVEL__
namespace: __NAMESPACE__ namespace: __NAMESPACE__
spec: spec:
selector: selector:
matchLabels: matchLabels:
app: beer app: beer
level: __LEVEL__
replicas: 1 replicas: 1
template: template:
metadata: metadata:
labels: labels:
app: beer app: beer
level: __LEVEL__
spec: spec:
containers: containers:
- name: beer - name: beer

View file

@ -3,10 +3,11 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: beer name: beer
namespace: beer namespace: __NAMESPACE__
spec: spec:
selector: selector:
app: beer app: beer
level: __LEVEL__
ports: ports:
- protocol: TCP - protocol: TCP
port: 80 port: 80

View file

@ -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

View file

@ -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