-
Notifications
You must be signed in to change notification settings - Fork 0
250 lines (215 loc) · 7.94 KB
/
ci-dev.yml
File metadata and controls
250 lines (215 loc) · 7.94 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: CI-Dev
on:
pull_request:
branches: ["Development"]
paths:
- "api-service/**"
- "web/**"
- ".github/workflows/ci-dev.yml"
push:
branches: ["Development"]
paths:
- "api-service/**"
- "web/**"
- ".github/workflows/ci-dev.yml"
tags-ignore:
- "**"
permissions:
contents: read
pull-requests: write
packages: write
jobs:
api-service-tests:
name: api-service Tests
runs-on: ubuntu-latest
environment: Development
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
cache-dependency-path: api-service/package-lock.json
- name: Install dependencies
working-directory: api-service
run: npm ci
- name: Run unit tests
working-directory: api-service
run: npm run test
- name: Run integration tests
working-directory: api-service
run: npm run test
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
- name: Run API tests
working-directory: api-service
run: npm run test
web-tests:
name: Web Tests
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
cache-dependency-path: web/package-lock.json
- name: Install dependencies
working-directory: web
run: npm ci
- name: Run unit tests
working-directory: web
run: npm run test
- name: Run component tests
working-directory: web
run: npm run test
# - name: Run E2E tests
# uses: cypress-io/github-action@v6
# with:
# working-directory: web
# start: npm run dev
# wait-on: "http://localhost:5173"
# wait-on-timeout: 120000
docker-tests:
name: Docker Tests
runs-on: ubuntu-latest
environment: Production
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Updated Docker Compose installation
- name: Install Docker Compose
run: |
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
- name: Create env file
run: |
echo "MONGODB_URI=${{ secrets.MONGODB_URI }}" >> .env
echo "DB_NAME=tapiro" >> .env
echo "AUTH0_SPA_CLIENT_ID=${{ secrets.AUTH0_SPA_CLIENT_ID }}" >> .env
echo "AUTH0_ISSUER_BASE_URL=${{ secrets.AUTH0_ISSUER_BASE_URL }}" >> .env
echo "AUTH0_TOKEN_URL=${{ secrets.AUTH0_TOKEN_URL }}" >> .env
echo "AUTH0_AUTHORIZE_URL=${{ secrets.AUTH0_AUTHORIZE_URL }}" >> .env
echo "AUTH0_AUDIENCE=${{ secrets.AUTH0_AUDIENCE }}" >> .env
echo "AUTH0_MANAGEMENT_API_TOKEN=${{ secrets.AUTH0_MANAGEMENT_API_TOKEN }}" >> .env
echo "AUTH0_USER_ROLE_ID=${{ secrets.AUTH0_USER_ROLE_ID }}" >> .env
echo "AUTH0_STORE_ROLE_ID=${{ secrets.AUTH0_STORE_ROLE_ID }}" >> .env
echo "AUTH0_M2M_CLIENT_ID=${{ secrets.AUTH0_M2M_CLIENT_ID }}" >> .env
echo "AUTH0_M2M_CLIENT_SECRET=${{ secrets.AUTH0_M2M_CLIENT_SECRET }}" >> .env
echo "AI_SERVICE_API_KEY=${{ secrets.AI_SERVICE_API_KEY }}" >> .env
echo "AUTH0_DOMAIN=${{ secrets.AUTH0_DOMAIN }}" >> .env
echo "ALLOWED_ORIGINS=http://localhost:5174" >> .env
# Variables for compose.yml that are not secrets but good to have in .env for consistency
echo "REDIS_HOST=redis" >> .env
echo "REDIS_PORT=6379" >> .env
echo "BASE_URL=http://localhost:3000" >> .env
echo "FRONTEND_URL=http://localhost:5173" >> .env
echo "AI_SERVICE_URL=http://ml-service:8000/api" >> .env
echo "EXTERNAL_API_URL=http://tapiro-api-external:3001" >> .env
echo "API_BASE_URL=http://tapiro-api-internal:3000" >> .env # For ml-service
echo "VITE_API_URL=http://localhost:3000" >> .env # For web
echo "VITE_STORE_API_URL=http://localhost:3001" >> .env # For demo-store
- name: Build containers
run: docker compose -f compose.yml build
# No explicit env block needed here if .env file is comprehensive
- name: Test container health
run: |
docker compose -f compose.yml up -d
echo "Waiting for containers to start..."
sleep 30 # Adjust sleep time if services take longer to start
# Check status of all services defined in compose.yml
SERVICES_COUNT=$(docker compose -f compose.yml config --services | wc -l)
RUNNING_CONTAINERS=$(docker compose -f compose.yml ps --services --filter "status=running" | wc -l)
echo "Expected services: $SERVICES_COUNT"
echo "Running containers: $RUNNING_CONTAINERS"
if [ "${RUNNING_CONTAINERS}" -eq "${SERVICES_COUNT}" ]; then
echo "All containers are running"
docker compose ps
else
echo "Not all containers started successfully."
docker compose ps
docker compose logs
exit 1
fi
- name: Show logs on failure
if: failure()
run: |
echo "api-service logs:"
docker compose logs api-service
echo "Frontend logs:"
docker compose logs web
echo "Redis logs:"
docker compose logs redis
- name: Cleanup
if: always()
run: docker compose down
validate:
name: Validate
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
strategy:
matrix:
service: [web, api-service]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
cache-dependency-path: ${{ matrix.service }}/package-lock.json
- name: Install dependencies
working-directory: ${{ matrix.service }}
run: npm ci
- name: Run linting
working-directory: ${{ matrix.service }}
run: npm run lint
- name: Run tests
working-directory: ${{ matrix.service }}
run: npm test
# build:
# needs: validate
# name: Build & Push
# runs-on: ubuntu-latest
# if: github.event_name == 'push' && github.ref == 'refs/heads/Development'
# permissions:
# contents: read
# packages: write
# strategy:
# matrix:
# service: [web, api-service]
# steps:
# - uses: actions/checkout@v4
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Prepare Docker tags
# id: prep
# run: |
# REPO=${GITHUB_REPOSITORY,,}
# echo "repository=${REPO}" >> "$GITHUB_OUTPUT"
# echo "sha=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
# - name: Build and push
# uses: docker/build-push-action@v5
# with:
# context: ./${{ matrix.service }}
# file: ./${{ matrix.service }}/dockerfile.dev
# push: true
# tags: |
# ghcr.io/${{ steps.prep.outputs.repository }}/${{ matrix.service }}:${{ steps.prep.outputs.sha }}
# ghcr.io/${{ steps.prep.outputs.repository }}/${{ matrix.service }}:dev
# cache-from: type=gha
# cache-to: type=gha,mode=max