Complete Node.js container implementation with multi-version support
- Add Dockerfile with AlmaLinux 9 base, Nginx reverse proxy, and PM2
- Support Node.js versions 18, 20, 22 with automated installation
- Implement memory-optimized configuration (256MB minimum, 512MB recommended)
- Add Memcached session storage for development environments
- Create comprehensive documentation (README, USER-GUIDE, MEMORY-GUIDE, CLAUDE.md)
- Include example applications (simple website and REST API)
- Add Gitea CI/CD pipeline for automated multi-version builds
- Provide local development script with helper utilities
- Implement health monitoring, log rotation, and backup systems
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-21 16:00:46 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
if [ -z "$NODEVER" ]; then
|
|
|
|
|
NODEVER="20";
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "$environment" ]; then
|
|
|
|
|
environment="PROD"
|
|
|
|
|
fi
|
|
|
|
|
|
2025-07-24 09:22:43 -07:00
|
|
|
# Create user with proper error handling
|
|
|
|
|
if ! id -u $user >/dev/null 2>&1; then
|
|
|
|
|
echo "Creating user $user with UID $uid"
|
|
|
|
|
adduser -u $uid -m -s /bin/bash $user || {
|
|
|
|
|
echo "Failed to create user $user with UID $uid"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
echo "User $user already exists"
|
|
|
|
|
fi
|
Complete Node.js container implementation with multi-version support
- Add Dockerfile with AlmaLinux 9 base, Nginx reverse proxy, and PM2
- Support Node.js versions 18, 20, 22 with automated installation
- Implement memory-optimized configuration (256MB minimum, 512MB recommended)
- Add Memcached session storage for development environments
- Create comprehensive documentation (README, USER-GUIDE, MEMORY-GUIDE, CLAUDE.md)
- Include example applications (simple website and REST API)
- Add Gitea CI/CD pipeline for automated multi-version builds
- Provide local development script with helper utilities
- Implement health monitoring, log rotation, and backup systems
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-21 16:00:46 -07:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2025-07-24 09:01:08 -07:00
|
|
|
# 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
|
Complete Node.js container implementation with multi-version support
- Add Dockerfile with AlmaLinux 9 base, Nginx reverse proxy, and PM2
- Support Node.js versions 18, 20, 22 with automated installation
- Implement memory-optimized configuration (256MB minimum, 512MB recommended)
- Add Memcached session storage for development environments
- Create comprehensive documentation (README, USER-GUIDE, MEMORY-GUIDE, CLAUDE.md)
- Include example applications (simple website and REST API)
- Add Gitea CI/CD pipeline for automated multi-version builds
- Provide local development script with helper utilities
- Implement health monitoring, log rotation, and backup systems
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-21 16:00:46 -07:00
|
|
|
fi
|
|
|
|
|
|
2025-07-24 09:01:08 -07:00
|
|
|
# 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
|
2025-07-24 09:22:43 -07:00
|
|
|
|
|
|
|
|
# Verify user exists and show info
|
|
|
|
|
echo "Verifying user setup:"
|
|
|
|
|
id $user || { echo "ERROR: User $user does not exist!"; exit 1; }
|
|
|
|
|
|
|
|
|
|
# Install dependencies as the user
|
|
|
|
|
echo "Installing npm dependencies as user $user..."
|
2025-07-24 09:01:08 -07:00
|
|
|
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"
|
2025-07-24 09:22:43 -07:00
|
|
|
chown $user:$user /home/$user/app/ecosystem.config.js
|
2025-07-24 09:01:08 -07:00
|
|
|
fi
|
|
|
|
|
|
2026-05-05 06:59:52 -07:00
|
|
|
# Mirror logs to docker logs in the background.
|
|
|
|
|
# Use -F (capital) so logrotate-recreated files keep streaming.
|
|
|
|
|
tail -F /home/$user/logs/nginx/access.log \
|
|
|
|
|
/home/$user/logs/nginx/error.log \
|
|
|
|
|
/home/$user/logs/nodejs/app.log \
|
|
|
|
|
/home/$user/logs/nodejs/out.log \
|
|
|
|
|
/home/$user/logs/nodejs/error.log 2>/dev/null &
|
|
|
|
|
|
|
|
|
|
# Start PM2 under tini so it becomes PID 1 (with proper signal forwarding
|
|
|
|
|
# and zombie reaping for nginx/crond/memcached children that reparent here).
|
|
|
|
|
# When pm2 exits (e.g. max_restarts exhausted), tini exits and Docker's
|
|
|
|
|
# restart policy brings the container back.
|
|
|
|
|
echo "Starting PM2 as user $user (under tini as PID 1)..."
|
2025-07-24 09:53:01 -07:00
|
|
|
cd /home/$user/app
|
2026-05-05 06:59:52 -07:00
|
|
|
exec tini -- su - $user -c "cd /home/$user/app && NODE_ENV=production pm2 start ecosystem.config.js --no-daemon"
|