@@ -113,26 +113,59 @@ jobs:
113113 script : |
114114 cd /home/ec2-user
115115
116- # Pull latest image
116+ echo "=== Starting Frontend Deployment ==="
117+
118+ # Login to GitHub Container Registry
117119 echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
120+
121+ # Pull latest image
122+ echo "Pulling latest frontend image..."
118123 docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
119124
120- # Stop PM2 process
121- pm2 stop autoswappr-dapp || true
122- pm2 delete autoswappr-dapp || true
125+ # Check if running via PM2 (legacy setup)
126+ if pm2 list | grep -q "autoswappr-dapp"; then
127+ echo "Detected PM2 process - migrating to Docker..."
128+ pm2 stop autoswappr-dapp || true
129+ pm2 delete autoswappr-dapp || true
130+ pm2 save --force
131+ echo "✓ PM2 process stopped and removed"
132+ fi
123133
124- # Stop and remove old container
125- docker stop autoswappr-dapp || true
126- docker rm autoswappr-dapp || true
134+ # Stop and remove old Docker container if exists
135+ if docker ps -a --format '{{.Names}}' | grep -q "^autoswappr-dapp$"; then
136+ echo "Stopping existing Docker container..."
137+ docker stop autoswappr-dapp || true
138+ docker rm autoswappr-dapp || true
139+ fi
127140
128141 # Run new container
142+ echo "Starting new frontend container..."
129143 docker run -d \
130144 --name autoswappr-dapp \
131145 --restart unless-stopped \
132146 -p 3000:3000 \
133147 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
134148
149+ # Wait for container to be healthy
150+ echo "Waiting for frontend to be healthy..."
151+ sleep 5
152+
153+ # Health check
154+ for i in {1..30}; do
155+ if curl -f http://localhost:3000 >/dev/null 2>&1; then
156+ echo "✓ Frontend is healthy!"
157+ break
158+ fi
159+ if [ $i -eq 30 ]; then
160+ echo "✗ Frontend health check failed!"
161+ docker logs autoswappr-dapp --tail 50
162+ exit 1
163+ fi
164+ echo "Waiting for frontend... ($i/30)"
165+ sleep 2
166+ done
167+
135168 # Clean up old images
136169 docker image prune -af
137170
138- echo "Frontend deployment completed successfully! "
171+ echo "=== Frontend Deployment Completed Successfully! === "
0 commit comments