Optimize github build workflow

This commit is contained in:
Karmaa
2025-03-16 21:02:21 -05:00
parent 8ae2e86fbc
commit 91eff86814
3 changed files with 56 additions and 38 deletions

View File

@@ -85,5 +85,8 @@ EXPOSE 8080 8081 8082 27017
# Copy and set entrypoint
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chmod +x /entrypoint.sh && \
mkdir -p /var/log/supervisor && \
chown -R root:root /var/log/supervisor
CMD ["/entrypoint.sh"]

View File

@@ -1,43 +1,11 @@
#!/bin/bash
set -e
# Create MongoDB pid directory if it doesn't exist
mkdir -p /var/run/mongodb /data/db /var/log/mongodb
# Create required directories
mkdir -p /var/run/mongodb /data/db /var/log/{mongodb,supervisor,nginx} /var/lib/nginx
chown -R mongodb:mongodb /var/run/mongodb /data/db /var/log/mongodb
# Start MongoDB (first without --fork to see errors)
echo "Starting MongoDB..."
gosu mongodb mongod --dbpath $MONGODB_DATA_DIR --logpath $MONGODB_LOG_DIR/mongodb.log &
MONGO_PID=$!
# Wait for MongoDB to be ready
echo "Waiting for MongoDB to start..."
until gosu mongodb mongo --eval "print(\"waited for connection\")" > /dev/null 2>&1; do
sleep 0.5
if ! kill -0 $MONGO_PID 2>/dev/null; then
echo "MongoDB failed to start. Checking logs:"
cat $MONGODB_LOG_DIR/mongodb.log
exit 1
fi
done
echo "MongoDB has started"
# Start nginx
echo "Starting nginx..."
nginx
# Change to app directory and ensure permissions
cd /app
chown -R www-data:www-data /var/log/nginx /var/lib/nginx
chown -R node:node /app
# Start the SSH service
echo "Starting SSH service..."
gosu node node src/backend/ssh.cjs &
# Start the database service
echo "Starting database service..."
gosu node node src/backend/database.cjs &
# Keep the container running and show MongoDB logs
echo "All services started. Tailing MongoDB logs..."
tail -f $MONGODB_LOG_DIR/mongodb.log
# Start all services using supervisor
exec /usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf

47
docker/supervisord.conf Normal file
View File

@@ -0,0 +1,47 @@
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:mongodb]
command=/usr/bin/mongod --dbpath /data/db --logpath /var/log/mongodb/mongodb.log
user=mongodb
autostart=true
autorestart=true
startsecs=10
startretries=3
stdout_logfile=/var/log/supervisor/mongodb.stdout.log
stderr_logfile=/var/log/supervisor/mongodb.stderr.log
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
user=root
autostart=true
autorestart=true
startsecs=5
startretries=3
stdout_logfile=/var/log/supervisor/nginx.stdout.log
stderr_logfile=/var/log/supervisor/nginx.stderr.log
[program:ssh-service]
command=/usr/bin/node /app/src/backend/ssh.cjs
user=node
directory=/app
autostart=true
autorestart=true
startsecs=10
startretries=3
stdout_logfile=/var/log/supervisor/ssh.stdout.log
stderr_logfile=/var/log/supervisor/ssh.stderr.log
[program:database-service]
command=/usr/bin/node /app/src/backend/database.cjs
user=node
directory=/app
autostart=true
autorestart=true
startsecs=10
startretries=3
stdout_logfile=/var/log/supervisor/database.stdout.log
stderr_logfile=/var/log/supervisor/database.stderr.log