[CI] Add stating environment
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing

This commit is contained in:
kleph 2020-03-01 01:28:04 +01:00
parent a66d0fda6f
commit 65eb050362
5 changed files with 85 additions and 12 deletions

View file

@ -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
depends_on:
- build
when:
branch:
include:
- master
depends_on:
- build

View file

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

View file

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

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