-
Notifications
You must be signed in to change notification settings - Fork 2
146 lines (125 loc) · 4.08 KB
/
test-docker-stack.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
name: Test Docker Stack
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
docker:
timeout-minutes: 20
runs-on: ubuntu-24.04
env:
# Overwrite dev.env to use http
PROXY_DEFAULT_ENTRYPOINTS: web
PROXY_DEFAULT_SCHEME: http
# Overwrite Addresses in dev.env
FRONTEND_ADDRESS: werkstatthub.docker.localhost
DOCS_ADDRESS: docs.werkstatthub.docker.localhost
KEYCLOAK_ADDRESS: keycloak.werkstatthub.docker.localhost
API_ADDRESS: api.werkstatthub.docker.localhost
DOCS_BUILD_WITH_PDF: 0
COMPOSE_PROFILES: full
steps:
# Setup environment
- name: Checkout
uses: actions/checkout@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
if: ${{ !env.ACT }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Install Python Development package (only ACT)
if: ${{ env.ACT }}
run: sudo apt-get update && sudo apt-get install python3-dev -y
- name: Setup python venv
run: python3 -m venv .venv
- name: Install python dependecies
run: |
source .venv/bin/activate
pip3 install -r requirements.txt
deactivate
# Tag Containers
- name: Build containers and save cache (only on main)
if: ${{ github.ref_name == 'main' && github.ref_type == 'branch'}}
run: |
docker compose \
--env-file=dev.env \
-f docker-compose.yml \
-f cache-from-override.yml \
-f cache-to-override.yml \
build
- name: Build containers (other than main)
if: ${{ github.ref_name != 'main' && github.ref_type == 'branch'}}
run: |
docker compose \
--env-file=dev.env \
-f docker-compose.yml \
-f cache-from-override.yml \
build
# Start Containers
- name: Start containers and wait for healthy state
run: |
docker compose \
--env-file=dev.env \
-f docker-compose.yml \
-f cache-from-override.yml \
up -d --wait
# Wait for Traefik to generate routes
- name: Proxy setup delay
run: sleep 10s
# Test API
- name: Check if API is healthy
run: |
curl -fs -o /dev/null -w 'http_code:%{http_code}' \
$PROXY_DEFAULT_SCHEME://$API_ADDRESS/v1/health/ping \
|| exit 1
- name: Check for strict-transport-security header
run: |
curl -sIX GET $PROXY_DEFAULT_SCHEME://$API_ADDRESS/v1/health/ping \
| grep -iq "strict-transport-security" \
|| exit 1
- name: Run pytest
run: |
source .venv/bin/activate
pytest ./api
deactivate
# Test documentation
- name: Check if documentation is reachable
run: |
curl -fs -o /dev/null -w 'http_code:%{http_code}' \
$PROXY_DEFAULT_SCHEME://$DOCS_ADDRESS \
|| exit 1
# Test MongoDB
- name: Check if MongoDB is reachable
run: |
curl -fs -o /dev/null -w 'http_code:%{http_code}' \
http://localhost:27017 \
|| exit 1
# Test Nautilus
- name: Check if Nautilus is reachable
run: |
curl -fs -o /dev/null -w 'http_code:%{http_code}' \
http://localhost:3000/health \
|| exit 1
# Test Keycloak
- name: Check if Keycloak is healthy
run: |
curl -fs -o /dev/null -w 'http_code:%{http_code}' \
$PROXY_DEFAULT_SCHEME://$KEYCLOAK_ADDRESS/health/live \
|| exit 1
# Test Frontend
- name: Check if Frontend is reachable
run: |
curl -fs -o /dev/null -w 'http_code:%{http_code}' \
$PROXY_DEFAULT_SCHEME://$FRONTEND_ADDRESS \
|| exit 1
# Clean up
- name: Stop containers
if: always()
run: docker compose --env-file=dev.env down -v