-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
104 lines (95 loc) · 2.4 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
stages:
- build
- test
- release
- validate
- provision
- post-scripts
variables:
IMAGE_NAME: "registry.gitlab.com/pipeform/pipeformer"
build-on-code-change:
stage: build
image: docker:dind
services:
- docker:dind
rules:
- changes:
compare_to: 'refs/heads/main'
paths:
- src/**/*
- tests/**/*
- Dockerfile
- requirements.txt
script:
- docker info
- docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker build -t $IMAGE_NAME:$CI_COMMIT_SHORT_SHA .
- docker push $IMAGE_NAME:$CI_COMMIT_SHORT_SHA
run-unit-test:
image: $IMAGE_NAME:$CI_COMMIT_SHORT_SHA
stage: test
rules:
- changes:
compare_to: 'refs/heads/main'
paths:
- src/**/*
- tests/**/*
- Dockerfile
- requirements.txt
script:
- python -m pytest
release:
stage: release
image: docker:dind
services:
- docker:dind
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
compare_to: 'refs/heads/main'
paths:
- src/**/*
- tests/**/*
- Dockerfile
- requirements.txt
script:
- docker info
- docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker pull $IMAGE_NAME:$CI_COMMIT_SHORT_SHA
- docker tag $IMAGE_NAME:$CI_COMMIT_SHORT_SHA $IMAGE_NAME:latest
- docker push $IMAGE_NAME:latest
validate-configuration:
image: $IMAGE_NAME:latest
stage: validate
rules:
- changes:
- compute/**/*
script:
- if [ "$CI_COMMIT_BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
OLD_SHA=$(git rev-parse HEAD^);
else
OLD_SHA=$CI_COMMIT_BEFORE_SHA;
fi;
- python cli.py --old-sha $CI_COMMIT_SHA --new-sha $OLD_SHA validate
provision-compute:
image: $IMAGE_NAME:latest
stage: provision
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
- compute/**/*
script:
- python cli.py --old-sha $CI_COMMIT_SHA --new-sha $CI_COMMIT_BEFORE_SHA provision
apply-playbooks:
image: $IMAGE_NAME:latest
stage: post-scripts
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
- compute/**/*
before_script:
- mkdir -p ~/.ssh
- echo "$SSH_SERVICE" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
script:
- python cli.py --old-sha $CI_COMMIT_SHA --new-sha $CI_COMMIT_BEFORE_SHA playbooks