Skip to content

Commit 202490d

Browse files
committed
2 parents 5701834 + 4ae6513 commit 202490d

File tree

75 files changed

+1519
-799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1519
-799
lines changed

.github/workflows/image-service-ci-cd.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ jobs:
129129
sed -i "s|DOCKERHUB_USERNAME_PLACEHOLDER|${{ secrets.DOCKERHUB_USERNAME }}|g" /tmp/deploy-image-service.sh
130130
sed -i "s|MONGO_ROOT_USERNAME_PLACEHOLDER|${{ secrets.MONGO_ROOT_USERNAME }}|g" /tmp/deploy-image-service.sh
131131
sed -i "s|MONGO_ROOT_PASSWORD_PLACEHOLDER|${{ secrets.MONGO_ROOT_PASSWORD }}|g" /tmp/deploy-image-service.sh
132-
# MONGO_INITDB_DATABASE placeholder'ı artık kullanılmıyor, doğrudan sabit değer kullanılacak
133-
# sed -i "s|MONGO_INITDB_DATABASE_PLACEHOLDER|${{ secrets.MONGO_INITDB_DATABASE }}|g" /tmp/deploy-image-service.sh
132+
# MONGO_INITDB_DATABASE placeholder'ı kaldırıldı, doğrudan sabit değer kullanılıyor
134133
sed -i "s|OPENAI_API_KEY_PLACEHOLDER|${{ secrets.OPENAI_API_KEY }}|g" /tmp/deploy-image-service.sh
135134
136135
# Make script executable

.github/workflows/llm-service-ci-cd.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
--name llm-service \
160160
--network craftpilot-network \
161161
--restart unless-stopped \
162-
-p 8062:8062 \
162+
-p 8066:8066 \
163163
-p 5005:5005 \
164164
-v /opt/craftpilot/gcp-credentials.json:/gcp-credentials.json:ro \
165165
-v /opt/craftpilot/tmp/netty:/tmp/netty \
@@ -199,7 +199,7 @@ jobs:
199199
--ulimit nofile=65536:65536 \
200200
--cap-drop ALL \
201201
--security-opt no-new-privileges \
202-
--health-cmd="curl -f http://localhost:8062/actuator/health/liveness || exit 1" \
202+
--health-cmd="curl -f http://localhost:8066/actuator/health/liveness || exit 1" \
203203
--health-interval=30s \
204204
--health-timeout=10s \
205205
--health-retries=3 \
@@ -210,7 +210,7 @@ jobs:
210210
--name llm-service \
211211
--network craftpilot-network \
212212
--restart unless-stopped \
213-
-p 8062:8062 \
213+
-p 8066:8066 \
214214
-v /opt/craftpilot/gcp-credentials.json:/gcp-credentials.json:ro \
215215
-v /opt/craftpilot/tmp/netty:/tmp/netty \
216216
-e SPRING_PROFILES_ACTIVE=prod \
@@ -249,7 +249,7 @@ jobs:
249249
--ulimit nofile=65536:65536 \
250250
--cap-drop ALL \
251251
--security-opt no-new-privileges \
252-
--health-cmd="curl -f http://localhost:8062/actuator/health/liveness || exit 1" \
252+
--health-cmd="curl -f http://localhost:8066/actuator/health/liveness || exit 1" \
253253
--health-interval=30s \
254254
--health-timeout=10s \
255255
--health-retries=3 \
@@ -278,17 +278,17 @@ jobs:
278278
docker exec llm-service nc -zv $MONGODB_CONTAINER 27017 || echo "Cannot connect to MongoDB from container"
279279
280280
echo "MongoDB component health check:"
281-
docker exec llm-service curl -s http://localhost:8062/actuator/health/mongo || echo "MongoDB health component unavailable"
281+
docker exec llm-service curl -s http://localhost:8066/actuator/health/mongo || echo "MongoDB health component unavailable"
282282
fi
283283
284284
# Health check
285-
HEALTH_CHECK=$(curl -s http://localhost:8062/actuator/health || echo '{"status":"UNKNOWN"}')
285+
HEALTH_CHECK=$(curl -s http://localhost:8066/actuator/health || echo '{"status":"UNKNOWN"}')
286286
287287
if echo "$HEALTH_CHECK" | grep -q '"status":"UP"'; then
288288
echo "✓ Service is healthy"
289289
290290
# MongoDB specific health check
291-
if echo "$HEALTH_CHECK" | grep -q '"mongo":{"status":"UP"' || docker exec llm-service curl -s http://localhost:8062/actuator/health/mongo | grep -q '"status":"UP"'; then
291+
if echo "$HEALTH_CHECK" | grep -q '"mongo":{"status":"UP"' || docker exec llm-service curl -s http://localhost:8066/actuator/health/mongo | grep -q '"status":"UP"'; then
292292
echo "✓ MongoDB connection verified"
293293
echo "=== Deployment completed successfully ==="
294294
exit 0
@@ -315,7 +315,7 @@ jobs:
315315
echo "Container Logs:"
316316
docker logs llm-service --tail 100
317317
echo "Health Check Response:"
318-
curl -v http://localhost:8062/actuator/health || true
318+
curl -v http://localhost:8066/actuator/health || true
319319
echo "MongoDB Connection Test:"
320320
docker exec llm-service nc -zv $MONGODB_CONTAINER 27017 || echo "MongoDB connection failed"
321321
exit 1

.github/workflows/mongodb-service-ci-cd.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,16 @@ jobs:
248248
#!/bin/bash
249249
set -e
250250
251+
MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE:-craftpilot_main}
252+
251253
# Env dosyasını yükle
252254
if [ -f "../.env" ]; then
253255
source ../.env
254256
else
255257
echo "Uyarı: .env dosyası bulunamadı, varsayılan değerler kullanılıyor..."
256258
MONGO_ROOT_USERNAME=${MONGO_ROOT_USERNAME:-craftpilot}
257259
MONGO_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD:-secure_password}
258-
MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE:-craftpilot}
260+
MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE:-craftpilot_main}
259261
MONGO_PORT=${MONGO_PORT:-27017}
260262
fi
261263
@@ -301,14 +303,18 @@ jobs:
301303
#!/bin/bash
302304
set -e
303305
306+
// ...existing code...
307+
MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE:-craftpilot_main}
308+
// ...existing code...
309+
304310
# Env dosyasını yükle
305311
if [ -f "../.env" ]; then
306312
source ../.env
307313
else
308314
echo "Uyarı: .env dosyası bulunamadı, varsayılan değerler kullanılıyor..."
309315
MONGO_ROOT_USERNAME=${MONGO_ROOT_USERNAME:-craftpilot}
310316
MONGO_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD:-secure_password}
311-
MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE:-craftpilot}
317+
MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE:-craftpilot_main}
312318
MONGO_PORT=${MONGO_PORT:-27017}
313319
fi
314320

.github/workflows/notification-service-ci-cd.yml

Lines changed: 142 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ jobs:
1818
steps:
1919
- uses: actions/checkout@v3
2020

21+
- id: "auth"
22+
name: "Authenticate to Google Cloud"
23+
uses: "google-github-actions/auth@v1"
24+
with:
25+
credentials_json: "${{ secrets.GCP_SA_KEY }}"
26+
2127
- name: Set up JDK
2228
uses: actions/setup-java@v3
2329
with:
@@ -82,26 +88,55 @@ jobs:
8288
echo "Checking Docker service status..."
8389
systemctl status docker || true
8490
85-
echo "Checking existing containers..."
86-
docker ps -a | grep notification-service || true
87-
88-
echo "Creating network if not exists..."
91+
# Infrastructure containers
8992
docker network create craftpilot-network || true
9093
91-
echo "Pulling latest image..."
92-
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/notification-service:latest-arm64
94+
# MongoDB container check
95+
MONGODB_CONTAINER="craftpilot-mongodb"
96+
if ! docker ps | grep -q "$MONGODB_CONTAINER"; then
97+
echo "WARNING: Default MongoDB container not found ($MONGODB_CONTAINER)"
98+
# Try to detect any MongoDB container as fallback
99+
MONGODB_CONTAINER=$(docker ps --format '{{.Names}}' | grep -E 'mongo|mongodb' | head -n 1)
100+
if [ -z "$MONGODB_CONTAINER" ]; then
101+
echo "ERROR: No MongoDB container found! Using default name, but connection may fail."
102+
MONGODB_CONTAINER="craftpilot-mongodb" # Fallback to default
103+
else
104+
echo "Found alternative MongoDB container: $MONGODB_CONTAINER"
105+
fi
106+
fi
107+
echo "Using MongoDB container: $MONGODB_CONTAINER"
108+
109+
# Test MongoDB connection before deployment
110+
echo "Testing MongoDB connection..."
111+
if docker run --rm --network craftpilot-network mongo:6.0 mongosh --quiet --eval "db.runCommand({ping:1}).ok" admin --host $MONGODB_CONTAINER --port 27017 -u ${{ secrets.MONGO_ROOT_USERNAME }} -p ${{ secrets.MONGO_ROOT_PASSWORD }} --authenticationDatabase admin | grep -q "1"; then
112+
echo "✅ MongoDB connection test successful!"
113+
else
114+
echo "⚠️ MongoDB connection test failed! Deployment will continue but may have issues."
115+
echo "Checking MongoDB container status:"
116+
docker ps | grep -i $MONGODB_CONTAINER || echo "Container not found!"
117+
fi
118+
119+
echo "Checking existing containers..."
120+
docker ps -a | grep notification-service || true
93121
94122
echo "Stopping and removing existing container..."
95123
docker stop notification-service || true
96124
docker rm notification-service || true
97125
98126
echo "Setting up directories and permissions..."
99127
mkdir -p /opt/craftpilot/config/notification-service
128+
mkdir -p /craftpilot
100129
101130
echo "Creating Firebase credentials..."
102-
echo '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}' > /opt/craftpilot/config/notification-service/firebase-service-account.json
131+
# Standardize credentials path to /craftpilot/gcp-credentials.json
132+
echo '${{ secrets.GCP_SA_KEY }}' > /craftpilot/gcp-credentials.json
133+
chmod 644 /craftpilot/gcp-credentials.json
134+
ls -la /craftpilot/gcp-credentials.json
135+
136+
# Also keep existing path for backward compatibility
137+
echo '${{ secrets.GCP_SA_KEY }}' > /opt/craftpilot/config/notification-service/firebase-service-account.json
103138
chmod 644 /opt/craftpilot/config/notification-service/firebase-service-account.json
104-
chown 65532:65532 /opt/craftpilot/config/notification-service/firebase-service-account.json
139+
ls -la /opt/craftpilot/config/notification-service/firebase-service-account.json
105140
106141
echo "#!/bin/sh
107142
curl -f http://localhost:8053/actuator/health || exit 1" > /opt/craftpilot/config/notification-service/healthcheck.sh
@@ -110,12 +145,27 @@ jobs:
110145
# Create function definition in a variable to avoid semicolon issues
111146
FUNCTION_DEF="notificationEventConsumer;notificationEventProducer"
112147
113-
# DNS ayarlarını güncelle
148+
# Setup networking config
114149
echo "Setting up networking config..."
115150
cat > /opt/craftpilot/config/notification-service/grpc-netty.properties << EOF
116151
io.netty.handler.ssl.openssl.useKeyManagerFactory=true
117152
EOF
118153
154+
# Build MongoDB URI with the correct container name
155+
if [ -n "${{ secrets.MONGODB_URI }}" ]; then
156+
# Parse the URI and replace the hostname with our container name
157+
URI_PREFIX=$(echo "${{ secrets.MONGODB_URI }}" | grep -oP 'mongodb://[^@]+@')
158+
URI_SUFFIX=$(echo "$URI_PREFIX" | grep -oP '(?<=@)[^/]+/.*')
159+
URI_HOST=$(echo "$URI_SUFFIX" | grep -oP '^[^:/]+')
160+
URI_REMAINDER=$(echo "$URI_SUFFIX" | grep -oP '(?<='"$URI_HOST"')[:/].*')
161+
162+
MONGODB_URI="${URI_PREFIX}${MONGODB_CONTAINER}${URI_REMAINDER}"
163+
echo "Modified MongoDB URI with correct container name: $(echo $MONGODB_URI | sed 's/:[^:]*@/:*****@/g')"
164+
else
165+
MONGODB_URI="mongodb://${{ secrets.MONGO_ROOT_USERNAME }}:${{ secrets.MONGO_ROOT_PASSWORD }}@${MONGODB_CONTAINER}:27017/craftpilot_notification_db?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=60000"
166+
echo "Built MongoDB URI from credential components: $(echo $MONGODB_URI | sed 's/:[^:]*@/:*****@/g')"
167+
fi
168+
119169
echo "Starting container..."
120170
docker run -d \
121171
--name notification-service \
@@ -128,9 +178,11 @@ jobs:
128178
-p 8053:8053 \
129179
-v /opt/craftpilot/config/notification-service:/app/config:ro \
130180
-v "/opt/craftpilot/config/notification-service/firebase-service-account.json:/app/credentials/firebase-credentials.json:ro" \
181+
-v "/craftpilot/gcp-credentials.json:/app/gcp-credentials.json:ro" \
131182
-v "/opt/craftpilot/config/notification-service/grpc-netty.properties:/app/config/grpc-netty.properties:ro" \
132183
-v "/opt/craftpilot/config/notification-service/healthcheck.sh:/app/healthcheck.sh:ro" \
133184
-e FIREBASE_CONFIG=/app/credentials/firebase-credentials.json \
185+
-e GOOGLE_APPLICATION_CREDENTIALS=/app/gcp-credentials.json \
134186
-e SPRING_PROFILES_ACTIVE=prod \
135187
-e SERVER_PORT=8053 \
136188
-e KAFKA_BOOTSTRAP_SERVERS=kafka:9092 \
@@ -147,7 +199,8 @@ jobs:
147199
-e SPRING_DATA_REDIS_HOST=redis \
148200
-e SPRING_DATA_REDIS_PORT=6379 \
149201
-e SPRING_DATA_REDIS_PASSWORD=13579ada \
150-
-e MONGODB_URI=${{ secrets.MONGODB_URI }} \
202+
-e MONGODB_URI="${MONGODB_URI}" \
203+
-e SPRING_DATA_MONGODB_URI="${MONGODB_URI}" \
151204
-e SPRING_DATA_MONGODB_DATABASE=craftpilot_notification_db \
152205
-e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://craftpilot:13579ada@eureka-server:8761/eureka/ \
153206
-e SPRING_MAIL_SENDGRID_FROM='${{ secrets.SENDGRID_FROM_EMAIL }}' \
@@ -169,49 +222,93 @@ jobs:
169222
${{ secrets.DOCKERHUB_USERNAME }}/notification-service:latest-arm64
170223
171224
echo "Waiting for container to start..."
172-
sleep 180 # Increased wait time
225+
sleep 30
173226
174-
echo "Checking container status..."
175-
if [ "$(docker ps -q -f name=notification-service)" ]; then
176-
echo "Container is running successfully"
177-
echo "Container logs:"
178-
docker logs notification-service --tail 100
179-
180-
echo "Container health status:"
181-
docker inspect --format='{{json .State.Health}}' notification-service
182-
183-
echo "Testing container health:"
184-
if docker exec notification-service /healthcheck.sh; then
185-
echo "Health check passed"
186-
else
187-
echo "Health check failed"
227+
echo "Performing enhanced health checks..."
228+
# Install jq if not present for proper JSON parsing
229+
if ! command -v jq &> /dev/null; then
230+
apt-get update && apt-get install -y jq || echo "Could not install jq, will use alternatives"
231+
fi
232+
233+
# Enhanced health check with component verification
234+
for i in {1..20}; do
235+
if ! docker ps | grep -q "notification-service"; then
236+
echo "❌ Container stopped unexpectedly!"
237+
docker logs notification-service || echo "No logs available"
188238
exit 1
189239
fi
190240
191-
echo "Container network info:"
192-
docker inspect notification-service | grep -i ip
193-
194-
echo "Testing container health:"
195-
curl -v http://localhost:8053/actuator/health || true
241+
# Try health check with better parsing
242+
HEALTH_CHECK=$(curl -s http://localhost:8053/actuator/health || echo "{}")
196243
197-
echo "Verifying Firestore connectivity..."
198-
docker exec notification-service curl -v https://firestore.googleapis.com/
199-
200-
echo "Verifying SendGrid API connectivity..."
201-
docker exec notification-service curl -v https://api.sendgrid.com/v3/mail/send -H "Authorization: Bearer $SENDGRID_API_KEY"
202-
else
203-
echo "Container failed to start"
204-
echo "Container logs:"
205-
docker logs notification-service
244+
# Check if overall service is UP
245+
if echo "$HEALTH_CHECK" | grep -q '"status":"UP"'; then
246+
echo "✅ Service reports overall status as UP!"
247+
248+
# Try to parse with jq if available
249+
if command -v jq &> /dev/null; then
250+
MONGO_STATUS=$(echo "$HEALTH_CHECK" | jq -r '.components.mongodb.status' 2>/dev/null || echo "UNKNOWN")
251+
REDIS_STATUS=$(echo "$HEALTH_CHECK" | jq -r '.components.redis.status' 2>/dev/null || echo "UNKNOWN")
252+
253+
if [ "$MONGO_STATUS" = "UP" ] && [ "$REDIS_STATUS" = "UP" ]; then
254+
echo "✅ All critical components are healthy!"
255+
echo "Deployment completed successfully!"
256+
docker logs notification-service --tail 20
257+
exit 0
258+
else
259+
echo "⚠️ Service is UP but component statuses - MongoDB: $MONGO_STATUS, Redis: $REDIS_STATUS"
260+
fi
261+
elif echo "$HEALTH_CHECK" | grep -q '"mongodb":{.*"status":"UP"' && echo "$HEALTH_CHECK" | grep -q '"redis":{.*"status":"UP"'; then
262+
echo "✅ All critical components are healthy based on string search!"
263+
echo "Deployment completed successfully!"
264+
docker logs notification-service --tail 20
265+
exit 0
266+
fi
267+
268+
# If we've been UP for several checks, assume success
269+
if [ $i -ge 10 ]; then
270+
echo "✅ Service has been reporting UP status for multiple checks"
271+
echo "Assuming deployment is successful"
272+
docker logs notification-service --tail 20
273+
exit 0
274+
fi
275+
fi
206276
207-
echo "Docker events:"
208-
docker events --filter container=notification-service --since 5m || true
277+
echo "Health check attempt $i/20 - service not ready yet or components not healthy"
209278
210-
echo "System logs:"
211-
journalctl -u docker.service --since "5 minutes ago" || true
279+
# Enhanced diagnostics on certain iterations
280+
if [ $i -eq 5 ] || [ $i -eq 10 ] || [ $i -eq 15 ]; then
281+
echo "--- Connection Diagnostics ---"
282+
echo "MongoDB container status:"
283+
docker ps | grep $MONGODB_CONTAINER || echo "MongoDB container not running!"
284+
285+
echo "Redis container status:"
286+
docker ps | grep redis || echo "Redis container not running!"
287+
288+
echo "Testing network connectivity:"
289+
docker exec notification-service nc -zv $MONGODB_CONTAINER 27017 || echo "Cannot connect to MongoDB"
290+
docker exec notification-service nc -zv redis 6379 || echo "Cannot connect to Redis"
291+
292+
echo "Container environment variables:"
293+
docker exec notification-service env | grep -E 'MONGO|REDIS|SENDGRID' || echo "No relevant env vars found"
294+
295+
echo "Network details:"
296+
docker network inspect craftpilot-network | grep -A 5 -E "$MONGODB_CONTAINER|redis|notification-service" || echo "Network inspection failed"
297+
fi
212298
213-
exit 1
214-
fi
299+
sleep 15
300+
done
301+
302+
echo "❌ Service failed to become fully healthy within timeout period."
303+
echo "Final container logs:"
304+
docker logs notification-service --tail 50
305+
echo "Container is still running for debugging purposes."
306+
307+
# Testing external connectivity
308+
echo "Testing SendGrid API connectivity..."
309+
docker exec notification-service curl -v https://api.sendgrid.com/v3/mail/send -H "Authorization: Bearer $SENDGRID_API_KEY" || echo "SendGrid connection failed"
310+
311+
exit 1
215312
216313
# Disable debug mode
217314
set +x

0 commit comments

Comments
 (0)