-
-
Notifications
You must be signed in to change notification settings - Fork 184
191 lines (157 loc) · 6.39 KB
/
Copy pathproduction-stack.yml
File metadata and controls
191 lines (157 loc) · 6.39 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
name: Production Stack Test
# Enable Buildkit and let compose use it to speed up image building
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
defaults:
run:
working-directory: ./
on:
pull_request:
branches: [ "master", "main", "v*" ]
paths:
- "compose/production/**"
- "production.yml"
- ".github/workflows/production-stack.yml"
push:
branches: [ "master", "main", "v*" ]
paths:
- "compose/production/**"
- "production.yml"
- ".github/workflows/production-stack.yml"
concurrency:
group: production-stack-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
production-stack:
runs-on: larger
timeout-minutes: 50
permissions:
contents: read
steps:
- name: Checkout Code Repository
uses: actions/checkout@v7
- name: Create Required Environment Files
run: |
mkdir -p .envs/.production
# Create minimal Django env file based on sample
cat > .envs/.production/.django << 'EOF'
# Core Django Security Settings
DJANGO_SETTINGS_MODULE=config.settings.production
DJANGO_SECRET_KEY=test-secret-key-for-ci-only-not-secure
DJANGO_ADMIN_URL=admin/
DJANGO_SECURE_SSL_REDIRECT=false
# Django Username and Password for Initial Admin Login
DJANGO_SUPERUSER_PASSWORD=Openc0ntracts_test
DJANGO_SUPERUSER_EMAIL=test@opensource.legal
DJANGO_SUPERUSER_USERNAME=admin
# General
USE_DOCKER=yes
WEB_CONCURRENCY=4
IPYTHONDIR=/app/.ipython
DJANGO_ALLOWED_HOSTS=django,127.0.0.1,localhost,0.0.0.0,contracts.opensource.legal
DJANGO_WORKER_TIMEOUT=3600
# Application Configuration
USE_ANALYZER=false
CALLBACK_ROOT_URL_FOR_ANALYZER=http://django:8000
# AWS - disabled for testing
USE_AWS=false
AWS_ACCESS_KEY_ID=test-key
AWS_SECRET_ACCESS_KEY=test-secret
AWS_STORAGE_BUCKET_NAME=test-bucket
AWS_S3_REGION_NAME=us-east-1
# Redis
REDIS_URL=redis://redis:6379/0
# Celery
# Flower
CELERY_FLOWER_USER=test
CELERY_FLOWER_PASSWORD=test
# NLM Parser
NLM_INGESTOR_ACTIVE=false
# LLM SETTINGS
OPENAI_API_KEY=test-api-key-not-real
OPENAI_MODEL=gpt-4o
# AUTH0 - disabled for testing
USE_AUTH0=false
AUTH0_CLIENT_ID=test-client-id
AUTH0_API_AUDIENCE=https://opensource.legal/contracts
AUTH0_DOMAIN=test.auth0.com
AUTH0_M2M_MANAGEMENT_API_SECRET=test-secret
AUTH0_M2M_MANAGEMENT_API_ID=test-id
AUTH0_M2M_MANAGEMENT_GRANT_TYPE=client_credentials
EMBEDDINGS_MICROSERVICE_URL=http://vector-embedder:8000
DOCLING_PARSER_SERVICE_URL=http://docling-parser:8000/parse/
# Docling
DOCLING_MODELS_PATH=/models/docling
EOF
# Create minimal Postgres env file
cat > .envs/.production/.postgres << 'EOF'
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=opencontracts
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
DATABASE_SSL_MODE=disable
EOF
# Create minimal Frontend env file based on sample
cat > .envs/.production/.frontend << 'EOF'
OPEN_CONTRACTS_REACT_APP_APPLICATION_DOMAIN=contracts.opensource.legal
OPEN_CONTRACTS_REACT_APP_APPLICATION_CLIENT_ID=test-client-id
OPEN_CONTRACTS_REACT_APP_AUDIENCE=http://localhost:3000
OPEN_CONTRACTS_REACT_APP_API_ROOT_URL=http://django:8000
# Disabled for testing
OPEN_CONTRACTS_REACT_APP_USE_AUTH0=false
OPEN_CONTRACTS_REACT_APP_USE_ANALYZERS=false
OPEN_CONTRACTS_REACT_APP_ALLOW_IMPORTS=false
EOF
- name: Build Production Stack (CI Mode)
run: docker compose -f production.yml -f compose/test-production-ci.yml build
- name: Run Database Migrations
run: |
echo "Running database migrations before starting services..."
docker compose -f production.yml -f compose/test-production-ci.yml --profile migrate up migrate
echo "Migrations completed successfully"
- name: Start Production Stack (CI Mode - HTTP only)
run: |
docker compose -f production.yml -f compose/test-production-ci.yml up -d
echo "Waiting for services to start..."
sleep 30 # Give services time to start
echo "Checking if required services are running..."
docker compose -f production.yml -f compose/test-production-ci.yml ps --services --filter status=running
# Wait for Django to be ready
echo "Waiting for Django to be ready..."
for i in {1..30}; do
if docker compose -f production.yml -f compose/test-production-ci.yml exec -T django python manage.py check --deploy 2>/dev/null; then
echo "Django is ready!"
break
fi
echo "Django not ready yet, waiting..."
sleep 2
done
- name: Verify Stack Health
run: |
echo "=== Docker containers status ==="
docker compose -f production.yml -f compose/test-production-ci.yml ps
echo "=== Container health checks ==="
for container in $(docker compose -f production.yml -f compose/test-production-ci.yml ps -q); do
name=$(docker inspect -f '{{.Name}}' $container | sed 's/^\/*//')
echo "--- Health for $name ---"
docker logs --tail 10 $container 2>&1 || true
done
- name: Test Rate Limiting (HTTP-only for CI)
run: |
./scripts/test-ci-rate-limiting.sh --compose-files "production.yml compose/test-production-ci.yml"
- name: Capture Logs on Failure
if: failure()
run: |
echo "=== Capturing logs for debugging ==="
docker compose -f production.yml -f compose/test-production-ci.yml logs --no-color > production-stack-logs.txt
- name: Upload Logs on Failure
if: failure()
uses: actions/upload-artifact@v7
with:
name: production-stack-logs
path: production-stack-logs.txt
- name: Tear Down Stack
if: always()
run: docker compose -f production.yml -f compose/test-production-ci.yml down -v