-
Notifications
You must be signed in to change notification settings - Fork 0
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
The "WPTT_CONTAINER_NAME" variable is not set #10
Comments
Can confirm I'm also getting the same error under the same conditions. |
It should be in the |
It is :). Just to be clear: in
in
|
It also should be in |
Okay, so I've done a little bit of testing. When I run $ ./docker/run compose
WARNING: The WPTT_CONTAINER_NAME variable is not set. Defaulting to a blank string. This is run using the following dockerfile. version: "3.7"
services:
wp:
init: true
env_file:
- ../.env
container_name: "${WPTT_CONTAINER_NAME}-wp"
ports:
- "8080:8080"
depends_on:
- db
build:
context: ..
dockerfile: docker/Dockerfile
volumes:
- ..:/app
db:
container_name: "${WPTT_CONTAINER_NAME}-db"
image: mariadb
env_file:
- ../.env Hardcoding these variables seems to fix the issue and remove the warning. Docker isn't loading these via env_file for some reason. I found I can revert my hardcoded changes and resolve this error by manually copying ./.env into ./docker/.env. I updated ./docker/run to write to./docker/.env automatically instead of ./.env. Then I updated docker-compose to use the new env_file location. Things are now running smoothly (minus some minimum PHP version errors I now have to work out). This may be very much a hotfix, but here are the changes I made if you want a quick solution. ./docker/run #!/bin/sh
set -eu
cmd=docker/run
help() {
echo "
Docker shell wrapper for WP Testing Tools
usage:
$cmd compose [custom options]
Start the Docker enviroment with docker-compose
$cmd shell
Enter the testing shell
$cmd update
Update these Docker scripts
$cmd compose-no-init
Start the container without installing anything. Usefull for
debugging or developing install steps
$cmd clean
Remove the installation directory and containers
"
}
if [ ! -f docker/run ]; then
>&2 echo
>&2 echo "Oops! The docker script is supposed to be run from the parent directory"
>&2 echo "Ex. ./docker/run or more simply just docker/run"
>&2 echo
exit 1
fi
echo "# Generated file. Do not edit. Edit .env.docker instead" > ./docker/.env
echo "" >> ./docker/.env
cat .env.docker >> ./docker/.env
eval $(grep -v '^#' ./docker/.env)
shell() {
command=$@
if [ "$command" = "" ]; then
command="bash -l"
>&2 echo
>&2 echo "Welcome to WordPress testing shell!"
>&2 echo "Your plugin is mounted to /app and all composer dependencies are put to PATH."
>&2 echo
>&2 echo "Try: codecept run wpunit"
>&2 echo " or: codecept run functional"
>&2 echo
fi
exec docker exec -it "${WPTT_CONTAINER_NAME}-wp" $command
}
compose() {
command=$@
if [ "$command" = "" ]; then
command="up --build --abort-on-container-exit"
fi
exec docker-compose -f docker/docker-compose.yml $command
}
update() {
if [ -x ./vendor/bin/wptt-configure ]; then
exec ./vendor/bin/wptt-configure --docker
fi
>&2 echo
>&2 echo "valu/wp-testing-tools not installed with composer?"
>&2 echo
exit 5
}
clean() {
rm -rf "$WPTT_INSTALL_DIR"
compose rm
}
case "${1:-}" in
-h|--help)
help
exit
;;
"")
>&2 help
exit
;;
compose)
shift
compose $@
;;
compose-no-init)
shift
echo "WPTT_NO_INIT=1" >> ./docker/.env
compose $@
;;
shell)
shift
shell $@
;;
update)
shift
update
;;
clean)
shift
clean
;;
*)
>&2 echo "Bad action ${1:-}"
exit 1
;;
esac ./docker/docker-compose version: "3.7"
services:
wp:
init: true
env_file:
- .env
container_name: "${WPTT_CONTAINER_NAME}-wp"
ports:
- "8080:8080"
depends_on:
- db
build:
context: ..
dockerfile: docker/Dockerfile
volumes:
- ..:/app
db:
container_name: "${WPTT_CONTAINER_NAME}-db"
image: mariadb
env_file:
- .env
|
Just realized that .env is used by wp-install. Could update script to write to both places. |
Been a while since I visited this thread. So I'll give a small update to anyone struggling. The issue is definitely related to docker-compose not respecting the relative path defined in docker/docker-compose.yml. This could be an intentional security feature to prevent reverse directory traversal or a bug on particular environments. Either way, this issue seems to go away when you pass the environment file path directly though command line arguments. Updating your compose method in docker/run with the following resolves the issue. compose() {
command=$@
if [ "$command" = "" ]; then
command="--env-file .env up --build --abort-on-container-exit"
fi
exec docker-compose -f docker/docker-compose.yml $command
} If I get some free time I'll test this thoroughly and PR it, but hopefully those struggling will see this issue and get some relief with this fix till then. |
Whenever I run
./docker/run compose
I get an error message telling me the WPTT_CONTAINER_NAME is not set.WARN[0000] The "WPTT_CONTAINER_NAME" variable is not set. Defaulting to a blank string.
This is weird, as the
.env
file does contain it:(I omitted the non-relevant lines).
Running the
config
command shows the same problem:Am I missing something here? According to the Docker docs this should work.
The text was updated successfully, but these errors were encountered: