forked from haskell-hvr/hackage-mirror-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
59 lines (53 loc) · 2.24 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
image: registry.gitlab.fpcomplete.com/fpco/default-build-image:17
cache:
key: "$CI_BUILD_NAME"
paths:
- .stack-work/
- .stack-root/
- etc/docker/_artifacts/
stages:
- build
- deploy
variables:
STACK_ROOT: "${CI_PROJECT_DIR}/.stack-root"
DEPLOYMENT_IMAGE: "registry.gitlab.fpcomplete.com/michael/hackage-mirror-tool:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
# 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
build:
stage: build
script:
# Clear *_TOKEN variables during code build so that libraries compile-time code can't access them
- CI_BUILD_TOKEN="" KUBE_TOKEN="" PROD_KUBE_TOKEN="" PROD_DOCKER_PASSWORD="" stack --install-ghc image container
- docker tag snoyberg/hackage-mirror-tool "${DEPLOYMENT_IMAGE}"
- docker login -u gitlab-ci-token -p "${CI_BUILD_TOKEN}" "${CI_REGISTRY}"
- docker push "${DEPLOYMENT_IMAGE}"
deploy:
stage: deploy
only:
- master
# environment:
# name: fpcomplete-site-prod
# url: https://www.fpcomplete.com/
variables:
DEPLOYMENT_NAME: "hackage-mirror-tool"
PROD_DEPLOYMENT_IMAGE: "snoyberg/hackage-mirror-tool:${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" "snoyberg/hackage-mirror-tool:latest"
- docker push "snoyberg/hackage-mirror-tool:latest"
- kubectl set image "deployment/$DEPLOYMENT_NAME" hackage-mirror-tool="$PROD_DEPLOYMENT_IMAGE"
- kubectl rollout status "deployment/$DEPLOYMENT_NAME"