Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@ variables:
IMAGE_TAG: $CI_COMMIT_REF_SLUG
REPO_NAME: ""


## Build
build-image:
stage: build
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/docker:20.10.16
services:
services:
- name: docker:20.10.16-dind
variables:
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- echo $IMAGE_NAME:$IMAGE_TAG
- echo $IMAGE_NAME:$IMAGE_TAG
- docker build -t $IMAGE_NAME:$IMAGE_TAG .
- docker push $IMAGE_NAME:$IMAGE_TAG
- docker rmi $IMAGE_NAME:$IMAGE_TAG # remove local image from shared runner
- docker logout $CI_REGISTRY


## deploy to k8s staging
deploy_to_k8s_staging:
stage: deploy
Expand All @@ -35,7 +33,7 @@ deploy_to_k8s_staging:
# create the .kube/ directory
- mkdir -p ~/.kube/
# move the config file to default location
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
- unset HTTPS_PROXY
variables:
DOCKER_IMAGE: $IMAGE_NAME:$IMAGE_TAG
Expand All @@ -46,7 +44,6 @@ deploy_to_k8s_staging:
- kubectl apply -k ./k8s/overlays/staging
- kubectl rollout restart deployment django-deployment-staging -n tark-staging


## deploy to k8s production
deploy_to_k8s_production:
stage: deploy
Expand All @@ -55,7 +52,7 @@ deploy_to_k8s_production:
# create the .kube/ directory
- mkdir -p ~/.kube/
# move the config file to default location
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
- unset HTTPS_PROXY
variables:
DOCKER_IMAGE: $IMAGE_NAME:$IMAGE_TAG
Expand All @@ -67,7 +64,32 @@ deploy_to_k8s_production:
- kubectl rollout restart deployment django-deployment-production -n tark-production

only:
- main
- migrate_to_k8s
- main
- migrate_to_k8s

when: manual

## deploy to k8s fallback
deploy_to_k8s_fallback:
stage: deploy
needs: ["build-image"]
before_script:
# create the .kube/ directory
- mkdir -p ~/.kube/
# move the config file to default location
- echo $FB_KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
- unset HTTPS_PROXY
variables:
DOCKER_IMAGE: $IMAGE_NAME:$IMAGE_TAG
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/alpine/k8s:1.25.16
script:
- export KUBECONFIG=~/.kube/config
- sed -i "s#<DOCKER_IMAGE>#${DOCKER_IMAGE}#g" ./k8s/base/app/django-deployment.yaml
- kubectl apply -k ./k8s/overlays/fallback
- kubectl rollout restart deployment django-deployment-fallback -n tark-fallback

only:
- main
- deploy_fallback

when: manual
20 changes: 20 additions & 0 deletions k8s/overlays/fallback/app/django-deployment-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: django-deployment
spec:
replicas: 2
selector:
matchLabels:
app: django
template:
spec:
containers:
- name: django-container
envFrom:
- configMapRef:
name: app-config-fallback
- configMapRef:
name: db-config-fallback
- secretRef:
name: db-secret-fallback
4 changes: 4 additions & 0 deletions k8s/overlays/fallback/app/django-service-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Service
metadata:
name: django-cluster-ip-service
12 changes: 12 additions & 0 deletions k8s/overlays/fallback/app/nodeport-service-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: app-nodeport-service
spec:
type: NodePort
ports:
- port: 8000
targetPort: 8000
nodePort: 32451
selector:
app: django
9 changes: 9 additions & 0 deletions k8s/overlays/fallback/config/app-cm-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# App variables
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
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"
WORKERS: "7"
DJANGO_ENVIRONMENT: production
8 changes: 8 additions & 0 deletions k8s/overlays/fallback/config/db-cm-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: db-config
data:
DATABASE_HOST: mysql-service-fallback
DATABASE_PORT: "4650"
DATABASE_NAME: ensembl_tark_e75_to_e115
20 changes: 20 additions & 0 deletions k8s/overlays/fallback/ingress/ingress-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This config file is used by the new K8s Cluster
# Kubectl Server Version: v1.21.4
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tark-ingress
spec:
ingressClassName: nginx
rules:
- host: tark.ensembl.org
http:
paths:
# URL ROUTING
- path: /?(.*)
pathType: Prefix
backend:
service:
name: django-cluster-ip-service
port:
number: 8000
20 changes: 20 additions & 0 deletions k8s/overlays/fallback/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: tark-fallback
resources:
- ../../base/

nameSuffix: -fallback

patches:
- path: app/django-service-patch.yaml
- path: app/django-deployment-patch.yaml
- path: app/nodeport-service-patch.yaml

- path: config/app-cm-patch.yaml
- path: config/db-cm-patch.yaml

- path: mysql/mysql-endpoint-patch.yaml
- path: mysql/mysql-service-patch.yaml

- path: ingress/ingress-patch.yaml
10 changes: 10 additions & 0 deletions k8s/overlays/fallback/mysql/mysql-endpoint-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Endpoints
metadata:
name: mysql-service
subsets:
- addresses:
- ip: 10.7.147.24
ports:
- name: mysql
port: 4650
10 changes: 10 additions & 0 deletions k8s/overlays/fallback/mysql/mysql-service-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
ports:
- name: mysql
protocol: TCP
port: 4650
targetPort: 4650
10 changes: 5 additions & 5 deletions k8s/overlays/staging/mysql/mysql-endpoint-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ kind: Endpoints
metadata:
name: mysql-service
subsets:
- addresses:
- ip: 10.42.33.220
ports:
- name: mysql
port: 4650
- addresses:
- ip: 10.42.33.220
ports:
- name: mysql
port: 4650