Merge pull request 'Adding script to make it easier to create local development' (#1) from add-script into trunk

Reviewed-on: #1
This commit is contained in:
jknapp 2024-01-30 21:36:02 +00:00
commit 6d966d388f

64
local-dev.sh Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env bash
name=''
http_port='80'
https_port='443'
root_path="$(pwd)"
verbose='false'
while getopts 'n:p:s:r:vh' flag; do
case "${flag}" in
n) name="${OPTARG}" ;;
p) http_port="${OPTARG}" ;;
s) https_port="${OPTARG}" ;;
r) root_path="${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 and database, defaults to current working path"
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
echo "Building Docker Image..."
user=$(whoami)
uid=$(id -u)
if [ ! -d "$root_path/db" ]; then
mkdir -p "$root_path/db";
fi
if [ ! -d "$root_path/web" ]; then
mkdir -p "$root_path/web";
fi
$check_docker run -d -p "$http_port":80 -p "$https_port":443 -e PHPVER=82 -e environment=DEV --mount type=bind,source="$root_path"/web,target=/home/"$user"/public_html --mount type=bind,source="$root_path"/db,target=/var/lib/mysql -e uid="$uid" -e user="$user" -e domain="$name-local.dev" --name "$name" public.ecr.aws/s1f6k4w4/cac
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 exec $name bash -c 'tail -f /etc/httpd/logs/*'" >> "$root_path/instance_logs"
echo "#!/usr/bin/env bash" > "$root_path/instance_db_info"
echo "docker exec $name cat /var/lib/mysql/creds" >> "$root_path/instance_db_info"
chmod +x $root_path/instance_*
echo "Waiting 120 seconds for setup to finish"
sleep 120;
echo "Installing WordPress..."
docker exec $name bash -c "cd /home/$(whoami)/public_html; wp core download; chown -R $(whoami) /home/$(whoami)/public_html"
echo "Local Development Instance Created, to stop run ./instance_stop from within the base directory"
echo "MySQL DB Credentials"
docker exec $name cat /var/lib/mysql/creds
exit 0