.gitlab-ci.yml 3.08 KB
Newer Older
1
variables:
Nane Kratzke's avatar
Nane Kratzke committed
2
  KUBECTL: "quay.io/bitnami/kubectl:1.18"
3
  PRIME: "yes"
Nane Kratzke's avatar
Nane Kratzke committed
4
  INMEM_CACHE: "no"
5
  PERSISTENT_CACHE: "no"
Nane Kratzke's avatar
Nane Kratzke committed
6
  TERMINATE: "yes"
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
        - kubectl delete secret gitlab-registry-credentials || true
Nane Kratzke's avatar
Nane Kratzke committed
21
22
23
        - "kubectl create secret docker-registry gitlab-registry-credentials \
                    --docker-server=$CI_REGISTRY \
                    --docker-username=image-registry \ 
Nane Kratzke's avatar
Nane Kratzke committed
24
                    --docker-password=$CI_REGISTRY_TOKEN"
Nane Kratzke's avatar
Nane Kratzke committed
25

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

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

53
deploy-prime:
54
    stage: deploy
Nane Kratzke's avatar
Nane Kratzke committed
55
56
57
    except:
        variables:
            - $TERMINATE == "yes"
58
59
60
    only:
        variables:
            - $PRIME == "yes"
61
62
63
64
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
65
        - echo prime-$GITLAB_USER_ID.loki.th-luebeck.dev
Nane Kratzke's avatar
Nane Kratzke committed
66
        - 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
67
68
69
        - ./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
70
71
        - kubectl delete -f deploy/prime || true
        - 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
            - $INMEM_CACHE == "yes"
81
82
83
84
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
Nane Kratzke's avatar
Nane Kratzke committed
85
86
87
        - kubectl delete -f deploy/persistent-redis || true
        - kubectl delete -f deploy/redis || true
        - kubectl apply -f deploy/redis
88
89
90

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

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