.gitlab-ci.yml 1.7 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

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

Nane Kratzke's avatar
Nane Kratzke committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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"

build:
27
    stage: build
Nane Kratzke's avatar
Nane Kratzke committed
28
29
30
31
32
33
    services:
        - docker:dind
    only:
        changes:
        - prime/*
        - .gitlab-ci.yml
34
    script:
Nane Kratzke's avatar
Nane Kratzke committed
35
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
36
        - cd prime
Nane Kratzke's avatar
Nane Kratzke committed
37
38
39
        - 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
40

Nane Kratzke's avatar
Nane Kratzke committed
41
deploy:
42
43
44
45
46
47
    stage: deploy
    image: 
        name: $KUBECTL
        entrypoint: [""]
    script:
        - echo "Deploying to Kubernetes"
Nane Kratzke's avatar
Nane Kratzke committed
48
        - 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
49
50
        - ./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
51
        - cat deploy/service/prime-ingress.yaml
Nane Kratzke's avatar
Nane Kratzke committed
52
53
        - kubectl delete -f deploy/service -n $NAMESPACE || true
        - kubectl apply -f deploy/service -n $NAMESPACE
54

55