.gitlab-ci.yml 2.97 KB
Newer Older
1
variables:
Nane Kratzke's avatar
Nane Kratzke committed
2
  KUBECTL: "quay.io/bitnami/kubectl:1.18"
3
4
  PRIME: "yes"
  CACHE: "no"
5
6
  PERSISTENT_CACHE: "no"
  TERMINATE: "no"
7
8

stages:
9
    - prepare
10
11
    - build
    - deploy
12
    - terminate
13

Nane Kratzke's avatar
Nane Kratzke committed
14
15
16
17
18
19
prepare:
    stage: prepare
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
20
21
        - kubectl apply -f deploy/storage
        - kubectl delete secret gitlab-registry-credentials || true
Nane Kratzke's avatar
Nane Kratzke committed
22
23
24
        - "kubectl create secret docker-registry gitlab-registry-credentials \
                    --docker-server=$CI_REGISTRY \
                    --docker-username=image-registry \ 
Nane Kratzke's avatar
Nane Kratzke committed
25
                    --docker-password=$CI_REGISTRY_TOKEN"
Nane Kratzke's avatar
Nane Kratzke committed
26

27
28
29
30
claim-volume:
    stage: prepare
    only:
        variables:
Nane Kratzke's avatar
Nane Kratzke committed
31
            - $PERSISTENT_CACHE == "yes"
32
            - $TERMINATE != "yes"
33
34
35
36
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
37
        - kubectl apply -f deploy/storage
38
39

build-prime:
40
    stage: build
Nane Kratzke's avatar
Nane Kratzke committed
41
42
    services:
        - docker:dind
43
    script:
Nane Kratzke's avatar
Nane Kratzke committed
44
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
45
        - cd prime
46
        - docker build -t $CI_REGISTRY_IMAGE/prime:latest .
Nane Kratzke's avatar
Nane Kratzke committed
47
        - docker push $CI_REGISTRY_IMAGE/prime:latest
48

49
deploy-prime:
50
    stage: deploy
51
52
53
    only:
        variables:
            - $PRIME == "yes"
54
            - $TERMINATE != "yes"
55
56
57
58
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
59
        - echo $GITLAB_USER_NAME.loki.th-luebeck.dev
Nane Kratzke's avatar
Nane Kratzke committed
60
        - wget -q https://github.com/mikefarah/yq/releases/download/3.4.0/yq_linux_amd64 -O ./yq && chmod +x yq
Nane Kratzke's avatar
Nane Kratzke committed
61
62
63
64
        - ./yq w -i deploy/prime/prime-ingress.yaml spec.rules[0].host $GITLAB_USER_NAME.loki.th-luebeck.dev
        - ./yq w -i deploy/prime/prime-ingress.yaml spec.tls[0].hosts[0] $GITLAB_USER_NAME.loki.th-luebeck.dev
        - kubectl delete -f deploy/prime || true
        - kubectl apply -f deploy/prime
65
66
67
68
69
70

deploy-cache:
    stage: deploy
    only:
        variables:
            - $CACHE == "yes"
71
72
            - $PERSISTENT_CACHE == "no"
            - $TERMINATE != "yes"
73
74
75
76
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
77
78
79
        - kubectl delete -f deploy/persistent-redis || true
        - kubectl delete -f deploy/redis || true
        - kubectl apply -f deploy/redis
80
81
82
83
84

deploy-persistent-cache:
    stage: deploy
    only:
        variables:
85
            - $CACHE == "yes"
86
            - $PERSISTENT_CACHE == "yes"
87
            - $TERMINATE != "yes"
88
89
90
91
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
92
93
94
        - kubectl delete -f deploy/redis || true
        - kubectl delete -f deploy/persistent-redis || true
        - kubectl apply -f deploy/persistent-redis
95

96
97
98
99
100
101
102
103
104
terminate:
    stage: terminate
    only:
        variables:
            - $TERMINATE == "yes"
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
105
106
107
108
        - kubectl delete -f deploy/redis -n || true
        - kubectl delete -f deploy/redis-persistent -n || true
        - kubectl delete -f deploy/prime || true
        - kubectl delete -f deploy/storage || true