.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"
Nane Kratzke's avatar
Nane Kratzke committed
3
  PRIME: "yes"
Nane Kratzke's avatar
Nane Kratzke committed
4
  CACHE: "no"        # one of "no", "in-memory", "persistent"
Nane Kratzke's avatar
Nane Kratzke committed
5
  TERMINATE: "yes"
6
7

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

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

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

build-prime:
43
    stage: build
Nane Kratzke's avatar
Nane Kratzke committed
44
    only:
Nane Kratzke's avatar
Nane Kratzke committed
45
46
        variables:
            - $PRIME == "yes"
Nane Kratzke's avatar
Nane Kratzke committed
47
48
    services:
        - docker:dind
49
    script:
Nane Kratzke's avatar
Nane Kratzke committed
50
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
51
        - cd prime
52
        - docker build -t $CI_REGISTRY_IMAGE/prime:latest .
Nane Kratzke's avatar
Nane Kratzke committed
53
        - docker push $CI_REGISTRY_IMAGE/prime:latest
54

55
deploy-prime:
56
    stage: deploy
Nane Kratzke's avatar
Nane Kratzke committed
57
58
59
    except:
        variables:
            - $TERMINATE == "yes"
60
61
62
    only:
        variables:
            - $PRIME == "yes"
63
64
65
66
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
67
        - echo prime-$GITLAB_USER_ID.loki.th-luebeck.dev
Nane Kratzke's avatar
Nane Kratzke committed
68
        - 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
69
70
        - ./yq w -i deploy/prime/prime-ingress.yaml spec.rules[0].host prime-$GITLAB_USER_ID.loki.th-luebeck.dev
        - ./yq w -i deploy/prime/prime-ingress.yaml spec.tls[0].hosts[0] prime-$GITLAB_USER_ID.loki.th-luebeck.dev
Nane Kratzke's avatar
Nane Kratzke committed
71
        - kubectl apply -f deploy/prime
72
73
74

deploy-cache:
    stage: deploy
Nane Kratzke's avatar
Nane Kratzke committed
75
76
77
    except:
        variables:
            - $TERMINATE == "yes"
78
79
    only:
        variables:
Nane Kratzke's avatar
Nane Kratzke committed
80
            - $CACHE == "in-memory"
81
82
83
84
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
85
86
        - kubectl delete -f deploy/persistent-redis || true
        - kubectl apply -f deploy/redis
87
88
89

deploy-persistent-cache:
    stage: deploy
Nane Kratzke's avatar
Nane Kratzke committed
90
91
92
    except:
        variables:
            - $TERMINATE == "yes"
93
94
    only:
        variables:
Nane Kratzke's avatar
Nane Kratzke committed
95
            - $CACHE == "persistent"
96
97
98
99
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
100
101
        - kubectl delete -f deploy/redis || true
        - kubectl apply -f deploy/persistent-redis
102

103
104
105
106
107
108
109
110
111
terminate:
    stage: terminate
    only:
        variables:
            - $TERMINATE == "yes"
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
112
113
        - kubectl delete -f deploy/redis || true
        - kubectl delete -f deploy/redis-persistent || true
Nane Kratzke's avatar
Nane Kratzke committed
114
115
        - kubectl delete -f deploy/prime || true
        - kubectl delete -f deploy/storage || true