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>
This commit is contained in:
95
local-dev.sh
Executable file
95
local-dev.sh
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env bash
|
||||
name=''
|
||||
http_port='80'
|
||||
https_port='443'
|
||||
root_path="$(pwd)"
|
||||
verbose='false'
|
||||
|
||||
while getopts 'n:p:s:r:a:vh' flag; do
|
||||
case "${flag}" in
|
||||
n) name="${OPTARG}" ;;
|
||||
p) http_port="${OPTARG}" ;;
|
||||
s) https_port="${OPTARG}" ;;
|
||||
r) root_path="${OPTARG}" ;;
|
||||
a) nodever="${OPTARG}" ;;
|
||||
v) verbose='true' ;;
|
||||
h) echo "Variables"
|
||||
echo "-n = Name of Container, Required"
|
||||
echo "-p = Non-https Port Override, default 80"
|
||||
echo "-s = Https Port Override, default 443"
|
||||
echo "-r = Root Path for files, defaults to current working path"
|
||||
echo "-a = Node.js Version, Default to 20 (options: 18, 20, 22)"
|
||||
echo "-v = Enable Verbose Mode"
|
||||
exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if Docker is installed
|
||||
echo "Checking if Docker is Installed..."
|
||||
check_docker=$(command -v docker)
|
||||
if [ $? != 0 ]; then
|
||||
echo "Docker must be installed to run this application"
|
||||
exit 1
|
||||
fi
|
||||
echo "Docker looks to be installed"
|
||||
|
||||
if [ -z "$name" ]; then
|
||||
echo "Name not set, please set it with -n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$nodever" ]; then
|
||||
nodever=20;
|
||||
fi
|
||||
|
||||
echo "Building Docker Image..."
|
||||
user=$(whoami)
|
||||
uid=$(id -u)
|
||||
if [ ! -d "$root_path/user" ]; then
|
||||
mkdir -p "$root_path/user";
|
||||
mkdir -p "$root_path/user/logs/{nginx,nodejs}";
|
||||
mkdir -p "$root_path/user/app";
|
||||
fi
|
||||
|
||||
# Create default Node.js app if it doesn't exist
|
||||
if [ ! -f "$root_path/user/app/package.json" ]; then
|
||||
echo "Creating default Node.js application..."
|
||||
cp configs/package.json "$root_path/user/app/"
|
||||
cp configs/index.js "$root_path/user/app/"
|
||||
cp configs/ecosystem.config.js "$root_path/user/app/"
|
||||
# Update ecosystem config with correct user path
|
||||
sed -i "s/\/home\/myuser/\/home\/$user/g" "$root_path/user/app/ecosystem.config.js"
|
||||
fi
|
||||
|
||||
$check_docker run --pull=always -d -p "$http_port":80 -p "$https_port":443 -e NODEVER=$nodever -e environment=DEV --mount type=bind,source="$root_path"/user,target=/home/"$user" --mount type=bind,source="$(pwd)"/user/logs/nginx,target=/var/log/nginx --mount type=bind,source="$(pwd)"/user/logs/nodejs,target=/var/log/nodejs -e uid="$uid" -e user="$user" -e domain="$name-local.dev" --name "$name" cloud-node-container:latest
|
||||
|
||||
echo "Creating management scripts in root directory..."
|
||||
echo "#!/usr/bin/env bash" > "$root_path/instance_start"
|
||||
echo "docker start $name" >> "$root_path/instance_start"
|
||||
echo "#!/usr/bin/env bash" > "$root_path/instance_stop"
|
||||
echo "docker stop $name" >> "$root_path/instance_stop"
|
||||
echo "#!/usr/bin/env bash" > "$root_path/instance_logs"
|
||||
echo "docker logs -f $name" >> "$root_path/instance_logs"
|
||||
echo "#!/usr/bin/env bash" > "$root_path/instance_shell"
|
||||
echo "docker exec -it $name /bin/bash" >> "$root_path/instance_shell"
|
||||
chmod +x $root_path/instance_*
|
||||
|
||||
echo "Waiting 30 seconds for setup to finish..."
|
||||
sleep 30
|
||||
|
||||
echo "Local Development Instance Created!"
|
||||
echo "- Container name: $name"
|
||||
echo "- HTTP port: $http_port"
|
||||
echo "- HTTPS port: $https_port"
|
||||
echo "- Node.js version: $nodever"
|
||||
echo ""
|
||||
echo "Management scripts created:"
|
||||
echo " ./instance_start - Start the container"
|
||||
echo " ./instance_stop - Stop the container"
|
||||
echo " ./instance_logs - View container logs"
|
||||
echo " ./instance_shell - Access container shell"
|
||||
echo ""
|
||||
echo "Your application files are in: $root_path/user/app/"
|
||||
echo "Visit https://localhost:$https_port (accept SSL warning) to see your app"
|
||||
|
||||
exit 0
|
Reference in New Issue
Block a user