.gitlab-ci.yml 1.85 KB
Newer Older
1
2
variables:
  KUBECTL: "bitnami/kubectl:1.18.9"
Nane Kratzke's avatar
Nane Kratzke committed
3
  NAMESPACE: "nane-kratzke"
Nane Kratzke's avatar
Nane Kratzke committed
4
  VERSION: "0.0.1"
5
  BRANCH: "$CI_COMMIT_BRANCH"
Nane Kratzke's avatar
Nane Kratzke committed
6
  URL: "prime-nk.loki.th-luebeck.dev"
7
8

stages:
9
    - prepare
10
11
12
    - build
    - deploy

Nane Kratzke's avatar
Nane Kratzke committed
13
prime-container:
14
15
16
17
18
19
20
21
22
23
    stage: build
    services:
        - docker:dind
    only:
        changes:
        - prime/*
        - .gitlab-ci.yml
    script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - cd prime
Nane Kratzke's avatar
Nane Kratzke committed
24
        - docker build -t $CI_REGISTRY_IMAGE/prime:$VERSION -t $CI_REGISTRY_IMAGE/prime:latest .
25
26
        - docker push $CI_REGISTRY_IMAGE/prime:$VERSION
        - docker push $CI_REGISTRY_IMAGE/prime:latest
27

28
prime-storage:
29
    stage: prepare
30
31
32
33
34
35
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - kubectl apply -f deploy/storage -n $NAMESPACE

36
37
deploy-credentials:
    stage: prepare
38
39
40
41
42
43
44
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - kubectl delete secret gitlab-registry-credentials -n $NAMESPACE || true
        - "kubectl create secret docker-registry gitlab-registry-credentials \
                    --docker-server=$CI_REGISTRY \
45
46
                    --docker-username=image-registry \ 
                    --docker-password=$CI_REGISTRY_TOKEN \
47
                    -n $NAMESPACE"
48

49
prime-service:
50
51
52
53
54
55
    stage: deploy
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - echo "Deploying to Kubernetes"
Nane Kratzke's avatar
Nane Kratzke committed
56
        - 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
57
58
        - ./yq w -i deploy/service/prime-ingress.yaml spec.rules[0].host $URL
        - ./yq w -i deploy/service/prime-ingress.yaml spec.tls[0].hosts[0] $URL
Nane Kratzke's avatar
Nane Kratzke committed
59
        - cat deploy/service/prime-ingress.yaml
Nane Kratzke's avatar
Nane Kratzke committed
60
61
        - kubectl delete -f deploy/service -n $NAMESPACE || true
        - kubectl apply -f deploy/service -n $NAMESPACE
62

63