-
Notifications
You must be signed in to change notification settings - Fork 274
/
config.yml
156 lines (152 loc) · 5.45 KB
/
config.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
version: 2.1
parameters:
VERSION:
type: string
default: ""
jobs:
ci:
machine:
image: ubuntu-2004:202010-01
resource_class: large
steps:
- checkout
- restore_cache:
keys:
- v1-docker-{{ .Branch }}
- run:
name: Install latest Docker and Docker Compose
command: |
mkdir -p $HOME/.docker/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-linux-x86_64 -o $HOME/.docker/cli-plugins/docker-compose
chmod +x $HOME/.docker/cli-plugins/docker-compose
- run:
name: Load Docker layers cache
command: |
set +o pipefail
docker load -i ~/docker-layers.tar | true
- run:
name: Docker compose
command: |
python3 rename.py git
cp -R ctfd/data/ tmp-ctfd/
docker compose -f docker-compose-dev.yaml up -d --build
- run:
name: Save Docker layers cache
command: |
DOCKER_IMAGES=$(docker images --format "{{ .Repository }}" --filter=reference="cidersecurity/goat-*")
DOCKER_LAYERS=$(for image in $DOCKER_IMAGES; do docker history $image -q | grep -v missing; done)
docker save -o ~/docker-layers.tar $DOCKER_LAYERS
- save_cache:
key: v1-docker-{{ .Branch }}-{{ epoch }}
paths:
- ~/docker-layers.tar
- run:
name: Install testing dependencies
command: |
python3 --version
python3 -m pip install pipenv
python3 -m pipenv install --deploy
- run:
name: Wait for services to start
command: |
for i in {1..30}
do
jenkins_status_code=$(curl --write-out %{http_code} --silent --output /dev/null localhost:8080/login) || true
gitea_status_code=$(curl --write-out %{http_code} --silent --output /dev/null localhost:3000/) || true
if [ "$jenkins_status_code" -eq 200 ] && [ "$gitea_status_code" -eq 200 ]; then
break
fi
sleep 1
done
sleep 80
- run:
name: Pytest
command: |
pipenv run python -m pytest tests/
release:
machine:
image: ubuntu-2004:202010-01
resource_class: large
environment:
ORG: cidersecurity
VERSION: << pipeline.parameters.VERSION >>
steps:
- checkout
- restore_cache:
keys:
- v1-docker-{{ .Branch }}
- run:
name: Install latest Docker and Docker Compose
command: |
mkdir -p $HOME/.docker/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-linux-x86_64 -o $HOME/.docker/cli-plugins/docker-compose
chmod +x $HOME/.docker/cli-plugins/docker-compose
- run:
name: Load Docker layers cache
command: |
echo $DOCKER_USERNAME | base64 | base64
set +o pipefail
docker load -i ~/docker-layers.tar | true
- run:
name: Docker compose
command: |
python3 rename.py git
cp -R ctfd/data/ tmp-ctfd/
docker compose -f docker-compose-dev.yaml build --build-arg VERSION=$VERSION --build-arg COMMIT_SHA=$CIRCLE_SHA1
docker compose -f docker-compose-dev.yaml up -d
- run:
name: Install testing dependencies
command: |
python3 --version
python3 -m pip install pipenv
python3 -m pipenv install --deploy
- run:
name: Wait for services to start
command: |
for i in {1..30}
do
jenkins_status_code=$(curl --write-out %{http_code} --silent --output /dev/null localhost:8080/login) || true
gitea_status_code=$(curl --write-out %{http_code} --silent --output /dev/null localhost:3000/) || true
if [ "$jenkins_status_code" -eq 200 ] && [ "$gitea_status_code" -eq 200 ]; then
break
fi
sleep 1
done
sleep 80
- run:
name: Pytest
command: |
pipenv run python -m pytest tests/
docker compose -f docker-compose-dev.yaml down
- run:
name: Push latest
command: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker compose -f docker-compose-dev.yaml push
- run:
name: Push version
command: |
echo "version: $VERSION"
docker tag $ORG/goat-jenkins-server:latest $ORG/goat-jenkins-server:$VERSION
docker tag $ORG/goat-jenkins-agent:latest $ORG/goat-jenkins-agent:$VERSION
docker tag $ORG/goat-gitea:latest $ORG/goat-gitea:$VERSION
docker tag $ORG/goat-ctfd:latest $ORG/goat-ctfd:$VERSION
docker tag $ORG/goat-lighttpd:latest $ORG/goat-lighttpd:$VERSION
docker push $ORG/goat-jenkins-server:$VERSION
docker push $ORG/goat-jenkins-agent:$VERSION
docker push $ORG/goat-gitea:$VERSION
docker push $ORG/goat-ctfd:$VERSION
docker push $ORG/goat-lighttpd:$VERSION
workflows:
version: 2
ci:
when:
equal: [ "", << pipeline.parameters.VERSION >> ]
jobs:
- ci
release:
when:
not:
equal: [ "", << pipeline.parameters.VERSION >> ]
jobs:
- release