Skip to content

Commit

Permalink
feat: purge, reset, and ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
aanduque committed May 21, 2022
1 parent 3f3b230 commit 14171cd
Show file tree
Hide file tree
Showing 20 changed files with 1,178 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.env
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@ Caesar installs and activated Query Monitor by default, and installs Debug Bar S

## Changelog

#### Version 0.0.6 - 2022-05-21

* Feature: reset command;
* Feature: purge command;
* Feature: ssh command;
* Fixes: Several minor.

#### Version 0.0.5 - 2022-05-20
* Feature: adds the `purge` command to remove all inactive containers;
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ networks:
name: caesar_supervisor
caesar_site:
external: true
name: caesar_${SLUG}
name: caesar_site_${SLUG}

services:
# ---------------
Expand Down
16 changes: 4 additions & 12 deletions images/wordpress/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
FROM wordpress:latest

RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

RUN chmod +x wp-cli.phar

RUN mv wp-cli.phar /usr/local/bin/wp
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp

RUN yes | pecl install xdebug

COPY xdebug.ini /usr/local/etc/php/conf.d

COPY htaccess-single /usr/src/wordpress/.htaccess-single

COPY htaccess-subdir /usr/src/wordpress/.htaccess-subdir

COPY htaccess-subdomain /usr/src/wordpress/.htaccess-subdomain
COPY . .
50 changes: 50 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"bin": "caesar",
"scripts": {
"build:wordpress": "docker build --rm -t nextpress/caesar-wordpress:${npm_package_version} -t nextpress/caesar-wordpress:latest ./images/wordpress",
"build:wp": "docker build --rm -t nextpress/caesar-wp:${npm_package_version} -t nextpress/caesar-wp:latest ./images/wp && docker run -d --name apache -p 8080:80 -p 4443:443 nextpress/caesar-wp",
"build:cert": "docker build --rm -t nextpress/caesar-cert:${npm_package_version} -t nextpress/caesar-cert:latest ./images/cert",
"push:wordpress": "docker push nextpress/caesar-wordpress",
"build:mkcert": "docker build --rm -t nextpress/caesar-mkcert:${npm_package_version} -t nextpress/caesar-mkcert:latest ./images/mkcert",
"push:mkcert": "docker push nextpress/caesar-mkcert",
Expand All @@ -28,10 +30,12 @@
},
"homepage": "https://github.com/next-press/caesar#readme",
"dependencies": {
"boxt": "^1.1.2",
"cli-welcome": "^2.2.2",
"commander": "^9.2.0",
"figlet": "^1.5.2",
"lodash": "^4.17.21",
"pad": "^3.2.0",
"random-words": "^1.1.2",
"slugify": "^1.6.5"
}
Expand Down
25 changes: 24 additions & 1 deletion scripts/container/install-wp.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
#!/usr/bin/env bash

function tap_wp_config {

if [ "$INSTALL_TYPE" == "single" ]; then
return
fi

cat wp-config.php | grep

if [ "$INSTALL_TYPE" == "subdomain" ]; then

pwd;

elif [ "$INSTALL_TYPE" == "subdomain" ]; then

pwd

fi

}

{

if wp core is-installed --allow-root &> /dev/null; then
exit

wp config set

fi

while :
Expand Down
14 changes: 11 additions & 3 deletions scripts/host/caesar-down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ else
. "${CWD_PATH}/.env" > /dev/null 2>&1
fi

SLUG=$(${LIB_PATH}/scripts/lib/slugify $SLUG 2> /dev/null)

if [ "$SLUG" == "shutdown" ]; then

start_spinner "Shutting containers for all sites..."
Expand All @@ -25,9 +27,15 @@ elif [ "$SLUG" == "purge" ]; then

start_spinner "Removing all Caesar containers not active at the moment."

docker container stop $(docker container ls -q --filter "status=exited" --filter "name=$SLUG") > /dev/null 2>&1
docker container rm $(docker container ls -q --filter "status=exited" --filter "name=$SLUG") > /dev/null 2>&1
docker container stop $(docker container ls -q --filter "status=exited" --filter "name=caesar") > /dev/null 2>&1
docker container rm $(docker container ls -q --filter "status=exited" --filter "name=caesar") > /dev/null 2>&1

stop_spinner 0

start_spinner "Prune unsed networks..."

docker network rm $(docker network ls -q --filter "name=caesar_site") &> /dev/null 2>&1

stop_spinner 0

pd "See you later!"
Expand All @@ -36,7 +44,7 @@ else

start_spinner "Shutting containers for site $SLUG down..."

docker container stop $(docker container ls -q --all --filter "name=$SLUG") > /dev/null 2>&1
docker container stop $(docker container ls -q --all --filter "name=$SLUG") &> /dev/null 2>&1
# docker container kill $(docker container ls -q --all --filter "name=$SLUG") > /dev/null 2>&1
# docker container rm $(docker container ls -q --all --filter "name=$SLUG") > /dev/null 2>&1

Expand Down
12 changes: 11 additions & 1 deletion scripts/host/caesar-init
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ NAME=$1

DOMAIN_NAME=$2

mkdir "$NAME"
mkdir "$NAME" 2> /dev/null

if [ $? -eq 1 ]; then

pdns "Unable to create the target directory '$1'..."

echo ""

exit 1;

fi

cd "$NAME";

Expand Down
30 changes: 25 additions & 5 deletions scripts/host/caesar-reset
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ fi

if ! [ -n "$SLUG" ]; then

pd "This needs to be run inside a project folder, or by passing the project slug as a parameter."
pdns "This needs to be run inside a project folder, or by passing the project slug as a parameter."

fi

SLUG=$(${LIB_PATH}/scripts/lib/slugify $SLUG)

if ! [ docker container ls | grep "$SLUG" &> /dev/null ]; then
if ! docker container ls | grep "$SLUG" &> /dev/null; then

pd "To reset a site container, it needs to be running first."
pdns "To reset a site container, it needs to be running first."

echo ""

exit;

fi

Expand All @@ -36,10 +40,26 @@ start_spinner "Reseting containers..."
docker container rm "caesar-$SLUG-wordpress"
docker container rm "caesar-$SLUG-db"
docker container rm "caesar-$SLUG-cert"

echo "INSTALLED=1" >> $CWD_PATH/.env
} &> /dev/null

stop_spinner 0

pd "Go to the project directory and run \`caesar up\` to re-build the environment."
cat "$CWD_PATH/.env" | grep -q "SLUG=$SLUG"

if [ $? -ne 0 ]; then

pd "Go to the project directory and run \`caesar up\` to re-build the environment."

echo ""

exit

fi

pd "Since we are already inside the target project, let's spin it up..."

sleep 2

exit
caesar up
24 changes: 24 additions & 0 deletions scripts/host/caesar-restart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# set -x

. ${LIB_PATH}/scripts/lib/func.sh

start_spinner "Taking it down...";

caesar down $1 &> /dev/null

DOWN=$?

stop_spinner $DOWN

if [ $DOWN -eq 0 ]; then

caesar up $1

else

pd "Unable to take containers down... You will need to do it by hand first."

exit 1;

fi
28 changes: 28 additions & 0 deletions scripts/host/caesar-ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# set -x

. ${LIB_PATH}/scripts/lib/func.sh

if [ -n "$1" ]; then
SLUG=$1
else
. "${CWD_PATH}/.env" > /dev/null 2>&1
fi

SLUG=$(${LIB_PATH}/scripts/lib/slugify $SLUG 2> /dev/null)

CONTAINER=${2:-wordpress}

pdns "Entering container ${CONTAINER} for ${SLUG}... (type 'exit' to return to the main shell)"

echo ""

let column=$(tput cols)

# printf "%${column}s"
printf "%0.s-" $(seq 1 $column)

echo ""
echo ""

docker exec -it "caesar-${SLUG}-${CONTAINER}" sh
Loading

0 comments on commit 14171cd

Please sign in to comment.