-
Notifications
You must be signed in to change notification settings - Fork 1.6k
151 lines (129 loc) · 4.65 KB
/
integration-tests.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
name: Integration tests
# pull requests:
# push:
# run on every push, which is when something gets merged also
on:
workflow_dispatch:
pull_request:
push:
branches:
- master
- dev
- release/**
- hotfix/**
env:
DD_DOCKER_REPO: defectdojo
jobs:
build:
# build with docker so we can use layer caching
name: Build Image
runs-on: ubuntu-latest
strategy:
matrix:
docker-image: [django, nginx, integration-tests]
steps:
# - name: Login to DockerHub
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v2
- name: Read Docker Image Identifiers
id: read-docker-image-identifiers
run: echo "IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
env:
docker-image: ${{ matrix.docker-image }}
with:
path: /tmp/.buildx-cache-${{ env.docker-image }}
key: ${{ runner.os }}-buildx-${{ env.docker-image }}-${{ github.workflow }}-${{ github.sha }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.docker-image }}-${{ github.workflow }}-${{ github.sha }}
${{ runner.os }}-buildx-${{ env.docker-image }}-${{ github.workflow }}
${{ runner.os }}-buildx-${{ env.docker-image }}
- name: Build
id: docker_build
uses: docker/build-push-action@v2
env:
docker-image: ${{ matrix.docker-image }}
with:
context: .
push: false
tags: |
${{ env.DD_DOCKER_REPO }}/defectdojo-${{ env.docker-image }}:latest
file: Dockerfile.${{ env.docker-image }}
outputs: type=docker,dest=${{ env.docker-image }}_img
cache-from: type=local,src=/tmp/.buildx-cache-${{ env.docker-image }}
cache-to: type=local,dest=/tmp/.buildx-cache-${{ env.docker-image }}
# export docker images to be used in next jobs below
- name: Upload image ${{ matrix.docker-image }} as artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.docker-image }}
path: ${{ matrix.docker-image }}_img
retention-days: 1
integration_tests:
# run tests with docker-compose
name: integration tests
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
test-case: [
"tests/finding_test.py",
"tests/report_builder_test.py",
"tests/notes_test.py",
"tests/regulations_test.py",
"tests/product_type_test.py",
"tests/product_test.py",
"tests/endpoint_test.py",
"tests/engagement_test.py",
"tests/environment_test.py",
"tests/test_test.py",
"tests/user_test.py",
"tests/group_test.py",
"tests/product_group_test.py",
"tests/product_type_group_test.py",
"tests/product_member_test.py",
"tests/product_type_member_test.py",
"tests/ibm_appscan_test.py",
"tests/search_test.py",
"tests/file_test.py",
"tests/dedupe_test.py",
"tests/check_various_pages.py",
]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
# load docker images from build jobs
- name: Load images from artifacts
uses: actions/download-artifact@v2
- name: Load docker images
run: |-
docker load -i nginx/nginx_img
docker load -i django/django_img
docker load -i integration-tests/integration-tests_img
docker images
- name: Set integration-test mode
run: ln -s docker-compose.override.integration_tests.yml docker-compose.override.yml
# phased startup so we can use the exit code from integrationtest container
- name: Start Dojo
# implicity starts uwsgi and rabbitmq
run: docker-compose up -d mysql nginx celerybeat celeryworker
- name: Initialize
run: docker-compose up --exit-code-from initializer initializer
- name: Integration tests
run: docker-compose up --exit-code-from integration-tests integration-tests
env:
DD_INTEGRATION_TEST_FILENAME: ${{ matrix.test-case }}
- name: Logs
if: always()
run: docker-compose logs --tail="2500"
- name: Shutdown
if: always()
run: docker-compose down