This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
.gitlab-ci.sample.yml
146 lines (137 loc) · 5.8 KB
/
.gitlab-ci.sample.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# This is a sample gitlab-ci configuration file that can be used to deploy FADI on GKE using gitlab-ci
# 1. rename this file to .gitlab-ci.yml
# 2. change the variables to match your setup (at least the GCP_PROJECT name)
# 3. let gitlab-ci do its magic
# more info on gitlab-ci: https://about.gitlab.com/product/continuous-integration/
stages:
- tf_validate
- tf_plan
- tf_apply
- deployWithHelm
- test
variables:
KUBECONFIG: /etc/deploy/config
.provision: &provision
image:
name: hashicorp/terraform:light
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
before_script:
- cd terraform/
- rm -rf .terraform
- terraform --version
- echo $SA_GKE | base64 -d > sa_gke.json
- terraform init -backend=true -get=true -input=false
tags:
- docker
only:
- master
validate:
<<: *provision
stage: tf_validate
script:
- terraform validate
plan:
<<: *provision
stage: tf_plan
script:
- terraform plan -out "planfile"
dependencies:
- validate
artifacts:
paths:
- terraform/planfile
apply:
<<: *provision
stage: tf_apply
script:
- terraform apply -input=false "planfile"
dependencies:
- plan
# Should be manual for production infrastructure with tag manuel
# when: manual
.deploy: &deploy
image: google/cloud-sdk
before_script:
- echo $SA_GKE | base64 -d > "$SA_FILE"
# install kubectl
- apt-get install kubectl
- gcloud auth activate-service-account --key-file="$SA_FILE"
- gcloud config set project "$GCP_PROJECT"
- gcloud container clusters list
- gcloud container clusters get-credentials "$GKE_PROJECT" --zone "$GCP_ZONE"
# get static ips
- IP_STATIC_MINIO="$(gcloud compute addresses describe ipv4-address-minio --region "$GCP_REGION" --format="value(address)")"
- IP_STATIC_SUPERSET="$(gcloud compute addresses describe ipv4-address-superset --region "$GCP_REGION" --format="value(address)")"
- IP_STATIC_JUPYTERHUB="$(gcloud compute addresses describe ipv4-address-jupyterhub --region "$GCP_REGION" --format="value(address)")"
- IP_STATIC_GRAFANA="$(gcloud compute addresses describe ipv4-address-grafana --region "$GCP_REGION" --format="value(address)")"
- IP_STATIC_NIFI="$(gcloud compute addresses describe ipv4-address-nifi --region "$GCP_REGION" --format="value(address)")"
- IP_STATIC_PGADMIN="$(gcloud compute addresses describe ipv4-address-pgadmin --region "$GCP_REGION" --format="value(address)")"
# - IP_STATIC_SPARKUI="$(gcloud compute addresses describe ipv4-address-sparkui --region "$GCP_REGION" --format="value(address)")"
- kubectl cluster-info
# clone FADI repo
- git clone https://github.com/cetic/fadi.git setup
- cd setup/helm/
# install helm
- curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
# create namespaces
- kubectl get namespace "$TILLER" 2> /dev/null || kubectl create namespace "$TILLER"
- kubectl get namespace "$PROJECT" 2> /dev/null || kubectl create namespace "$PROJECT"
- kubectl get configmap config-nifi-bootstrap -n "$PROJECT" 2> /dev/null || kubectl create configmap config-nifi-bootstrap --from-file=../k8s/nifi/bootstrap.conf -n "$PROJECT"
# create sa for tiller
- kubectl get sa tiller -n "$TILLER" 2> /dev/null || kubectl create -f ./tiller/rbac-config.yaml
- helm init --history-max 200 --tiller-namespace "$TILLER" --service-account tiller --upgrade
# wait that tiller is deployed
- kubectl rollout status deployment tiller-deploy --namespace "$TILLER"
# add helm repos
- helm repo add stable https://kubernetes-charts.storage.googleapis.com/
- helm repo add jupyterhub https://jupyterhub.github.io/helm-chart/
- helm repo add cetic https://cetic.github.io/helm-charts/
- helm repo update
script:
# spark (+ zeppelin, set to 0 for the moment)
# - helm upgrade --install "$PROJECT"-spark stable/spark -f ./spark/config.yml --namespace "$PROJECT" --tiller-namespace "$TILLER"
# superset
- helm upgrade --install "$PROJECT"-superset stable/superset -f ./superset/config.yml --namespace "$PROJECT" --tiller-namespace "$TILLER" --set service.loadBalancerIP="$IP_STATIC_SUPERSET"
# postgres
- helm upgrade --install "$PROJECT"-postgres stable/postgresql -f ./postgresql/config.yml --namespace "$PROJECT" --tiller-namespace "$TILLER"
# minio
- helm upgrade --install "$PROJECT"-minio stable/minio -f ./minio/config.yml --namespace "$PROJECT" --tiller-namespace "$TILLER" --set service.loadBalancerIP="$IP_STATIC_MINIO"
# jupyter-hub
- helm upgrade --install "$PROJECT"-jhub jupyterhub/jupyterhub --version=0.8.2 -f ./jupyterhub/config.yml --namespace "$PROJECT" --tiller-namespace "$TILLER" --set proxy.service.loadBalancerIP="$IP_STATIC_JUPYTERHUB"
# nifi TODO
- kubectl get services nifi -n "$PROJECT" 2> /dev/null ||sed -i '/LoadBalancer/a \ \ loadBalancerIP:\ '"$IP_STATIC_NIFI"'' ../k8s/nifi/nifi.yml
- kubectl get services nifi -n "$PROJECT" 2> /dev/null || kubectl apply -f ../k8s/nifi/nifi.yml -n "$PROJECT"
# grafana
- helm upgrade --install "$PROJECT"-grafana stable/grafana -f ./grafana/config.yml --namespace "$PROJECT" --tiller-namespace "$TILLER" --set service.loadBalancerIP="$IP_STATIC_GRAFANA"
# pgadmin
- helm upgrade --install "$PROJECT"-pgadmin cetic/pgadmin -f ./pgadmin/config.yml --namespace "$PROJECT" --tiller-namespace "$TILLER" --set service.loadBalancerIP="$IP_STATIC_PGADMIN"
tags:
- docker
deployWithHelm:
<<: *deploy
stage: deployWithHelm
variables:
GCP_PROJECT: <your-project-id>
GCP_ZONE: europe-west1-d
GCP_REGION: europe-west1
GKE_PROJECT: gke-"$PROJECT"-dev
SA_FILE: sa_gke.json
PROJECT: FADI
TILLER: tiller
environment:
name: dev
url: http://$PROJECT
only:
- master
test:
stage: test
image: ceticasbl/puppeteer-jest
script:
- cd tests/
- npm run test
tags:
- docker
only:
- develop