Skip to content

Commit

Permalink
Merge pull request #7813 from ampproject/fix/local-env
Browse files Browse the repository at this point in the history
Fix local-env issue of missing `xfs` user
  • Loading branch information
thelovekesh authored Jun 5, 2024
2 parents 5c306fc + 14bfb80 commit f819f2c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 229 deletions.
8 changes: 8 additions & 0 deletions bin/local-env/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 3 additions & 16 deletions bin/local-env/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '3.1'

services:
wordpress:
image: wordpress
build:
context: .
dockerfile: Dockerfile
ports:
- "127.0.0.1:8890:80"
env_file:
Expand All @@ -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
Expand Down
70 changes: 2 additions & 68 deletions bin/local-env/includes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/tty
else
endtime=$((`date +%s` + $timeout));
while [ "$endtime" -ge `date +%s` ]; do
timediff=$(($endtime - `date +%s`))

echo -en "\r$1 [$prompt] (Default $default in ${timediff}s) "
read -t 1 reply </dev/tty

if [ -n "$reply" ]; then
break
fi
done
fi

# Default?
if [ -z "$reply" ]; then
reply=$default
fi

# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac

done
}

##
# Download from a remote source.
#
Expand Down Expand Up @@ -147,7 +81,7 @@ command_exists() {
# Calls docker-compose with common options.
##
dc() {
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS "$@"
docker compose $DOCKER_COMPOSE_FILE_OPTIONS "$@"
}

##
Expand All @@ -156,7 +90,7 @@ dc() {
# Executes a WP CLI request in the CLI container.
##
wp() {
dc exec -T -u xfs $CLI wp "$@"
dc exec -T -u www-data $CONTAINER wp "$@"
}

##
Expand Down
42 changes: 0 additions & 42 deletions bin/local-env/install-composer.sh

This file was deleted.

97 changes: 0 additions & 97 deletions bin/local-env/install-node-nvm.sh

This file was deleted.

4 changes: 4 additions & 0 deletions bin/local-env/launch-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions bin/local-env/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit f819f2c

Please sign in to comment.