Skip to content

Commit 35efe30

Browse files
authored
Merge pull request #101 from Ensembl/deploy-fallback
added manifests to deploy to fallback
2 parents bbe9356 + b01fe88 commit 35efe30

File tree

11 files changed

+149
-14
lines changed

11 files changed

+149
-14
lines changed

.gitlab-ci.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,23 @@ variables:
88
IMAGE_TAG: $CI_COMMIT_REF_SLUG
99
REPO_NAME: ""
1010

11-
1211
## Build
1312
build-image:
1413
stage: build
1514
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/docker:20.10.16
16-
services:
15+
services:
1716
- name: docker:20.10.16-dind
1817
variables:
1918
DOCKER_TLS_CERTDIR: ""
2019
before_script:
2120
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
2221
script:
23-
- echo $IMAGE_NAME:$IMAGE_TAG
22+
- echo $IMAGE_NAME:$IMAGE_TAG
2423
- docker build -t $IMAGE_NAME:$IMAGE_TAG .
2524
- docker push $IMAGE_NAME:$IMAGE_TAG
2625
- docker rmi $IMAGE_NAME:$IMAGE_TAG # remove local image from shared runner
2726
- docker logout $CI_REGISTRY
2827

29-
3028
## deploy to k8s staging
3129
deploy_to_k8s_staging:
3230
stage: deploy
@@ -35,7 +33,7 @@ deploy_to_k8s_staging:
3533
# create the .kube/ directory
3634
- mkdir -p ~/.kube/
3735
# move the config file to default location
38-
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
36+
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
3937
- unset HTTPS_PROXY
4038
variables:
4139
DOCKER_IMAGE: $IMAGE_NAME:$IMAGE_TAG
@@ -46,7 +44,6 @@ deploy_to_k8s_staging:
4644
- kubectl apply -k ./k8s/overlays/staging
4745
- kubectl rollout restart deployment django-deployment-staging -n tark-staging
4846

49-
5047
## deploy to k8s production
5148
deploy_to_k8s_production:
5249
stage: deploy
@@ -55,7 +52,7 @@ deploy_to_k8s_production:
5552
# create the .kube/ directory
5653
- mkdir -p ~/.kube/
5754
# move the config file to default location
58-
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
55+
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
5956
- unset HTTPS_PROXY
6057
variables:
6158
DOCKER_IMAGE: $IMAGE_NAME:$IMAGE_TAG
@@ -67,7 +64,32 @@ deploy_to_k8s_production:
6764
- kubectl rollout restart deployment django-deployment-production -n tark-production
6865

6966
only:
70-
- main
71-
- migrate_to_k8s
67+
- main
68+
- migrate_to_k8s
69+
70+
when: manual
71+
72+
## deploy to k8s fallback
73+
deploy_to_k8s_fallback:
74+
stage: deploy
75+
needs: ["build-image"]
76+
before_script:
77+
# create the .kube/ directory
78+
- mkdir -p ~/.kube/
79+
# move the config file to default location
80+
- echo $FB_KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
81+
- unset HTTPS_PROXY
82+
variables:
83+
DOCKER_IMAGE: $IMAGE_NAME:$IMAGE_TAG
84+
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/alpine/k8s:1.25.16
85+
script:
86+
- export KUBECONFIG=~/.kube/config
87+
- sed -i "s#<DOCKER_IMAGE>#${DOCKER_IMAGE}#g" ./k8s/base/app/django-deployment.yaml
88+
- kubectl apply -k ./k8s/overlays/fallback
89+
- kubectl rollout restart deployment django-deployment-fallback -n tark-fallback
90+
91+
only:
92+
- main
93+
- deploy_fallback
7294

7395
when: manual
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: django-deployment
5+
spec:
6+
replicas: 2
7+
selector:
8+
matchLabels:
9+
app: django
10+
template:
11+
spec:
12+
containers:
13+
- name: django-container
14+
envFrom:
15+
- configMapRef:
16+
name: app-config-fallback
17+
- configMapRef:
18+
name: db-config-fallback
19+
- secretRef:
20+
name: db-secret-fallback
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: django-cluster-ip-service
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: app-nodeport-service
5+
spec:
6+
type: NodePort
7+
ports:
8+
- port: 8000
9+
targetPort: 8000
10+
nodePort: 32451
11+
selector:
12+
app: django
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# App variables
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: app-config
6+
data:
7+
DJANGO_ALLOWED_HOSTS: "hx-rke-wp-webadmin-31-worker-1.caas.ebi.ac.uk hx-rke-wp-webadmin-31-worker-2.caas.ebi.ac.uk hx-rke-wp-webadmin-31-worker-3.caas.ebi.ac.uk tark.ensembl.org"
8+
WORKERS: "7"
9+
DJANGO_ENVIRONMENT: production
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: db-config
5+
data:
6+
DATABASE_HOST: mysql-service-fallback
7+
DATABASE_PORT: "4650"
8+
DATABASE_NAME: ensembl_tark_e75_to_e115
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This config file is used by the new K8s Cluster
2+
# Kubectl Server Version: v1.21.4
3+
apiVersion: networking.k8s.io/v1
4+
kind: Ingress
5+
metadata:
6+
name: tark-ingress
7+
spec:
8+
ingressClassName: nginx
9+
rules:
10+
- host: tark.ensembl.org
11+
http:
12+
paths:
13+
# URL ROUTING
14+
- path: /?(.*)
15+
pathType: Prefix
16+
backend:
17+
service:
18+
name: django-cluster-ip-service
19+
port:
20+
number: 8000
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: tark-fallback
4+
resources:
5+
- ../../base/
6+
7+
nameSuffix: -fallback
8+
9+
patches:
10+
- path: app/django-service-patch.yaml
11+
- path: app/django-deployment-patch.yaml
12+
- path: app/nodeport-service-patch.yaml
13+
14+
- path: config/app-cm-patch.yaml
15+
- path: config/db-cm-patch.yaml
16+
17+
- path: mysql/mysql-endpoint-patch.yaml
18+
- path: mysql/mysql-service-patch.yaml
19+
20+
- path: ingress/ingress-patch.yaml
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Endpoints
3+
metadata:
4+
name: mysql-service
5+
subsets:
6+
- addresses:
7+
- ip: 10.7.147.24
8+
ports:
9+
- name: mysql
10+
port: 4650
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: mysql-service
5+
spec:
6+
ports:
7+
- name: mysql
8+
protocol: TCP
9+
port: 4650
10+
targetPort: 4650

0 commit comments

Comments
 (0)