.gitlab-ci.yml 3.16 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
  NAMESPACE: "nane-kratzke"
4
  URL: "$GITLAB_USER_NAME.loki.th-luebeck.dev"
5
6
  PRIME: "yes"
  CACHE: "no"
7
8
  PERSISTENT_CACHE: "no"
  TERMINATE: "no"
9
10

stages:
11
    - prepare
12
13
    - build
    - deploy
14
    - terminate
15

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

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

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

52
deploy-prime:
53
    stage: deploy
54
55
56
    only:
        variables:
            - $PRIME == "yes"
57
            - $TERMINATE != "yes"
58
59
60
61
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
62
        - 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
63
64
        - ./yq w -i deploy/prime/prime-ingress.yaml spec.rules[0].host $URL
        - ./yq w -i deploy/prime/prime-ingress.yaml spec.tls[0].hosts[0] $URL
65
66
67
68
69
70
71
72
        - kubectl delete -f deploy/prime -n $NAMESPACE || true
        - kubectl apply -f deploy/prime -n $NAMESPACE

deploy-cache:
    stage: deploy
    only:
        variables:
            - $CACHE == "yes"
73
74
            - $PERSISTENT_CACHE == "no"
            - $TERMINATE != "yes"
75
76
77
78
79
80
81
82
83
84
85
86
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - kubectl delete -f deploy/persistent-redis -n $NAMESPACE || true
        - kubectl delete -f deploy/redis -n $NAMESPACE || true
        - kubectl apply -f deploy/redis -n $NAMESPACE

deploy-persistent-cache:
    stage: deploy
    only:
        variables:
87
            - $CACHE == "yes"
88
            - $PERSISTENT_CACHE == "yes"
89
            - $TERMINATE != "yes"
90
91
92
93
94
95
96
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - kubectl delete -f deploy/redis -n $NAMESPACE || true
        - kubectl delete -f deploy/persistent-redis -n $NAMESPACE || true
        - kubectl apply -f deploy/persistent-redis -n $NAMESPACE
97

98
99
100
101
102
103
104
105
106
107
108
109
110
terminate:
    stage: terminate
    only:
        variables:
            - $TERMINATE == "yes"
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - kubectl delete -f deploy/redis -n $NAMESPACE || true
        - kubectl delete -f deploy/redis-persistent -n $NAMESPACE || true
        - kubectl delete -f deploy/prime -n $NAMESPACE || true
        - kubectl delete -f deploy/storage -n $NAMESPACE || true