Files
cloud-node-container/scripts/entrypoint.sh
jknapp 9f0aa4b8b1
Some checks failed
Cloud Node Container / Build-and-Push (18) (push) Failing after 38s
Cloud Node Container / Build-and-Push (20) (push) Failing after 33s
Cloud Node Container / Build-and-Push (22) (push) Failing after 33s
Implement auto-generation of ecosystem.config.js and improve container setup
- Add automatic ecosystem.config.js generation from package.json
- Create app directory automatically if missing
- Copy simple-website example when app directory is empty
- Remove redundant default app files from configs/
- Add HAProxy support with proper real IP forwarding
- Configure nginx to trust proxy headers from private networks
- Simplify entrypoint logic - always use /home/$user/app

This makes the container more user-friendly by eliminating the need for
manual PM2 configuration and ensuring the server always has a working app.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-24 09:01:08 -07:00

80 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
if [ -z "$NODEVER" ]; then
NODEVER="20";
fi
if [ -z "$environment" ]; then
environment="PROD"
fi
adduser -u $uid $user
mkdir -p /home/$user/app
mkdir -p /home/$user/logs/{nginx,nodejs}
# Link log directories
rm -rf /var/log/nginx
ln -s /home/$user/logs/nginx /var/log/nginx
ln -s /home/$user/logs/nodejs /var/log/nodejs
# Configure nginx for reverse proxy
/scripts/create-nginx-config.sh
# Set ownership and permissions
chown -R $user:$user /home/$user
chmod -R 755 /home/$user
# Start nginx
nginx
if [[ $environment == 'DEV' ]]; then
echo "Starting Dev Deployment"
# Ensure microdnf is available for installing additional packages in DEV mode
if ! command -v microdnf &> /dev/null; then
echo "microdnf not found, installing with dnf..."
dnf install -y microdnf && dnf clean all
fi
# Install Memcached for session storage in DEV mode with memory limit
microdnf install -y memcached
# Start memcached with 32MB memory limit
nohup memcached -d -u $user -p 11211 -m 32
fi
# Start cron for log rotation and backups
/usr/sbin/crond
# Create app directory if it doesn't exist
if [ ! -d /home/$user/app ]; then
echo "Creating app directory at /home/$user/app"
mkdir -p /home/$user/app
chown -R $user:$user /home/$user/app
fi
# If app directory is empty, copy the simple-website example
if [ -z "$(ls -A /home/$user/app)" ]; then
echo "App directory is empty, copying simple-website example..."
cp -r /examples/simple-website/* /home/$user/app/
chown -R $user:$user /home/$user/app
echo "Copied simple-website example to provide a working application"
fi
# Now there's always an app in the user directory (either user's or example)
cd /home/$user/app
su -c "npm install" $user
# Check if ecosystem.config.js exists, if not generate it
if [ ! -f /home/$user/app/ecosystem.config.js ]; then
echo "No ecosystem.config.js found, generating from package.json..."
/scripts/generate-ecosystem-config.sh "$user" "/home/$user/app"
fi
su -c "pm2 start ecosystem.config.js" $user
# Follow logs
tail -f /home/$user/logs/nginx/* /home/$user/logs/nodejs/*
exit 0