This repository has been archived by the owner on Sep 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
73 lines (67 loc) · 2 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
stages:
- build
- test
- deploy
# Global Variables
variables:
DOCKER_DRIVER: overlay2
IMAGE_NAME: registry.gitlab.com/${CI_PROJECT_PATH}
IMAGE_NAME_COMMIT: registry.gitlab.com/${CI_PROJECT_PATH}/commits/${CI_PROJECT_NAME}:${CI_BUILD_REF}
# Build Stage
Push Commit Image:
stage: build
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
script:
- docker pull ${IMAGE_NAME}:latest || true
- docker build --cache-from ${IMAGE_NAME}:latest --tag ${IMAGE_NAME_COMMIT} .
- docker push ${IMAGE_NAME_COMMIT}
# Test Stage
Test Templates:
stage: test
image: ${IMAGE_NAME_COMMIT}
before_script:
- oc version
- oc login ${KUBE_URL} --token=${KUBE_TOKEN}
- oc project cloudigrade-ci
script:
- kontemplate template ocp/local.yaml | oc apply --dry-run -f -
- kontemplate template ocp/review.yaml | oc apply --dry-run -f -
- kontemplate template ocp/test.yaml | oc apply --dry-run -f -
Test Ansible Playbooks:
stage: test
image: ${IMAGE_NAME_COMMIT}
script:
- ansible-playbook --syntax-check ansible/*.yaml
# Deploy Stage
Push Latest Image:
stage: deploy
image: docker:stable
services:
- docker:dind
only:
- master@cloudigrade/shiftigrade
except:
- tags@cloudigrade/shiftigrade
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
script:
- docker pull ${IMAGE_NAME_COMMIT} || true
- docker build --cache-from ${IMAGE_NAME_COMMIT} --tag ${IMAGE_NAME}:latest .
- docker push ${IMAGE_NAME}:latest
Push Tagged Image:
stage: deploy
image: docker:stable
services:
- docker:dind
only:
- tags@cloudigrade/shiftigrade
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
script:
- docker pull ${IMAGE_NAME_COMMIT} || true
- docker build --cache-from ${IMAGE_NAME_COMMIT} --tag ${IMAGE_NAME}:${CI_COMMIT_TAG} .
- docker push ${IMAGE_NAME}:${CI_COMMIT_TAG}