forked from crosscloudci/cross-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
167 lines (156 loc) · 6.04 KB
/
.gitlab-ci.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
stages:
- Artifacts
- Cross-Cloud
- End-To-End
- Update-Dashboard
before_script:
- export BASE_URL=${BASE_URL:-$(echo $CI_PROJECT_URL | cut -d'/' -f1-3)}
- mkdir -p ./data ; touch ./data/empty.env
- for envfile in data/*env ; do source $envfile ; echo ----- $envfile ---- ; cat $envfile ; done
- export KUBECONFIG=$(pwd)/data/${CLOUD}/kubeconfig
- >
if [ -z "$CROSS_CLOUD_YML" ]; then
export CROSS_CLOUD_YML="https://raw.githubusercontent.com/CrossCloudCI/cncf-configuration/production/cross-cloud.yml"
else
export CROSS_CLOUD_YML="$CROSS_CLOUD_YML"
fi
- >
if [ "$BASE_URL" == "https://gitlab.cncf.ci" ]; then
export ENVIRONMENT="pd"
elif [ "$BASE_URL" == "https://gitlab.staging.cncf.ci" ]; then
export ENVIRONMENT="sg"
elif [ "$BASE_URL" == "https://gitlab.dev.cncf.ci" ]; then
export ENVIRONMENT="dv"
elif [ "$BASE_URL" == "https://gitlab.cidev.cncf.ci" ]; then
export ENVIRONMENT="ci"
elif [ "$BASE_URL" == "https://gitlab.demo.cncf.ci" ]; then
export ENVIRONMENT="dm"
elif [ "$BASE_URL" == "https://gitlab.onap.cncf.ci" ]; then
export ENVIRONMENT="on"
else
echo "Environment unknown: $BASE_URL"
exit 1
fi
- >
if [ "$CI_JOB_NAME" == "Build-Source" ]; then
source /opt/local/etc/rvmrc ; source /opt/local/etc/profile.d/rvm.sh ; cp -a /opt/local/dashboard /dashboard ; pushd /dashboard ; source /opt/local/.env ; ./bin/update_dashboard ; popd
elif [ "$CI_JOB_NAME" == "Dashboard" ]; then
source /opt/local/etc/rvmrc ; source /opt/local/etc/profile.d/rvm.sh ; cp -a /opt/local/dashboard /dashboard ; pushd /dashboard ; source /opt/local/.env ; ./bin/update_dashboard ; popd
else
source /opt/local/alpine/etc/rvmrc ; source /opt/local/alpine/etc/profile.d/rvm.sh ; cp -a /opt/local/dashboard /dashboard ; pushd /dashboard ; source /opt/local/.env ; ./bin/update_dashboard ; popd
fi
.build_source: &build_source
image: buildpack-deps:stretch
stage: Artifacts
variables:
# SOURCE
# ORG: MUST BE SET
# PROJECT: MUST BE SET
# PROJECT_ID: MUST BE SET
script:
- apt update && apt -y install jq
- >
if [ -z "${SOURCE}" ]; then
exit 0 #Should Show Skipped on Gitlab CI FIXME
elif [ "${DISABLE_SOURCE}" == "yes" ]; then
exit 0 #Should Show Skipped on Gitlab CI FIXME
else
PROJECT_JOB=$(curl --header "PRIVATE-TOKEN:${TOKEN}" "${BASE_URL}/api/v4/projects/14/pipelines/${SOURCE}/jobs?scope=success" | jq '.[] | select(.name=="container") | .id')
curl -s -o data/kubernetes.env -L "${BASE_URL}/kubernetes/kubernetes/-/jobs/${PROJECT_JOB}/artifacts/raw/release.env"
cat data/kubernetes.env
fi
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
untracked: true
expire_in: 5 weeks
paths:
- ./data
# Deploy Template used for Each Cloud
.kubernetes_deploy_template: &kubernetes_deploy_template
image: ${CI_REGISTRY}/cncf/cross-cloud/provisioning:$CI_COMMIT_REF_SLUG
stage: Cross-Cloud
variables:
CLOUD: MUST BE SET
script:
- >
if [ $CLOUD == "oci" ]; then
echo "Writing certs"
mkdir /cncf/keys
echo "$OCI_API_KEY" > /cncf/keys/oci_api_key.pem
echo "$OCI_API_PUB" > /cncf/keys/oci_api_key_pub.pem
else
echo "Skipping OCI Cloud Certs"
fi
- /cncf/provision.sh ${CLOUD}-deploy ${ENVIRONMENT}${DEPLOYMENT_SHA} s3 ${CLOUD}
- >
if [ $CLOUD == "gke" ]; then
echo "kube-dns is already deployed, skipping"
kubectl create -f ./rbac/helm-rbac.yml || true
elif [ $CLOUD == "ibmcloud" ]; then
echo "kube-dns is already deployed, skipping"
kubectl create -f ./rbac/helm-rbac.yml || true
elif [ $CLOUD == "oci" ]; then
kubectl create -f ./rbac/ || true
kubectl --namespace kube-system create secret generic oci-cloud-controller-manager --from-file=cloud-provider.yaml=./data/addons/create/oci-ccm-secret.yaml || true
kubectl --namespace kube-system create secret generic oci-flexvolume-driver --from-file=config.yaml=./data/addons/create/oci-fvd-secret.yaml || true
kubectl --namespace kube-system create secret generic oci-volume-provisioner --from-file=config.yaml=./data/addons/create/oci-vp-secret.yaml || true
kubectl apply -f ./data/addons/apply
else
kubectl create -f ./rbac/ || true
kubectl create -f ./addons/ || true
fi
- KUBECTL_PATH=$(which kubectl) NUM_NODES="$TF_VAR_worker_node_count" KUBERNETES_PROVIDER=local ./validate-cluster/cluster/validate-cluster.sh || true
- helm init --service-account tiller
- sleep 10
- kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system
artifacts:
when: always
expire_in: 4 weeks
paths:
- ./data/
# # E2E Template used for Per Cloud e2e Tests
# .k8s_e2e_template: &k8s_e2e_template
# image: ${CI_REGISTRY}/kubernetes/kubernetes/kubernetes-e2e:ci-v1-6-3.job.4793
# stage: cncf-e2e
# variables:
# CLOUD: MUST BE SET
# environment:
# name: MUST BE SET
# url: MUST BE SET
# script:
# - /kubernetes/e2e/run-conformance.sh
# Per Cloud Destroy Template only run when DESTROY_VAR is Set
.kubernetes_cloud_destroy_template: &kubernetes_cloud_destroy_template
image: ${CI_REGISTRY}/cncf/cross-cloud/provisioning:$CI_COMMIT_REF_SLUG
stage: Cross-Cloud
when: manual
variables:
CLOUD: MUST BE SET
script:
- /cncf/provision.sh ${CLOUD}-destroy ${ENVIRONMENT}${DEPLOYMENT_SHA} s3 ${CLOUD}
# Build-Source VARs
Build-Source:
<<: *build_source
# Cloud Deploy VARs
Provisioning:
<<: *kubernetes_deploy_template
variables:
CLOUD: "${CLOUD}"
# # AWS E2E VARs
# aws_k8s_e2e:
# <<: *k8s_e2e_template
# variables:
# CLOUD: ${AWS_CLOUD}
# environment:
# name: ${AWS_CLOUD}-${CI_COMMIT_REF_SLUG}
# url: https://$CI_ENVIRONMENT_SLUG.demo.cncf.ci/
# AWS Destroy VARs
Kubernetes_destroy:
<<: *kubernetes_cloud_destroy_template
variables:
CLOUD: "${CLOUD}"
Dashboard:
image: crosscloudci/debian-docker
stage: Update-Dashboard
script:
- echo 'true'