Skip to content

Commit

Permalink
Docker: Install plugin from current folder
Browse files Browse the repository at this point in the history
  • Loading branch information
HMKnapp committed Oct 5, 2021
1 parent 12c69e6 commit 0f51f7b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WORDPRESS_HOST=
NGROK_TOKEN=
PLUGIN_URL=https://github.com/qenta-cee/woocommerce-qcs.git
PLUGIN_VERSION=
WORDPRESS_HOST=
WORDPRESS_ADMIN_USER=
WORDPRESS_ADMIN_PASS=
WORDPRESS_ADMIN_EMAIL=
Expand Down
45 changes: 45 additions & 0 deletions docker-compose.persistent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
services:
wc_db:
image: mariadb:10.5
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${WORDPRESS_DB_ROOTPASS:-ABC123}
MYSQL_DATABASE: ${WORDPRESS_DB_NAME:-wordpress}
MYSQL_USER: ${WORDPRESS_DB_USER:-wordpress}
MYSQL_PASSWORD: ${WORDPRESS_DB_PASS:-wordpress}
volumes:
- ./data/wc_db:/var/lib/mysql
woocommerce:
container_name: woocommerce
build:
context: docker/wordpress/
dockerfile: Dockerfile
depends_on:
- wc_db
ports:
- ${PORT_HTTP:-8000}:80
- ${PORT_SSL:-8443}:443
volumes:
- ./:/tmp/plugin:ro
- ./data/woocommerce:/var/www/html
environment:
WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-wc_db}
WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress}
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wordpress}
WORDPRESS_DB_PASS: ${WORDPRESS_DB_PASS:-wordpress}
WORDPRESS_TABLE_PREFIX: "wp_"
WORDPRESS_DEBUG: 1
WORDPRESS_LOCALE: ${WORDPRESS_LOCALE:-en_US}
WORDPRESS_TITLE: ${WORDPRESS_TITLE:-QSHOP}
WORDPRESS_ADMIN_USER: ${WORDPRESS_ADMIN_USER:-admin}
WORDPRESS_ADMIN_PASS: ${WORDPRESS_ADMIN_PASS:-admin123}
WORDPRESS_ADMIN_EMAIL: ${WORDPRESS_ADMIN_EMAIL:[email protected]}
WORDPRESS_URL: ${WORDPRESS_HOST}
PLUGIN_VERSION: ${PLUGIN_VERSION}
PLUGIN_URL: ${PLUGIN_URL}
NGROK_TOKEN: ${NGROK_TOKEN}
GITHUB_SERVER_URL: ${GITHUB_SERVER_URL}
GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}
GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}
GITHUB_SHA: ${GITHUB_SHA}
GITHUB_REF: ${GITHUB_REF}
13 changes: 7 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
services:
wc_db:
image: mysql:5.7
image: mariadb:10.5
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${WORDPRESS_DB_ROOTPASS:-ABC123}
MYSQL_DATABASE: ${WORDPRESS_DB_NAME:-wordpress}
MYSQL_USER: ${WORDPRESS_DB_USER:-wordpress}
MYSQL_PASSWORD: ${WORDPRESS_DB_PASS:-wordpress}
# volumes:
# - ./data/wc_db:/var/lib/mysql
# volumes:
# - ./data/wc_db:/var/lib/mysql
woocommerce:
container_name: woocommerce
build:
Expand All @@ -19,8 +19,9 @@ services:
ports:
- ${PORT_HTTP:-8000}:80
- ${PORT_SSL:-8443}:443
# volumes:
# - ./data/woocommerce:/var/www/html
volumes:
- ./:/tmp/plugin:ro
# - ./data/woocommerce:/var/www/html
environment:
WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-wc_db}
WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress}
Expand All @@ -35,7 +36,7 @@ services:
WORDPRESS_ADMIN_EMAIL: ${WORDPRESS_ADMIN_EMAIL:[email protected]}
WORDPRESS_URL: ${WORDPRESS_HOST}
PLUGIN_VERSION: ${PLUGIN_VERSION}
PLUGIN_URL: ${PLUGIN_URL}
PLUGIN_URL: ${PLUGIN_URL:-local}
NGROK_TOKEN: ${NGROK_TOKEN}
GITHUB_SERVER_URL: ${GITHUB_SERVER_URL}
GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}
Expand Down
9 changes: 8 additions & 1 deletion docker/wordpress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,22 @@ COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN useradd -u 431 -r -g www-data -s /sbin/nologin -c "Wordpress user" wp
RUN mkdir -p /home/wp && chown -R wp:www-data /home/wp /etc/ssl
USER wp
WORKDIR /home/wp

WORKDIR /var/www/html
# install ngrok
COPY --from=ngrok/ngrok:debian /bin/ngrok /usr/bin/ngrok

# install WP-CLI and recommended packages
RUN composer global require wp-cli/wp-cli-bundle
RUN composer global require --dev $(composer suggests --by-package | awk '/wp-cli\/wp-cli-bundle/' RS= | grep -o -P '(?<=- ).*(?=:)')

RUN mkdir /tmp/wp-data
WORKDIR /tmp/wp-data

# download latest stable Wordpress
RUN wp core download

WORKDIR /var/www/html

EXPOSE 80
EXPOSE 443
5 changes: 5 additions & 0 deletions docker/wordpress/get_plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

REPO_WS=$(mktemp -d)

[[ ${PLUGIN_URL} == 'local' ]] && cp -r /tmp/plugin/* ${REPO_WS}/

# can be zip or repo url
PLUGIN_URL=${1}

Expand Down Expand Up @@ -39,6 +41,9 @@ if [[ ${PLUGIN_URL} == http*://*.zip ]]; then
curl -s ${PLUGIN_URL} > ${REPO_WS}/${ZIP_NAME}
PATH_TO_ZIP=${REPO_WS}/${ZIP_NAME}
PLUGIN_NAME=$(unzip -l ${PATH_TO_ZIP} | sed -n 's/.*\ \(.*\)\/$/\1/p' | head -n 1)
elif [[ ${PLUGIN_URL} == 'local' ]]; then
>&2 echo "Creating plugin zip from local folder"
create_package
else
>&2 echo "Creating plugin zip of ${PLUGIN_VERSION} from ${PLUGIN_URL}"
>&2 clone
Expand Down
22 changes: 15 additions & 7 deletions docker/wordpress/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ if [[ -z ${WORDPRESS_URL} && ! -e wp-config.php ]]; then
WORDPRESS_URL=$(ngrok.sh ${NGROK_TOKEN})
else
echo "No NGROK_TOKEN specified. Using localhost as URL"
WORDPRESS_URL=localhost
fi
fi

echo "Waiting for DB host ${WORDPRESS_DB_HOST}"

while ! mysqladmin ping -h"${WORDPRESS_DB_HOST}" --silent; do
sleep 1
sleep 10
done

function create_db() {
Expand All @@ -37,8 +38,6 @@ function create_db() {
}

function install_core() {
echo "Installing Wordpress"

wp core install \
--url=${WORDPRESS_URL} \
--title=${WORDPRESS_TITLE} \
Expand All @@ -49,14 +48,21 @@ function install_core() {
}

function install_woocommerce() {
echo "Installing WooCommerce"
wp plugin install woocommerce --activate

echo "Install Sample Data"
wp plugin install wordpress-importer --activate
wp import wp-content/plugins/woocommerce/sample-data/sample_products.xml --authors=create
}

function wp_set_array() {
option_name=${1}
option_key=${2}
option_value=${3}
#wp option get ${option_name} --format=json
#wp option get ${option_name} --format=json | php -r '$option = json_decode( fgets(STDIN) ); $option->'${option_key}' = '${option_value}'; print json_encode($option);' | wp option set ${option_name} --format=json
}

function install_plugin() {
STR_PLUGIN=$(get_plugin.sh ${PLUGIN_URL} ${PLUGIN_VERSION})
PLUGIN_NAME=$(echo ${STR_PLUGIN} | cut -d'^' -f1)
Expand All @@ -72,6 +78,7 @@ function setup_store() {
wp option set woocommerce_store_city "Graz"
wp option set woocommerce_store_postcode "8020"
wp option set woocommerce_default_country "AT"
wp_set_array woocommerce_onboarding_profile skipped 1
wp wc --user=admin tool run install_pages
}

Expand All @@ -80,7 +87,9 @@ function print_info() {
echo '####################################'
echo
echo "URL: https://${WORDPRESS_URL}"
echo "Shop: https://${WORDPRESS_URL}/?post_type=product"
echo "Panel: https://${WORDPRESS_URL}/wp-admin/"
echo "Plugin Config: https://${WORDPRESS_URL}/wp-admin/admin.php?page=wc-settings&tab=checkout"
echo "User: ${WORDPRESS_ADMIN_USER}"
echo "Password: ${WORDPRESS_ADMIN_PASS}"
echo
Expand All @@ -94,8 +103,9 @@ function _log() {

if [[ -e wp-config.php ]]; then
echo "Wordpress detected. Skipping installations"
WORDPRESS_URL=$(wp option get siteurl | sed 's/http:/https:/')
WORDPRESS_URL=$(wp option get siteurl | sed 's,^https\?://,,')
else
cp -r /tmp/wp-data/* /var/www/html/
create_db
_log "db created"
install_core
Expand All @@ -116,8 +126,6 @@ fi
_log "url=https://${WORDPRESS_URL}"
_log "ready"


echo "ready" > /tmp/debug.log
cat /tmp/debug.log

apache2-foreground "$@"
17 changes: 10 additions & 7 deletions docker/wordpress/ngrok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

set -e

NGROK_BINARY="./node_modules/ngrok/bin/ngrok"

if [[ ! -x ${NGROK_BINARY} ]]; then
which ngrok >/dev/null
if [[ $? == 0 ]]; then
NGROK_BINARY="$(which ngrok)"
else
>&2 echo "Installing NGROK"
npm install ngrok &>/dev/null
cd ~/
npm install ngrok
NGROK_BINARY="~/node_modules/ngrok/bin/ngrok"
fi

function get_ngrok_url() {
Expand All @@ -16,7 +19,7 @@ function get_ngrok_url() {
function wait_for_ngrok() {
while [[ -z ${RESPONSE} || ${RESPONSE} == 'null' ]]; do
RESPONSE=$(get_ngrok_url)
sleep 3;
sleep 1;
done
}

Expand All @@ -30,6 +33,6 @@ fi
${NGROK_BINARY} authtoken ${NGROK_TOKEN} >&/dev/null
${NGROK_BINARY} http https://localhost:443 >&/dev/null &
wait_for_ngrok
export NGROK_URL=$(get_ngrok_url)
export NGROK_HOST=$(sed 's,^https\?://,,' <<< ${NGROK_URL})
NGROK_URL=$(get_ngrok_url)
NGROK_HOST=$(sed 's,^https\?://,,' <<< ${NGROK_URL})
echo ${NGROK_HOST}

0 comments on commit 0f51f7b

Please sign in to comment.