diff --git a/bin/local-env/Dockerfile b/bin/local-env/Dockerfile new file mode 100644 index 00000000000..a50aa06cfd3 --- /dev/null +++ b/bin/local-env/Dockerfile @@ -0,0 +1,8 @@ +FROM wordpress + +# 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 + +CMD ["apache2-foreground"] diff --git a/bin/local-env/docker-compose.yml b/bin/local-env/docker-compose.yml index 1e9751eb774..3b13bdf3ce5 100644 --- a/bin/local-env/docker-compose.yml +++ b/bin/local-env/docker-compose.yml @@ -1,8 +1,8 @@ -version: '3.1' - services: wordpress: - image: wordpress + build: + context: . + dockerfile: Dockerfile ports: - "127.0.0.1:8890:80" env_file: @@ -14,19 +14,6 @@ services: depends_on: - mysql - cli: - image: wordpress:cli - user: xfs - volumes: - - wordpress_data:/var/www/html - - ../../:/var/www/html/wp-content/plugins/amp - env_file: - - .env.wp - depends_on: - - mysql - - wordpress - command: tail -f /dev/null - mysql: image: mariadb:10 restart: always diff --git a/bin/local-env/includes.sh b/bin/local-env/includes.sh index 3fae71e19e5..2202d1987da 100755 --- a/bin/local-env/includes.sh +++ b/bin/local-env/includes.sh @@ -8,72 +8,6 @@ CONTAINER='wordpress' DATABASE='mysql' SITE_TITLE='AMP Dev' -## -# Ask a Yes/No question, and way for a reply. -# -# This is a general-purpose function to ask Yes/No questions in Bash, either with or without a default -# answer. It keeps repeating the question until it gets a valid answer. -# -# @param {string} prompt The question to ask the user. -# @param {string} [default] Optional. "Y" or "N", for the default option to use if none is entered. -# @param {int} [timeout] Optional. The number of seconds to wait before using the default option. -# -# @returns {bool} true if the user replies Yes, false if the user replies No. -## -ask() { - # Source: https://djm.me/ask - local timeout endtime timediff prompt default reply - - while true; do - - timeout="${3:-}" - - if [ "${2:-}" = "Y" ]; then - prompt="Y/n" - default=Y - elif [ "${2:-}" = "N" ]; then - prompt="y/N" - default=N - else - prompt="y/n" - default= - timeout= - fi - - if [ -z "$timeout" ]; then - # Ask the question (not using "read -p" as it uses stderr not stdout) - echo -en "$1 [$prompt] " - - # Read the answer (use /dev/tty in case stdin is redirected from somewhere else) - read reply /dev/null 2>&1 - mkdir -p /usr/local/bin - mv composer.phar /usr/local/bin/composer - echo ' done!' - else - echo -e $(error_message "") - echo -e $(error_message "Please install Composer manually, then re-run the setup script to continue.") - echo -e $(error_message "Composer installation instructions can be found here: $(action_format "https://getcomposer.org/doc/00-intro.md")") - fi - - exit 1 -fi - -# Check if the current Composer version is up to date. -if [ "$CI" != "true" ] && ! [[ "$(composer --version)" == "Composer version $COMPOSER_VERSION "* ]]; then - echo -en $(status_message "Updating Composer..." ) - composer self-update - echo ' done!' -fi - - -# Install/update packages -if [ "$CI" != "true" ]; then - echo -e $(status_message "Installing and updating Composer packages..." ) - composer install -fi diff --git a/bin/local-env/install-node-nvm.sh b/bin/local-env/install-node-nvm.sh deleted file mode 100755 index f3d64b9f5de..00000000000 --- a/bin/local-env/install-node-nvm.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash -NVM_VERSION=`curl -Ls -w %{url_effective} -o /dev/null https://github.com/nvm-sh/nvm/releases/latest | rev | cut -d '/' -f 1 | rev` -NODE_REQUIRED_VERSION=v$(<.nvmrc) - -# Exit if any command fails -set -e - -# Include useful functions -. "$(dirname "$0")/includes.sh" - -# Load NVM -if [ -n "$NVM_DIR" ]; then - # The --no-use option ensures loading NVM doesn't switch the current version. - if [ -f "$NVM_DIR/nvm.sh" ]; then - . "$NVM_DIR/nvm.sh" --no-use - elif command_exists "brew" && [ -f "$(brew --prefix nvm)/nvm.sh" ]; then - # use homebrew if that's how nvm was installed - . "$(brew --prefix nvm)/nvm.sh" --no-use - fi -fi - -# Change to the expected directory -cd "$(dirname "$0")/../.." - -# Check if nvm is installed -if [ "$CI" != "true" ] && ! command_exists "nvm"; then - if ask "$(error_message "NVM isn't installed, would you like to download and install it automatically?")" Y; then - # The .bash_profile file needs to exist for NVM to install - if [ ! -e ~/.bash_profile ]; then - touch ~/.bash_profile - fi - - echo -en $(status_message "Installing NVM..." ) - download "https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 - echo ' done!' - - echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) - echo -e $(warning_message "$(action_format ". \$HOME/.nvm/nvm.sh")" ) - echo -e $(warning_message "After that, re-run the setup script to continue." ) - else - echo -e $(error_message "") - echo -e $(error_message "Please install NVM manually, then re-run the setup script to continue.") - echo -e $(error_message "NVM installation instructions can be found here: $(action_format "https://github.com/nvm-sh/nvm")") - fi - - exit 1 -fi - -# Check if the current nvm version is up to date. -if [ "$CI" != "true" ] && [ $NVM_VERSION != "v$(nvm --version)" ]; then - echo -en $(status_message "Updating NVM..." ) - download "https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 - echo ' done!' - - echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) - echo -e $(warning_message "$(action_format ". \$HOME/.nvm/nvm.sh")" ) - echo -e $(warning_message "After that, re-run the setup script to continue." ) - exit 1 -fi - -# Check if the current node version is up to date. -if [ "$CI" != "true" ] && [ $(nvm current) =~ $NODE_REQUIRED_VERSION.* ]; then - echo -e $(warning_message "Node version does not match the latest long term support version. Please run this command to install and use it:" ) - echo -e $(warning_message "$(action_format "nvm install")" ) - echo -e $(warning_message "After that, re-run the setup script to continue." ) - exit 1 -fi - -if [ "$CI" != "true" ]; then - # Install/update packages - echo -e $(status_message "Installing and updating NPM packages..." ) - npm ci - - # Make sure npm is up-to-date - npm install npm -g -fi - -# There was a bug in NPM that caused changes in package-lock.json. Handle that. -if [ "$CI" != "true" ] && ! git diff --no-ext-diff --exit-code package-lock.json >/dev/null; then - if ask "$(warning_message "Your package-lock.json changed, which may mean there's an issue with your NPM cache. Would you like to try and automatically clean it up?" )" N 10; then - rm -rf node_modules/ - npm cache clean --force >/dev/null 2>&1 - git checkout package-lock.json - - echo -e $(status_message "Reinstalling NPM packages..." ) - npm ci - - # Check that it's cleaned up now. - if git diff --no-ext-diff --exit-code package-lock.json >/dev/null; then - echo -e $(warning_message "Confirmed that the NPM cache is cleaned up." ) - else - echo -e $(error_message "We were unable to clean the NPM cache, please manually review the changes to package-lock.json. Continuing with the setup process..." ) - fi - else - echo -e $(warning_message "Please manually review the changes to package-lock.json. Continuing with the setup process..." ) - fi -fi diff --git a/bin/local-env/launch-containers.sh b/bin/local-env/launch-containers.sh index 10f8d00f201..31a2001701f 100755 --- a/bin/local-env/launch-containers.sh +++ b/bin/local-env/launch-containers.sh @@ -22,6 +22,10 @@ fi echo -e $(status_message "Stopping Docker containers...") dc down --remove-orphans >/dev/null 2>&1 +# Build the Docker containers. +echo -e $(status_message "Building Docker containers...") +dc build wordpress >/dev/null + # Download image updates. echo -e $(status_message "Downloading Docker image updates...") dc pull diff --git a/bin/local-env/start.sh b/bin/local-env/start.sh index ee67677b05d..1d78a64e54e 100755 --- a/bin/local-env/start.sh +++ b/bin/local-env/start.sh @@ -9,12 +9,6 @@ set -e # Change to the expected directory cd "$(dirname "$0")/../.." -# Check whether Node and NVM are installed -. "$(dirname "$0")/install-node-nvm.sh" - -# Check whether Composer installed -. "$(dirname "$0")/install-composer.sh" - # Check whether Docker is installed and running . "$(dirname "$0")/launch-containers.sh"