Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local-env issue of missing xfs user #7813

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"

Comment on lines -12 to -17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the CI runners already have these tools pre-installed, and we configure NodeJS and Composer in the CI.

For local development, I doubt if this is being used given we already have wp-env setup.

# Check whether Docker is installed and running
. "$(dirname "$0")/launch-containers.sh"

Expand Down
Loading