Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto cleanup of default wordpress themes, plugins, posts & pages & Multiple installation & activation of themes or plugins in local or wordpress repository #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ PHPMYADMIN_VERSION=latest
PHPMYADMIN_PORT=8080

# 6/ Volumes on host --------------------------------------------------
#-------------------- DEFAULT FOLDERS --------------------#
WORDPRESS_THEME_FOLDER="WordPressThemes"
WORDPRESS_THEME_PLUGIN_FOLDER="plugins"

#-------------------- WORDPRESS LOCAL, THEME & PLUGIN DIRECTORY --------------------#
WORDPRESS_DATA_DIR=./wordpress
WORDPRESS_THEME_LOCAL_DIR="~/${WORDPRESS_THEME_FOLDER}"
WORDPRESS_THEME_PLUGIN_LOCAL_DIR="~/${WORDPRESS_THEME_FOLDER}/${WORDPRESS_THEME_PLUGIN_FOLDER}"

#-------------------- CONTAINER ROOT DIRECTORY --------------------#
WORDPRESS_THEME_CONTAINER_ROOT_DIR="/${WORDPRESS_THEME_FOLDER}"
WORDPRESS_THEME_PLUGIN_CONTAINER_ROOT_DIR="/${WORDPRESS_THEME_FOLDER}/${WORDPRESS_THEME_PLUGIN_FOLDER}"

# 7/ Healthcheck availability of host services (mysql and woordpress server)
# Waiting time in second
Expand All @@ -43,3 +54,17 @@ WAIT_HOST_CONNECT_TIMEOUT=5
# 8/ Used only in online deployement --------------------------------------
WORDPRESS_WEBSITE_URL_WITHOUT_WWW=example.com
PHPMYADMIN_WEBSITE_URL_WITHOUT_HTTP=sql.example.com

# 9/ Wordpress Themes, Plugins, Posts & Pages --------------------------------------
# NOTE: Spaces are case sensitive here 1 space needed per theme or plugin for local or repo and .zip extension is needed for local theme & plugins.
#-------------------- THEMES & PLUGINS --------------------#
WORDPRESS_LOCAL_THEMES="unos.2.7.2.zip"
WORDPRESS_REPO_THEMES="sydney calliope newsberg"
WORDPRESS_LOCAL_PLUGINS="all-in-one-wp-migration.6.82.zip all-in-one-wp-migration-file-extension.zip carousel-slider.zip"
WORDPRESS_REPO_PLUGINS="contact-form-7"

#-------------------- DEFAULT THEMES, PLUGINS, POSTS & PAGES --------------------#
WORDPRESS_DEFAULT_THEMES="twentytwenty twentynineteen twentyseventeen twentysixteen"
WORDPRESS_DEFAULT_PLUGINS="hello akismet"
# Hello world! post & Sample & Privacy Policy page
WORDPRESS_DEFAULT_POSTS_PAGES="1 2 3"
11 changes: 5 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
version: '3.6'
version: "3.6"
services:

wordpress:
image: wordpress:${WORDPRESS_VERSION:-latest}
container_name: ${COMPOSE_PROJECT_NAME:-wordpress}
Expand All @@ -18,7 +17,7 @@ services:
- phpmyadmin
restart: always
ports:
- 80:80
- 80:80

mysql:
image: mariadb:${MARIADB_VERSION:-latest}
Expand Down Expand Up @@ -51,9 +50,11 @@ services:
container_name: ${COMPOSE_PROJECT_NAME}_wpcli
volumes:
- ${WORDPRESS_DATA_DIR:-./wordpress}:/var/www/html
- ${WORDPRESS_THEME_LOCAL_DIR}:${WORDPRESS_THEME_CONTAINER_ROOT_DIR}
- ${WORDPRESS_THEME_PLUGIN_LOCAL_DIR}:${WORDPRESS_THEME_PLUGIN_CONTAINER_ROOT_DIR}
working_dir: /var/www/html

# Check availability of essential services
# Check availability of essential services
healthcheck:
image: wpcli
build: ./wpcli/
Expand All @@ -66,5 +67,3 @@ services:
- WAIT_HOSTS_TIMEOUT=${WAIT_HOSTS_TIMEOUT:-300}
- WAIT_SLEEP_INTERVAL=${WAIT_SLEEP_INTERVAL:-30}
- WAIT_HOST_CONNECT_TIMEOUT=${WAIT_HOST_CONNECT_TIMEOUT:-30}


13 changes: 12 additions & 1 deletion wp-auto-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.6'
version: "3.6"
services:
# Wordpress auto configuration
# depends on wp-cli build
Expand All @@ -9,6 +9,8 @@ services:
entrypoint: sh -c "/wait && make -f /scripts/Makefile"
volumes:
- ${WORDPRESS_DATA_DIR:-./wordpress}:/var/www/html
- ${WORDPRESS_THEME_LOCAL_DIR}:${WORDPRESS_THEME_CONTAINER_ROOT_DIR}
- ${WORDPRESS_THEME_PLUGIN_LOCAL_DIR}:${WORDPRESS_THEME_PLUGIN_CONTAINER_ROOT_DIR}
working_dir: /var/www/html
depends_on:
- wordpress
Expand All @@ -34,3 +36,12 @@ services:
- WORDPRESS_ADMIN_USER=${WORDPRESS_ADMIN_USER:-wordpress}
- WORDPRESS_ADMIN_PASSWORD=${WORDPRESS_ADMIN_PASSWORD:-wordpress}
- WORDPRESS_ADMIN_EMAIL=${WORDPRESS_ADMIN_EMAIL:-"[email protected]"}
- WORDPRESS_LOCAL_THEMES=${WORDPRESS_LOCAL_THEMES}
- WORDPRESS_REPO_THEMES=${WORDPRESS_REPO_THEMES}
- WORDPRESS_DEFAULT_THEMES=${WORDPRESS_DEFAULT_THEMES}
- WORDPRESS_LOCAL_PLUGINS=${WORDPRESS_LOCAL_PLUGINS}
- WORDPRESS_REPO_PLUGINS=${WORDPRESS_REPO_PLUGINS}
- WORDPRESS_DEFAULT_PLUGINS=${WORDPRESS_DEFAULT_PLUGINS}
- WORDPRESS_DEFAULT_POSTS_PAGES=${WORDPRESS_DEFAULT_POSTS_PAGES}
- WORDPRESS_THEME_FOLDER=${WORDPRESS_THEME_FOLDER}
- WORDPRESS_THEME_PLUGIN_FOLDER=${WORDPRESS_THEME_PLUGIN_FOLDER}
73 changes: 72 additions & 1 deletion wpcli/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,85 @@

##############################
# CONDITIONAL STATEMENTS
##############################

####### THEMES & PLUGINS DIRECTORIES ######
# Assign home folders for theme & plugin
wpThemeDir = /${WORDPRESS_THEME_FOLDER}
wpPluginDir = $(wpThemeDir)/${WORDPRESS_THEME_PLUGIN_FOLDER}

####### CHECKING LOCAL & REPO THEMES ######
# Check if both local & repo theme variables are not empty
ifneq "$(and ${WORDPRESS_LOCAL_THEMES},${WORDPRESS_REPO_THEMES})" ""
# Loop all theme then assign it with the theme path diretory
localThemes := $(foreach theme,${WORDPRESS_LOCAL_THEMES},$(wpThemeDir)/$(theme))
# Combine all local & repo themes
wpThemes := $(localThemes) ${WORDPRESS_REPO_THEMES}

# Check if local theme is not empty
else ifneq ($(strip ${WORDPRESS_LOCAL_THEMES}),)
# Loop all themes then assign it with the theme path diretory
localThemes := $(foreach theme,${WORDPRESS_LOCAL_THEMES},$(wpThemeDir)/$(theme))
wpThemes := $(localThemes)

# Check if repo theme is not empty
else ifneq ($(strip ${WORDPRESS_REPO_THEMES}),)
wpThemes := ${WORDPRESS_REPO_THEMES}
endif

####### CHECKING LOCAL & REPO PLUGINS ######
# Check if both local & repo plugin variables are not empty
ifneq "$(and ${WORDPRESS_LOCAL_PLUGINS},${WORDPRESS_REPO_PLUGINS})" ""
# Loop all plugins then assign it with the plugin path diretory
localPlugins := $(foreach plugin,${WORDPRESS_LOCAL_PLUGINS},$(wpPluginDir)/$(plugin))
# Combine all local & repo plugins
wpPlugins := $(localPlugins) ${WORDPRESS_REPO_PLUGINS}

# Check if local plugin is not empty
else ifneq ($(strip ${WORDPRESS_LOCAL_PLUGINS}),)
# Loop all plugins then assign it with the plugin path diretory
localPlugins := $(foreach plugin,${WORDPRESS_LOCAL_PLUGINS},$(wpPluginDir)/$(plugin))
wpPlugins := $(localPlugins)

# Check if repo plugin is not empty
else ifneq ($(strip ${WORDPRESS_REPO_PLUGINS}),)
wpPlugins := ${WORDPRESS_REPO_PLUGINS}
endif

#################
# COMMANDS
#################
install: configure

configure:

@echo "⚙️ Configuring Wordpress parameters..."
wp core install \
--url=${WORDPRESS_WEBSITE_URL_WITHOUT_HTTP} \
--title=$(WORDPRESS_WEBSITE_TITLE) \
--title="${WORDPRESS_WEBSITE_TITLE}" \
--admin_user=${WORDPRESS_ADMIN_USER} \
--admin_password=${WORDPRESS_ADMIN_PASSWORD} \
--admin_email=${WORDPRESS_ADMIN_EMAIL}

@echo -e "\n⚙️ Update default site url..."
wp option update siteurl ${WORDPRESS_WEBSITE_URL}
wp rewrite structure $(WORDPRESS_WEBSITE_POST_URL_STRUCTURE)

ifdef wpThemes
@echo -e "\n⚙️ Install & activate themes ..."
-wp theme install --activate ${wpThemes}
endif

ifdef wpPlugins
@echo -e "\n⚙️ Install & activate plugins..."
-wp plugin install --activate $(wpPlugins)
endif

@echo -e "\n⚙️ Removing Wordpress default themes..."
-wp theme delete ${WORDPRESS_DEFAULT_THEMES}

@echo -e "\n⚙️ Removing Wordpress default plugins..."
-wp plugin delete ${WORDPRESS_DEFAULT_PLUGINS}

@echo -e "\n⚙️ Removing Wordpress default posts & pages..."
-wp post delete --force ${WORDPRESS_DEFAULT_POSTS_PAGES}