forked from haskell-lang/haskell-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
106 lines (97 loc) · 3.58 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
image: registry.gitlab.fpcomplete.com/fpco/default-build-image:1954
cache:
key: "$CI_BUILD_NAME"
paths:
- .stack-work/
- .stack-root/
- static/combined/
stages:
- build
- deploy
variables:
STACK_ROOT: "${CI_PROJECT_DIR}/.stack-root"
DEPLOYMENT_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
DEPLOYMENT_NAME: "haskell-lang-review-${CI_BUILD_REF_SLUG}"
DEPLOYMENT_APP: "${CI_ENVIRONMENT_SLUG}"
# This creates anchors for bits of script that are reused between builds
.anchors:
# The KUBE_* variables are set by Gitlab's Kubernetes deployment service
- &KUBELOGIN
echo "$KUBE_CA_PEM" >"$HOME/ca.pem" &&
kubectl config set-cluster cluster --server="$KUBE_URL" --certificate-authority="$HOME/ca.pem" &&
kubectl config set-credentials cluster --token="$KUBE_TOKEN" && kubectl config set-context cluster --cluster=cluster --user=cluster --namespace="$KUBE_NAMESPACE" &&
kubectl config use-context cluster
- &KUBEAPPLY
kubectl apply -f <(envsubst <etc/kube/service_template.yaml) &&
kubectl apply -f <(envsubst <etc/kube/deployment_template.yaml) &&
kubectl apply -f <(envsubst <etc/kube/ingress_template.yaml) &&
kubectl rollout status -f <(envsubst <etc/kube/deployment_template.yaml)
build:
stage: build
script:
# Clear *_TOKEN variables during code build so that compile-time code can't access them
- CI_BUILD_TOKEN="" KUBE_TOKEN="" PROD_KUBE_TOKEN="" PROD_DOCKER_PASSWORD="" etc/scripts/stage_docker.sh --install-ghc --test
- docker build -t "${DEPLOYMENT_IMAGE}" etc/docker
- docker login -u gitlab-ci-token -p "${CI_BUILD_TOKEN}" "${CI_REGISTRY}"
- docker push "${DEPLOYMENT_IMAGE}"
- |
if [[ "$CI_BUILD_REF_NAME" == "master" ]]; then
docker tag "${DEPLOYMENT_IMAGE}" "${CI_REGISTRY_IMAGE}:latest"
docker push "${CI_REGISTRY_IMAGE}:latest"
fi
deploy_review:
stage: deploy
when: manual
only:
- branches
except:
- master
environment:
name: haskell-lang-review/$CI_BUILD_REF_NAME
url: https://haskell-lang-$CI_BUILD_REF_SLUG.fpco-public.fpcomplete.com/
on_stop: stop_review
variables:
APPROOT: https://haskell-lang-$CI_BUILD_REF_SLUG.fpco-public.fpcomplete.com/
HOST: haskell-lang-$CI_BUILD_REF_SLUG.fpco-public.fpcomplete.com
script:
- *KUBELOGIN
- *KUBEAPPLY
stop_review:
stage: deploy
only:
- branches
except:
- master
when: manual
environment:
name: haskell-lang-review/$CI_BUILD_REF_NAME
action: stop
script:
- *KUBELOGIN
- kubectl delete service,deployment,ingress,secret -l app=${CI_ENVIRONMENT_SLUG}
deploy_prod:
stage: deploy
only:
- master
environment:
name: haskell-lang-prod
url: https://haskell-lang.org/
variables:
DEPLOYMENT_NAME: "haskell-lang-prod"
PROD_DEPLOYMENT_IMAGE: "fpco/haskell-lang-prod:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
script:
- export
KUBE_CA_PEM="$PROD_KUBE_CA_PEM"
KUBE_URL="$PROD_KUBE_URL"
KUBE_TOKEN="$PROD_KUBE_TOKEN"
KUBE_NAMESPACE="$PROD_KUBE_NAMESPACE"
- *KUBELOGIN
- docker login -u "$PROD_DOCKER_USERNAME" -p "${PROD_DOCKER_PASSWORD}"
- docker tag "$DEPLOYMENT_IMAGE" "$PROD_DEPLOYMENT_IMAGE"
- docker push "$PROD_DEPLOYMENT_IMAGE"
- docker tag "$DEPLOYMENT_IMAGE" "fpco/haskell-lang-prod:latest"
- docker push "fpco/haskell-lang-prod:latest"
- export DEPLOYMENT_IMAGE=$PROD_DEPLOYMENT_IMAGE
- kubectl apply -f <(envsubst <etc/kube/service_template.yaml)
- kubectl apply -f <(envsubst <etc/kube/deployment_template.yaml)
- kubectl rollout status "deployment/$DEPLOYMENT_NAME"