Newer
Older
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
stages:
- deploy_ocf_staging
- delete_ocf_staging
- deploy_ocf_dev
- delete_ocf_dev
variables:
INGRESS: "10.43.32.232"
NAMESPACE_DEV: "ocf-dev-$CI_JOB_USER"
NAMESPACE_STAGING: "ocf-staging"
DOMAIN_STAGING: staging.int
DOAMIN_DEV: developer.int
CI_JOB_TOKEN: $CI_JOB_TOKEN
IMAGE_TAG_DEV: "v0.0.1-$CI_COMMIT_SHA"
IMAGE_TAG_STAGING: "v0.0.1-staging"
.staging_common: &staging_common
only:
- merge_requests
except:
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "staging"
tags:
- shell
.dev_common: &dev_common
tags:
- shell
deploy_ocf_staging:
stage: deploy_ocf_staging
<<: *staging_common
environment:
name: review/staging
url: https://$NAMESPACE_STAGING.$DOMAIN_STAGING
on_stop: delete_ocf_staging
auto_stop_in: 3 day
rules:
- if: $CI_COMMIT_BRANCH == "main"
when: never
- if: $CI_COMMIT_BRANCH
script:
- echo "### git clone OCF repo ###"
- git clone https://oauth2:${CI_JOB_TOKEN}@labs.etsi.org/rep/ocf/capif.git
- echo "### install helm ###"
- curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
- chmod 700 get_helm.sh
- ./get_helm.sh
- helm version
- echo "### install kubectl ###"
- curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
- chmod +x kubectl
- sudo mv kubectl /usr/local/bin
- kubectl version --output=yaml
- echo "### setting kubeconfig ###"
- echo $KUBECONFIG | base64 -d > ~/cluster.kubeconfig
- kubectl get nodes --kubeconfig ~/cluster.kubeconfig
- kubectl cluster-info --kubeconfig ~/cluster.kubeconfig #comment that when is working
- echo "### install yq ###"
- sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
- sudo chmod a+x /usr/local/bin/yq
- yq --version
- yq e -i '.version = "$IMAGE_TAG_STAGING"' helm/capif/Chart.yaml
- yq e -i '.appVersion = "$IMAGE_TAG_STAGING"' helm/capif/Chart.yaml
- cat helm/capif/Chart.yaml
- echo "### download dependencies ###"
- helm dependency build helm/capif
- echo "### updating capif ###"
- helm uninstall -n $NAMESPACE_STAGING ocf --kubeconfig ~/cluster.kubeconfig || true
- helm upgrade --install -n $NAMESPACE_STAGING ocf helm/capif/ \
--set nginx.nginx.env.capifHostname=capif.$DOMAIN_STAGING \
--set ingress_ip.oneke="$INGRESS" --atomic \
--set monitoring.prometheus.enable="" \
--set monitoring.grafana.ingress.hosts[0].host="grafana.$DOMAIN_STAGING" \
--set monitoring.grafana.ingress.hosts[0].paths[0].path="/" \
--set monitoring.grafana.ingress.hosts[0].paths[0].pathType="Prefix" \
--wait --timeout=10m \
--create-NAMESPACE_STAGING --kubeconfig ~/cluster.kubeconfig
delete_ocf_staging:
stage: delete_ocf_staging
<<: *staging_common
script:
- echo "### deleting environment $NAMESPACE_STAGING ###"
- helm uninstall -n $NAMESPACE_STAGING ocf --kubeconfig ~/cluster.kubeconfig
when: manual
environment:
name: review/staging
action: stop
## dev ###
deploy_ocf_dev:
stage: deploy_ocf_dev
<<: *dev_common
environment:
name: review/$CI_COMMIT_REF_SLUG
url: https://$NAMESPACE_DEV.$DOMAIN_DEV
on_stop: delete_ocf_dev
auto_stop_in: 3 day
rules:
- if: $CI_COMMIT_BRANCH == "main"
when: never
- if: $CI_COMMIT_BRANCH == "staging"
when: never
- if: $CI_COMMIT_BRANCH
script:
- echo "### git clone OCF repo ###"
- git clone https://oauth2:${CI_JOB_TOKEN}@labs.etsi.org/rep/ocf/capif.git
- echo "### install helm ###"
- curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
- chmod 700 get_helm.sh
- ./get_helm.sh
- helm version
- echo "### install kubectl ###"
- curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
- chmod +x kubectl
- sudo mv kubectl /usr/local/bin
- kubectl version --output=yaml
- echo "### setting kubeconfig ###"
- echo $KUBECONFIG | base64 -d > ~/cluster.kubeconfig
- kubectl get nodes --kubeconfig ~/cluster.kubeconfig
- kubectl cluster-info --kubeconfig ~/cluster.kubeconfig #comment that when is working
- echo "### install yq ###"
- sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
- sudo chmod a+x /usr/local/bin/yq
- yq --version
- yq e -i '.version = "$IMAGE_TAG_STAGING"' helm/capif/Chart.yaml
- yq e -i '.appVersion = "$IMAGE_TAG_STAGING"' helm/capif/Chart.yaml
- cat helm/capif/Chart.yaml
- echo "### download dependencies ###"
- helm dependency build helm/capif
- echo "### updating capif ###"
- helm uninstall -n $NAMESPACE_STAGING ocf --kubeconfig ~/cluster.kubeconfig || true
- helm upgrade --install -n $NAMESPACE_STAGING ocf helm/capif/ \
--set nginx.nginx.env.capifHostname=capif.$DOMAIN_STAGING \
--set ingress_ip.oneke="$INGRESS" --atomic \
--set monitoring.prometheus.enable="" \
--set monitoring.grafana.ingress.hosts[0].host="grafana.$DOMAIN_STAGING" \
--set monitoring.grafana.ingress.hosts[0].paths[0].path="/" \
--set monitoring.grafana.ingress.hosts[0].paths[0].pathType="Prefix" \
--wait --timeout=10m \
--create-NAMESPACE_STAGING --kubeconfig ~/cluster.kubeconfig