diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..e2f065ef --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,36 @@ +FROM wordpress + +# Allow devcontainer/Codespace use www-data as the remote user instead of root. +RUN usermod --shell /bin/bash www-data +RUN touch /var/www/.bashrc +RUN chown -R www-data: /var/www/ + +# Install git & zip +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y git && \ + apt-get install -y sudo && \ + apt-get install -y zip + +# Install Xdebug +RUN pecl install "xdebug" || true \ + && docker-php-ext-enable xdebug +RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN apachectl restart + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +# 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 nvm and node +RUN su www-data -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash' +RUN su www-data -c 'export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && nvm install --lts' + +# Allow www-data user to use sudo without password +RUN adduser www-data sudo +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..52620f4c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,11 @@ +{ + "name": "${localWorkspaceFolderBasename}", + "dockerComposeFile": "docker-compose.yml", + "service": "wordpress", + "forwardPorts": [ 8080 ], + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ "xdebug.php-debug" ], + "workspaceFolder": "/var/www/html/", + "postCreateCommand": "/var/www/html/wp-content/plugins/${localWorkspaceFolderBasename}/.devcontainer/setup.sh", + "remoteUser": "www-data" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..63961e72 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.1' + +services: + + wordpress: + build: . + restart: always + ports: + - 8080:80 + environment: + WORDPRESS_DB_HOST: db + WORDPRESS_DB_USER: exampleuser + WORDPRESS_DB_PASSWORD: examplepass + WORDPRESS_DB_NAME: exampledb + volumes: + - wordpress:/var/www/html + - "../:/var/www/html/wp-content/plugins/simple-podcasting" + + db: + image: mariadb + restart: always + environment: + MYSQL_DATABASE: exampledb + MYSQL_USER: exampleuser + MYSQL_PASSWORD: examplepass + MYSQL_RANDOM_ROOT_PASSWORD: '1' + volumes: + - db:/var/lib/mysql + +volumes: + wordpress: + db: diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100755 index 00000000..fac8dbe6 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,46 @@ +#! /bin/bash +CURRENT_WORKING_DIR="$(pwd)" +PROJECT_DIR="$(dirname "$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" )" +SLUG="$(basename "$PROJECT_DIR")" +PROJECT_TYPE=plugin +if [ -f "$PROJECT_DIR/style.css" ]; then + PROJECT_TYPE=theme +fi + +if [[ ! -z "$CODESPACE_NAME" ]] +then + SITE_HOST="https://${CODESPACE_NAME}-8080.githubpreview.dev" +else + SITE_HOST="http://localhost:8080" +fi + +exec 3>&1 4>&2 +trap 'exec 2>&4 1>&3' 0 1 2 3 +exec 1>setup.log 2>&1 + +# Prepare a nice name from project name for the site title. +function getTitleFromSlug() +{ + local _slug=${SLUG//-/ } + local __slug=${_slug//_/ } + local ___slug=( $__slug ) + echo "${___slug[@]^}" +} + +source ~/.bashrc + +# Install dependencies +cd /var/www/html/wp-content/${PROJECT_TYPE}s/${SLUG}/ +npm i && npm run build +composer i + +# Install WordPress and activate the plugin/theme. +cd /var/www/html/ +echo "Setting up WordPress at $SITE_HOST" +wp db reset --yes +wp core install --url="$SITE_HOST" --title="$(getTitleFromSlug) Development" --admin_user="admin" --admin_email="admin@example.com" --admin_password="password" --skip-email + +echo "Activate $SLUG" +wp $PROJECT_TYPE activate $SLUG + +exit 0 diff --git a/.gitignore b/.gitignore index a4267151..5a869e56 100755 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,9 @@ Session.vim Thumbs.db Desktop.ini +.env +setup.log + # E2E testing .wp-env.override.json artifacts