.gitlab-ci.yml 3.17 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
  PERSISTENT_CACHE: "no"
Nane Kratzke's avatar
Nane Kratzke committed
6
  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
claim-volume:
    stage: prepare
Nane Kratzke's avatar
Nane Kratzke committed
29
30
31
    except:
        variables:
            - $TERMINATE == "yes"
32
33
    only:
        variables:
Nane Kratzke's avatar
Nane Kratzke committed
34
            - $PERSISTENT_CACHE == "yes"
35
36
37
38
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
39
        - kubectl apply -f deploy/storage
40
41

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

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

deploy-cache:
    stage: deploy
Nane Kratzke's avatar
Nane Kratzke committed
76
77
78
    except:
        variables:
            - $TERMINATE == "yes"
79
80
81
    only:
        variables:
            - $CACHE == "yes"
82
            - $PERSISTENT_CACHE == "no"
83
84
85
86
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
87
88
89
        - kubectl delete -f deploy/persistent-redis || true
        - kubectl delete -f deploy/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:
98
            - $CACHE == "yes"
99
100
101
102
103
            - $PERSISTENT_CACHE == "yes"
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
104
105
106
        - kubectl delete -f deploy/redis || true
        - kubectl delete -f deploy/persistent-redis || true
        - kubectl apply -f deploy/persistent-redis
107

108
109
110
111
112
113
114
115
116
terminate:
    stage: terminate
    only:
        variables:
            - $TERMINATE == "yes"
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
117
118
119
120
        - 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