-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
138 lines (123 loc) · 3.75 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
stages:
- build
- test
- update
- release
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
RELEASE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
PUBLIC_RELEASE_TAG: yourlabs/playlabs:$CI_COMMIT_REF_NAME
PUBLIC_IMAGE_TAG: yourlabs/playlabs:$CI_COMMIT_SHA
ANSIBLE_FORCE_COLOR: 'true'
USER: gitlab
cache:
paths:
- .vagrant/cache
.vagrant: &vagrant
stage: test
tags: [shell]
before_script:
- export venv="$(pwd)/vagrant-${CI_JOB_ID}-env"
- rm -rf "vagrant-*-env"; virtualenv -p python3 $venv
- source $venv/bin/activate
- pip install -e .
- rm -rf inventory
- vagrant destroy -f; vagrant up
- export ssh_config="$(pwd)/vagrant-${CI_JOB_ID}-ssh-config"
- rm -rf "vagrant-*-ssh-config"; vagrant ssh-config > $ssh_config
- export VAGRANT_IP=$(vagrant ssh -c "ip -o -4 addr show dev eth1 | cut -d' ' -f7 | cut -d'/' -f1" )
after_script:
- vagrant destroy -f
- rm -rf $venv $ssh_config inventory
deployment:
<<: *vagrant
script:
- playlabs deploy @default --ssh-common-args="-F $ssh_config"
image=yourlabs/crudlfap:master
dns=$VAGRANT_IP
- rm -rf inventory && playlabs scaffold inventory && cd inventory
- playlabs install ssh @default --ssh-common-args="-F $ssh_config"
- playlabs deploy deploy@default
image=yourlabs/crudlfap:master
dns=$VAGRANT_IP
--tags=update
--ssh-common-args="-F $ssh_config"
monitoring:
<<: *vagrant
script:
- playlabs install netdata @default --ssh-common-args="-F $ssh_config"
- rm -rf inventory && playlabs scaffold inventory && cd inventory
- playlabs install netdata @default --ssh-common-args="-F $ssh_config"
k8s:
<<: *vagrant
script:
- playlabs install k8s @default --ssh-common-args="-F $ssh_config"
build:
stage: build
image: docker:dind
before_script:
- echo $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
script:
- docker pull $CI_REGISTRY_IMAGE:master || true
- docker build --cache-from $CI_REGISTRY_IMAGE:master -t $IMAGE_TAG .
- docker push $IMAGE_TAG
- docker logout $CI_REGISTRY
- echo -n $DOCKER_PASS | docker login --username "$DOCKER_USER" --password-stdin
- docker tag $IMAGE_TAG $PUBLIC_IMAGE_TAG
- docker push $PUBLIC_IMAGE_TAG
after_script:
- docker logout
#buildah version, better because ci is not privileged, but where is caching
#support ? Not to mention the random failures ...
# image: tomkukral/buildah
# before_script:
# - podman login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY
# script:
# - buildah bud -t $IMAGE_TAG .
# - buildah push $IMAGE_TAG docker://$IMAGE_TAG
# after_script:
# - podman logout $CI_REGISTRY
py-qa:
stage: build
image: yourlabs/python
script: flake8 --show-source --max-complexity=11 --ignore=E305,W503 playlabs
py-test:
stage: test
image: $IMAGE_TAG
script: cd playlabs/tests/ && py.test --cov playlabs
ubuntu-init:
stage: test
image: $IMAGE_TAG
services:
- name: rastasheep/ubuntu-sshd
alias: target
command:
- /usr/sbin/sshd
- -e
- -o
- LogLevel=DEBUG
- -D
before_script: [ssh-keygen -f $HOME/.ssh/id_rsa]
script:
- playlabs init root:root@target sshd_handler=reloaded
pypi:
stage: release
image: yourlabs/python
script: pypi-release
docker-push:
stage: release
image: docker:stable
services: ['docker:dind']
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script:
- echo $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- docker pull $IMAGE_TAG
- docker tag $IMAGE_TAG $RELEASE_TAG
- docker push $RELEASE_TAG
- docker logout
- echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
- docker tag $IMAGE_TAG $PUBLIC_RELEASE_TAG
- docker push $PUBLIC_RELEASE_TAG
- docker logout