.gitlab-ci.yml 3.04 KB
Newer Older
1
variables:
Nane Kratzke's avatar
Nane Kratzke committed
2
  KUBECTL: "quay.io/bitnami/kubectl:1.18"
3
  PRIME: "yes"
4
  CACHE: "in-memory"        # one of "no", "in-memory", "persistent"
Nane Kratzke's avatar
Finish    
Nane Kratzke committed
5
  TERMINATE: "no"
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
45
46
    except:
        variables:
            - $TERMINATE == "yes"
Nane Kratzke's avatar
Nane Kratzke committed
47
    only:
Nane Kratzke's avatar
Nane Kratzke committed
48
49
        variables:
            - $PRIME == "yes"
Nane Kratzke's avatar
Nane Kratzke committed
50
51
    services:
        - docker:dind
52
    script:
Nane Kratzke's avatar
Nane Kratzke committed
53
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
54
        - cd prime
55
        - docker build -t $CI_REGISTRY_IMAGE/prime:latest .
Nane Kratzke's avatar
Nane Kratzke committed
56
        - docker push $CI_REGISTRY_IMAGE/prime:latest
57

58
deploy-prime:
59
    stage: deploy
Nane Kratzke's avatar
Nane Kratzke committed
60
61
62
    except:
        variables:
            - $TERMINATE == "yes"
63
64
65
    only:
        variables:
            - $PRIME == "yes"
66
67
68
69
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
70
        - echo prime-$GITLAB_USER_ID.loki.th-luebeck.dev
Nane Kratzke's avatar
Nane Kratzke committed
71
        - 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
72
73
        - ./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
74
        - kubectl apply -f deploy/prime
75
76
77

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

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

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