-
Notifications
You must be signed in to change notification settings - Fork 38
/
base_deploy_kosko_stage.yml
105 lines (101 loc) · 4.37 KB
/
base_deploy_kosko_stage.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
#
variables:
K8S_FOLDER: ${CI_PROJECT_DIR}/.k8s
KOSKO_GENERATE_ARGS: ""
.print_env: &print_env |
printenv | grep \
-e "^AUTO_" \
-e "^CI_COMMIT_" \
-e "^CI_ENVIRONMENT_" \
-e "^CI_PROJECT_" \
-e "^CI_REGISTRY_" \
-e "^KUBE_INGRESS_BASE_DOMAIN" \
-e "^KUBE_NAMESPACE" \
-e "^PRODUCTION" \
-e "^KOSKO_" \
-e "^RANCHER_PROJECT_ID" | sort
.base_deploy_kosko_stage:
stage: Deploy
image: ghcr.io/socialgouv/docker/no-k8s:6.65.0
dependencies: []
cache:
key:
files:
- ${K8S_FOLDER}/yarn.lock
prefix: ${CI_JOB_NAME}
paths:
- ${CI_PROJECT_DIR}/.cache
- ${K8S_FOLDER}/node_modules
script:
- *print_env
- |
if [[ -d "${CI_PROJECT_DIR}/.socialgouv" ]]; then
echo "Use .socialgouv config."
rm -rf /k8s/.socialgouv
cp -r ${CI_PROJECT_DIR}/.socialgouv /k8s/
if [[ -d "/k8s/.socialgouv/environments" ]]; then
cp -r /k8s/.socialgouv/environments/* /k8s/.k8s/environments/
fi
if [[ -d "/k8s/.socialgouv/components" ]]; then
cp -r /k8s/.socialgouv/components/* /k8s/.k8s/components/
fi
cd /k8s/.k8s
else
yarn config set cache-folder ${CI_PROJECT_DIR}/.cache/yarn
cd ${K8S_FOLDER}
yarn --production --frozen-lockfile --prefer-offline --link-duplicates
fi
#
- echo "kosko generate ${KOSKO_GENERATE_ARGS} >> ${CI_PROJECT_DIR}/manifest.yaml"
- kosko generate ${KOSKO_GENERATE_ARGS} > ${CI_PROJECT_DIR}/manifest.yaml
#
- cd -
- |
if [[ -d "${KOSKO_APPEND_YAML_FROM}" ]]; then
echo "Append to ${CI_PROJECT_DIR}/manifest.yaml"
find ${KOSKO_APPEND_YAML_FROM} -name '*.yaml'
find ${KOSKO_APPEND_YAML_FROM} -name '*.yaml' -exec \
echo '---' \; -exec cat {} \; \
>> ${CI_PROJECT_DIR}/manifest.yaml
fi
# hack: this enable new cert-manager for legacy gitlab+nok8s repos (ex: medle)
- sed -i "s#certmanager.k8s.io/cluster-issuer#cert-manager.io/cluster-issuer#" ${CI_PROJECT_DIR}/manifest.yaml
- |
if [[ -n $AUTO_DEVOPS_ENABLE_KAPP ]]; then
if [[ -z $PRODUCTION ]]; then
kubectl create ns ${KUBE_NAMESPACE} || true
kubectl annotate ns ${KUBE_NAMESPACE} azure-pg-admin-user=${CI_PROJECT_NAME} || true
fi
kapp --dangerous-override-ownership-of-existing-resources -y deploy -a ${CI_PROJECT_NAME} --namespace ${KUBE_NAMESPACE} -f ${CI_PROJECT_DIR}/manifest.yaml ${KAPP_DEPLOY_ARGS}
else
kubectl apply -f ${CI_PROJECT_DIR}/manifest.yaml
fi
- |
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
[[ -z $PRODUCTION ]] && GRAFANA_CLUSTER="dev2" || GRAFANA_CLUSTER="prod2";
[[ -f "${CI_PROJECT_DIR}/manifest.yaml" ]] && yq e -N '.spec.rules[] .host' "${CI_PROJECT_DIR}/manifest.yaml" | grep -v null | sed -e s/^/\ \ 🚀\ https\:\\/\\// || true
echo " 📕 logs : https://grafana.fabrique.social.gouv.fr/explore?orgId=1&left=%5B%22now-1h%22,%22now%22,%22Loki-tail%22,%7B%22expr%22:%22%7Bnamespace%3D%5C%22${KUBE_NAMESPACE}%5C%22%7D%22%7D%5D"
echo " 📊 pods : https://grafana.fabrique.social.gouv.fr/d/85a562078cdf77779eaa1add43ccec1e/kubernetes-compute-resources-namespace-pods?orgId=1&refresh=10s&var-datasource=default&var-cluster=${GRAFANA_CLUSTER}&var-namespace=${KUBE_NAMESPACE}"
echo " 📊 workloads : https://grafana.fabrique.social.gouv.fr/d/a87fb0d919ec0ea5f6543124e16c42a5/kubernetes-compute-resources-namespace-workloads?orgId=1&refresh=10s&var-datasource=default&var-cluster=${GRAFANA_CLUSTER}&var-namespace=${KUBE_NAMESPACE}&var-type=deployment"
echo " 🔎 rancher : https://rancher.fabrique.social.gouv.fr/p/${RANCHER_PROJECT_ID}/workloads"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
artifacts:
expire_in: 1 week
paths:
- manifest.yaml
when: always
.base_kosko_k8s_test:
stage: Code Quality
extends:
- .base_deploy_kosko_stage
script:
- *print_env
#
- yarn config set cache-folder ${CI_PROJECT_DIR}/.cache/yarn
- cd ${K8S_FOLDER}
- yarn --frozen-lockfile --prefer-offline --link-duplicates
# HACK(douglasduteil): pre-cache jest
# As it's most likely being used to test our kosko charts
- yarn add -D jest --frozen-lockfile --prefer-offline --link-duplicates
#
- yarn test