-
Notifications
You must be signed in to change notification settings - Fork 2
197 lines (169 loc) · 5.69 KB
/
Copy pathdocker-image.yml
File metadata and controls
197 lines (169 loc) · 5.69 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
name: CI/CD Pipeline
# Define variables at the top
env:
REGISTRY: ghcr.io
IMAGE_NAME: sandialabs/vista
PYTHON_VERSION: "3.11"
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
checks: write
security-events: write
packages: write
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up Node.js
uses: actions/setup-node@v5
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev which
- name: Build frontend
run: |
cd frontend
npm ci --legacy-peer-deps
npm run build
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install Python dependencies with uv
run: uv sync --frozen
- name: Set up test environment
run: |
cp .env.example backend/.env || echo "No .env.example found, using defaults"
- name: Run tests
run: uv run bash test/run_tests.sh
env:
DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5432/postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_SERVER: localhost
POSTGRES_PORT: 5432
DEBUG: true
SKIP_HEADER_CHECK: true
MOCK_USER_EMAIL: test@example.com
JUNIT_XML_PATH: ${{ github.workspace }}/test-results/backend.xml
- name: Publish test results
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Backend Test Results
path: test-results/backend.xml
reporter: java-junit
build:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test container
run: |
# Start the container (install dev deps for aiosqlite SQLite driver)
docker run -d --name test-container \
-e DATABASE_URL="sqlite+aiosqlite:///./test.db" \
-e FAST_TEST_MODE=true \
-e DEBUG=true \
-e SKIP_HEADER_CHECK=true \
-e ENV=development \
-e VISTA_AUTH_BACKEND=demo \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-e POSTGRES_SERVER=localhost \
-p 8000:8000 \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
bash -c "uv sync --frozen && uvicorn main:app --host 0.0.0.0 --port 8000"
# Wait for container to start and implement health checking with retry
echo "Waiting for container to become healthy..."
for i in {1..30}; do
if curl -f http://localhost:8000/api/health > /dev/null 2>&1; then
echo "Container is healthy after ${i} attempts"
break
fi
if [ $i -eq 30 ]; then
echo "Container failed to become healthy after 30 attempts"
docker logs test-container
exit 1
fi
echo "Attempt $i failed, waiting 2 seconds..."
sleep 2
done
# Test health endpoint one more time to be sure
curl -f http://localhost:8000/api/health || exit 1
# Stop container
docker stop test-container
docker rm test-container
- name: Run tests in container
run: |
docker run --rm \
-e DATABASE_URL="sqlite+aiosqlite:///./test.db" \
-e FAST_TEST_MODE=true \
-e DEBUG=true \
-e SKIP_HEADER_CHECK=true \
-e ENV=development \
-e VISTA_AUTH_BACKEND=demo \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-e POSTGRES_SERVER=localhost \
--workdir /app \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
bash -c "uv sync --frozen && bash test/run_tests.sh --backend"
- name: Push Docker image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max