-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
87 lines (79 loc) · 2.22 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
image: docker:stable
stages:
- build_nginx_image
- build_image
- deploy
- move_ns
- update
variables:
IMAGE_NAME: $CI_REGISTRY/scpomedialab/scpo-experts-search
NGINX_IMAGE_NAME: $CI_REGISTRY/scpomedialab/scpo-experts-search-nginx
before_script:
- VERSION=$(echo $CI_COMMIT_TAG | sed -nre 's/^v([0-9.]+)$/\1/p')
- if [ -n "${VERSION}" ]; then IMAGE_TAG=${VERSION}; else IMAGE_TAG=${CI_COMMIT_REF_SLUG}; fi
- STACKS=$(ls "k8s/overlays/$CI_COMMIT_REF_SLUG/" 2> /dev/null || echo)
- export KUBECONFIG=$kubeconfig_file
build_image:
stage: build_image
script:
- docker build -t $IMAGE_NAME:$IMAGE_TAG -f Dockerfile .
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
- docker push $IMAGE_NAME:$IMAGE_TAG
environment:
name: $CI_COMMIT_REF_SLUG
only:
- tags
except:
- schedules
build_nginx_image:
stage: build_nginx_image
script:
- docker build -t $NGINX_IMAGE_NAME:$IMAGE_TAG -f ./nginx/Dockerfile ./nginx/
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
- docker push $NGINX_IMAGE_NAME:$IMAGE_TAG
environment:
name: $CI_COMMIT_REF_SLUG
only:
- tags
except:
- schedules
deploy:
image:
name: jrisp/kubehelper:latest
entrypoint: [""]
stage: deploy
script:
- for stack in $STACKS; do echo "Deploying halexp-$stack overlay..."; kubectl apply -f k8s/overlays/$CI_COMMIT_REF_SLUG/$stack/ns.yml; kubectl apply -k k8s/overlays/$CI_COMMIT_REF_SLUG/$stack; done
environment:
name: $CI_COMMIT_REF_SLUG
only:
- staging
- prod
except:
- schedules
move_ns:
image:
name: rancher/cli2:v2.4.5
entrypoint: [""]
stage: move_ns
script:
- rancher login $RANCHER_URL --token $RANCHER_TOKEN --context $RANCHER_CONTEXT
- for stack in $STACKS; do rancher namespaces move halexp-$stack $RANCHER_CONTEXT; done
environment:
name: $CI_COMMIT_REF_SLUG
only:
- staging
- prod
except:
- schedules
update:
image:
name: jrisp/kubehelper:latest
entrypoint: [""]
stage: update
script:
- for stack in $STACKS; do echo "Redeploying halexp-$stack overlay..."; kubectl -n halexp-$stack rollout restart deployment halexp; done
environment:
name: $CI_COMMIT_REF_SLUG
only:
- schedules