Skip to content

Commit 8e5ff6f

Browse files
committed
feat: MongoDB yapılandırması güncellendi; GitHub Secrets kullanılarak URI ve kimlik bilgileri ayarlandı, bağlantı kontrolleri eklendi, uygulama yapılandırmaları optimize edildi.
1 parent d1f4785 commit 8e5ff6f

File tree

5 files changed

+92
-10
lines changed

5 files changed

+92
-10
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,16 @@ jobs:
9999
docker stop admin-service || true
100100
docker rm admin-service || true
101101
102-
# MongoDB URI configuration - using container variable
103-
MONGODB_URI="mongodb://craftpilot:secure_password@${MONGODB_CONTAINER}:27017/craftpilot?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=60000"
102+
# MongoDB URI configuration - using GitHub Secrets
103+
if [ -n "${{ secrets.MONGODB_URI }}" ]; then
104+
# Use the URI directly from secrets if available
105+
MONGODB_URI="${{ secrets.MONGODB_URI }}"
106+
echo "Using pre-configured MongoDB URI from secrets"
107+
else
108+
# Otherwise, build the URI from components
109+
MONGODB_URI="mongodb://${{ secrets.MONGO_ROOT_USERNAME }}:${{ secrets.MONGO_ROOT_PASSWORD }}@${MONGODB_CONTAINER}:27017/${{ secrets.MONGO_INITDB_DATABASE || 'craftpilot' }}?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=60000"
110+
echo "Built MongoDB URI from credential components"
111+
fi
104112
echo "MongoDB URI: $(echo $MONGODB_URI | sed 's/:[^:]*@/:\*\*\*@/g')"
105113
106114
echo "Starting admin-service container with environment: ${{ github.event.inputs.environment || 'prod' }}"

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

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,40 @@ jobs:
6666
username: ${{ secrets.SSH_USERNAME }}
6767
key: ${{ secrets.SSH_PRIVATE_KEY }}
6868
script: |
69+
# Ensure network exists
70+
echo "=== Creating or verifying network ==="
71+
docker network create craftpilot-network 2>/dev/null || true
72+
73+
# Determine MongoDB container and connection info
74+
echo "=== Checking MongoDB container ==="
75+
MONGODB_CONTAINER="craftpilot-mongodb"
76+
if ! docker ps | grep -q "$MONGODB_CONTAINER"; then
77+
echo "WARNING: Default MongoDB container not found, trying alternative names..."
78+
MONGODB_CONTAINER=$(docker ps --format '{{.Names}}' | grep -E 'mongo|mongodb' | head -n 1)
79+
80+
if [ -z "$MONGODB_CONTAINER" ]; then
81+
echo "ERROR: No MongoDB container found, using default name"
82+
MONGODB_CONTAINER="craftpilot-mongodb"
83+
else
84+
echo "Found MongoDB container: $MONGODB_CONTAINER"
85+
fi
86+
fi
87+
echo "Using MongoDB container: $MONGODB_CONTAINER"
88+
89+
# Configure MongoDB URI
90+
if [ -n "${{ secrets.MONGODB_URI }}" ]; then
91+
# Use the URI directly from secrets if available
92+
MONGODB_URI="${{ secrets.MONGODB_URI }}"
93+
echo "Using pre-configured MongoDB URI from secrets"
94+
else
95+
# Otherwise, build the URI from components
96+
MONGODB_URI="mongodb://${{ secrets.MONGO_ROOT_USERNAME }}:${{ secrets.MONGO_ROOT_PASSWORD }}@${MONGODB_CONTAINER}:27017/${{ secrets.MONGO_INITDB_DATABASE || 'craftpilot' }}?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=30000&connectTimeoutMS=20000&socketTimeoutMS=60000"
97+
echo "Built MongoDB URI from credential components"
98+
fi
99+
echo "MongoDB URI: $(echo $MONGODB_URI | sed 's/:[^:]*@/:\*\*\*@/g')"
69100
70101
# Deploy Credit Service
102+
echo "=== Deploying Credit Service ==="
71103
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/credit-service:latest-arm64
72104
docker stop credit-service || true
73105
docker rm credit-service || true
@@ -84,23 +116,65 @@ jobs:
84116
-e GOOGLE_APPLICATION_CREDENTIALS=/gcp-credentials.json \
85117
-e SPRING_SECURITY_USER_NAME=craftpilot \
86118
-e SPRING_SECURITY_USER_PASSWORD=13579ada \
119+
-e MONGODB_URI="$MONGODB_URI" \
120+
-e MONGODB_DATABASE="${{ secrets.MONGO_INITDB_DATABASE || 'craftpilot' }}" \
87121
-e REDIS_HOST=redis \
88122
-e REDIS_PORT=6379 \
89123
-e REDIS_PASSWORD=13579ada \
90124
-e MANAGEMENT_HEALTH_VALIDATE_GROUP_MEMBERSHIP=false \
125+
-e MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE="health,info,metrics,prometheus" \
126+
-e MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS=always \
91127
${{ secrets.DOCKERHUB_USERNAME }}/credit-service:latest-arm64
92128
129+
# Verify MongoDB connection
130+
echo "=== Verifying MongoDB connection ==="
131+
sleep 5
132+
if docker exec credit-service nc -z -w5 $MONGODB_CONTAINER 27017; then
133+
echo "✅ MongoDB connection successful"
134+
else
135+
echo "⚠️ MongoDB connection check failed"
136+
echo "Testing connection from host machine..."
137+
nc -z -w5 localhost 27017 && echo "Host can connect to MongoDB" || echo "Host cannot connect to MongoDB"
138+
139+
# Check network details
140+
echo "Container network details:"
141+
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' credit-service
142+
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $MONGODB_CONTAINER
143+
fi
144+
93145
# Enhanced health check with longer timeout
94-
echo "Waiting for service to start..."
95-
for i in {1..12}; do
146+
echo "=== Waiting for service to start ==="
147+
MAX_ATTEMPTS=12
148+
ATTEMPT=1
149+
150+
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
151+
echo "Health check attempt $ATTEMPT/$MAX_ATTEMPTS"
152+
153+
# Check container status
154+
if ! docker ps | grep -q "credit-service"; then
155+
echo "Container stopped unexpectedly! Checking logs..."
156+
docker logs credit-service
157+
exit 1
158+
fi
159+
160+
# Check health
96161
if curl -s http://localhost:8058/actuator/health | grep -q "UP"; then
97-
echo "Service is healthy"
162+
echo "Service is healthy"
98163
exit 0
99164
fi
100-
echo "Attempt $i: Service not ready yet..."
165+
166+
echo "Service not ready yet... Waiting"
167+
168+
# Show logs at middle of attempts
169+
if [ $ATTEMPT -eq 6 ]; then
170+
echo "Service logs:"
171+
docker logs credit-service --tail 50
172+
fi
173+
174+
ATTEMPT=$((ATTEMPT + 1))
101175
sleep 10
102176
done
103177
104-
echo "Service failed to become healthy within timeout"
178+
echo "Service failed to become healthy within timeout"
105179
docker logs credit-service
106180
exit 1

activity-log-service/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spring:
1414
include: kafka-base
1515
data:
1616
mongodb:
17-
uri: ${MONGODB_URI:mongodb://craftpilot:secure_password@mongodb:27017/craftpilot?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=5000}
17+
uri: ${MONGODB_URI:mongodb://${MONGO_ROOT_USERNAME:craftpilot}:${MONGO_ROOT_PASSWORD:secure_password}@craftpilot-mongodb:27017/${MONGO_INITDB_DATABASE:craftpilot}?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=30000&connectTimeoutMS=20000&socketTimeoutMS=60000}
1818
database: ${MONGODB_DATABASE:craftpilot}
1919
connection-timeout: 30000
2020
socket-timeout: 60000

admin-service/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spring:
1414
include: kafka-base
1515
data:
1616
mongodb:
17-
uri: ${SPRING_DATA_MONGODB_URI:mongodb://craftpilot:secure_password@craftpilot-mongodb:27017/craftpilot?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=60000}
17+
uri: ${SPRING_DATA_MONGODB_URI:mongodb://${MONGO_ROOT_USERNAME:craftpilot}:${MONGO_ROOT_PASSWORD:secure_password}@craftpilot-mongodb:27017/${SPRING_DATA_MONGODB_DATABASE:craftpilot}?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=60000}
1818
database: ${SPRING_DATA_MONGODB_DATABASE:craftpilot}
1919
auto-index-creation: true
2020
connect-timeout: 60000

credit-service/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ spring:
6060
web-application-type: reactive
6161
data:
6262
mongodb:
63-
uri: ${MONGODB_URI:mongodb://craftpilot:secure_password@mongodb:27017/craftpilot?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=5000}
63+
uri: ${MONGODB_URI:mongodb://${MONGO_ROOT_USERNAME:craftpilot}:${MONGO_ROOT_PASSWORD:secure_password}@craftpilot-mongodb:27017/${MONGO_INITDB_DATABASE:craftpilot}?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=30000&connectTimeoutMS=20000&socketTimeoutMS=60000}
6464
database: ${MONGODB_DATABASE:craftpilot}
6565
connection-timeout: 30000
6666
socket-timeout: 60000

0 commit comments

Comments
 (0)