.gitlab-ci.yml 2.64 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"
Nane Kratzke's avatar
Nane Kratzke committed
4
  VERSION: "0.0.1"
Nane Kratzke's avatar
Nane Kratzke committed
5
  URL: "prime-nk.loki.th-luebeck.dev"
6
7
  PRIME: "yes"
  CACHE: "no"
Nane Kratzke's avatar
Nane Kratzke committed
8
  PERSISTENT_CACHE: "yes"
9

10
11

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

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
34
35
36
37
38
39
40
41
claim-volume:
    stage: prepare
    only:
        variables:
            - $VOLUME == "yes"
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - kubectl apply -f deploy/storage -n $NAMESPACE

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

52
deploy-prime:
53
    stage: deploy
54
55
56
    only:
        variables:
            - $PRIME == "yes"
57
58
59
60
61
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - echo "Deploying to Kubernetes"
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        - kubectl delete -f deploy/prime -n $NAMESPACE || true
        - kubectl apply -f deploy/prime -n $NAMESPACE

deploy-cache:
    stage: deploy
    only:
        variables:
            - $CACHE == "yes"
    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:
            - $PERSISTENT_CACHE == "yes"
    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
93

94