Files
cloud-node-container/local-dev.sh
jknapp f8edb2b407
All checks were successful
Cloud Node Container / Build-and-Push (18) (push) Successful in 51s
Cloud Node Container / Build-and-Push (20) (push) Successful in 51s
Cloud Node Container / Build-and-Push (22) (push) Successful in 53s
Change container name from cnc to cnoc to avoid nginx container conflict
- Update Gitea pipeline to build cnoc:node18, cnoc:node20, cnoc:node22
- Update local-dev.sh to use cnoc container from registry
- Update documentation references from CNC to CNOC
- Update default app package name to cnoc-default-app
- Avoid conflict with existing nginx container (cnc)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-21 16:17:16 -07:00

95 lines
3.3 KiB
Bash
Executable File

#!/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" repo.anhonesthost.net/cloud-hosting-platform/cnoc: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