diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..f5dd4b8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,80 @@ +FROM php:8.4-apache + +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" +# set php memory limit to -1 +RUN sed -i 's/memory_limit = .*/memory_limit = -1/' $PHP_INI_DIR/php.ini +# Enable .htaccess files & mod_rewrite +RUN sed -i '//,/<\/Directory>/ s/AllowOverride None/AllowOverride all/' /etc/apache2/apache2.conf +RUN a2enmod rewrite + +#Most of this comes directly from the WordPress docker image +#We don't inherit from it becase it has a VOLUME that causes issues +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends ghostscript git less ssh-client mariadb-client; \ + rm -rf /var/lib/apt/lists/* + +# install the PHP extensions, including XDebug +RUN set -ex; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libfreetype6-dev \ + libjpeg-dev \ + libmagickwand-dev \ + libpng-dev \ + libzip-dev \ + ; \ + docker-php-ext-configure gd --with-freetype --with-jpeg; \ + docker-php-ext-install -j "$(nproc)" \ + bcmath \ + exif \ + gd \ + mysqli \ + opcache \ + zip \ + ; \ + pecl install imagick-3.8.0; \ + pecl install xdebug-3.4.3; \ + pear install PHP_CodeSniffer; \ + docker-php-ext-enable imagick xdebug;\ + rm -rf /var/lib/apt/lists/* + +#XDebug settings +RUN echo "[XDebug]\nxdebug.mode = debug\nxdebug.start_with_request = 1" > $PHP_INI_DIR/conf.d/xdebug.ini + +#WP recommended PHP settings +RUN { \ + echo 'opcache.memory_consumption=128'; \ + echo 'opcache.interned_strings_buffer=8'; \ + echo 'opcache.max_accelerated_files=4000'; \ + echo 'opcache.revalidate_freq=2'; \ + echo 'opcache.fast_shutdown=1'; \ +} > /usr/local/etc/php/conf.d/opcache-recommended.ini + +#install WP-CLI +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 + +#install Composer +WORKDIR /tmp +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ + && php composer-setup.php --quiet --install-dir=/usr/local/bin --filename=composer + +#add vscode user +RUN useradd -ms /bin/bash vscode \ + && usermod -aG www-data vscode + +WORKDIR /var/www/html +USER www-data + +#Download WP +RUN wp core download + +#add dirs for plugin and theme dev +RUN mkdir -p /var/www/html/wp-content/plugins/imagekit + +USER root +RUN chown -R www-data:www-data /var/www/html/ +RUN chmod g+w -R /var/www/html/ +RUN find /var/www/html/ -type d -exec chmod g+s {} \; \ No newline at end of file diff --git a/.devcontainer/data/plugins/.keep b/.devcontainer/data/plugins/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..b33d110 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "WordPress", + "dockerComposeFile": "docker-compose.yml", + "service": "wordpress", + "workspaceFolder": "/var/www/html/wp-content/plugins/imagekit", + "customizations": { + "vscode": { + "extensions": ["felixfbecker.php-pack", "wordpresstoolbox.wordpress-toolbox", "johnbillion.vscode-wordpress-hooks"], + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "php.suggest.basic": false + } + } + }, + "postCreateCommand": ".devcontainer/wp-setup.sh", + "remoteUser": "vscode" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..f6e2683 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3' +services: + wordpress: + build: ./ + ports: + - 8080:80 + depends_on: + - db + environment: + WORDPRESS_DB_HOST: db + WORDPRESS_DB_USER: wp_user + WORDPRESS_DB_PASSWORD: wp_pass + WORDPRESS_DB_NAME: wordpress + WORDPRESS_DEBUG: 1 + links: + - db + volumes: + #Swap the folder path for plugin vs theme development + - wordpress:/var/www/html + - ../:/var/www/html/wp-content/plugins/imagekit + - ./.idea:/var/www/html/wp-content/plugins/imagekit/.idea + #- ../:/var/www/html/wp-content/themes/theme-dev + + db: + image: mariadb:11.4 + environment: + MYSQL_DATABASE: wordpress + MYSQL_USER: wp_user + MYSQL_PASSWORD: wp_pass + MYSQL_RANDOM_ROOT_PASSWORD: '1' + ports: + - 3306:3306 + volumes: + - data:/var/lib/mysql + +volumes: + wordpress: + data: \ No newline at end of file diff --git a/.devcontainer/wp-setup.sh b/.devcontainer/wp-setup.sh new file mode 100755 index 0000000..7e01a79 --- /dev/null +++ b/.devcontainer/wp-setup.sh @@ -0,0 +1,45 @@ +#! /bin/bash + +#Site configuration options +SITE_TITLE="Dev Site" +ADMIN_USER=admin +ADMIN_PASS=password +ADMIN_EMAIL="admin@localhost.com" +#Space-separated list of plugin ID's to install and activate +PLUGINS="" + +#Set to true to wipe out and reset your wordpress install (on next container rebuild) +WP_RESET=true + +echo "Setting up WordPress" +DEVDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd /var/www/html; +if $WP_RESET ; then + echo "Resetting WP" + wp plugin delete $PLUGINS + wp db reset --yes + rm wp-config.php; +fi + +if [ ! -f wp-config.php ]; then + echo "Configuring"; + wp config create --dbhost="db" --dbname="wordpress" --dbuser="wp_user" --dbpass="wp_pass" --skip-check; + wp core install --url="http://localhost:8080" --title="$SITE_TITLE" --admin_user="$ADMIN_USER" --admin_email="$ADMIN_EMAIL" --admin_password="$ADMIN_PASS" --skip-email; + wp plugin install $PLUGINS --activate + #TODO: Only activate plugin if it contains files - i.e. might be developing a theme instead + wp plugin activate plugin-dev + + #Data import + cd $DEVDIR/data/ + for f in *.sql; do + wp db import $f + done + + cp -r plugins/* /var/www/html/wp-content/plugins + for p in plugins/*; do + wp plugin activate $(basename $p) + done + +else + echo "Already configured" +fi \ No newline at end of file