Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9400 from PierreRambaud/improvement/docker-e2e
Allow docker to run e2e tests
- Loading branch information
Showing
18 changed files
with
1,377 additions
and
1,058 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM prestashop/base:7.2-apache | ||
|
||
WORKDIR /tmp | ||
|
||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
# Install dependencies | ||
RUN apt-get update | ||
RUN apt-get install -y apt-utils | ||
RUN apt install -y \ | ||
gnupg2 \ | ||
curl \ | ||
git \ | ||
software-properties-common | ||
|
||
RUN rm -rf /var/lib/apt/lists/* | ||
|
||
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - | ||
RUN apt-get update | ||
RUN apt-get install -y nodejs | ||
RUN npm i npm@latest -g | ||
|
||
# Repository update | ||
WORKDIR /var/www/html/tests/E2E | ||
|
||
RUN usermod -u 1000 www-data | ||
|
||
COPY prepare-prestashop.sh /tmp/prepare-prestashop.sh | ||
|
||
COPY /prestashop/wait-for-it.sh /tmp/ | ||
COPY run-tests.sh /tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
if [ "$DB_SERVER" = "<to be defined>" -a $PS_INSTALL_AUTO = 1 ]; then | ||
echo >&2 'error: You requested automatic PrestaShop installation but MySQL server address is not provided ' | ||
echo >&2 ' You need to specify DB_SERVER in order to proceed' | ||
exit 1 | ||
fi | ||
|
||
# init if empty | ||
cp -n -R /tmp/data-ps/prestashop/* /var/www/html | ||
|
||
if [ -f /var/www/html/config/settings.inc.php ]; then | ||
rm /var/www/html/config/settings.inc.php | ||
echo "Remove unwanted configuration file" | ||
fi | ||
|
||
/bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
FROM prestashop/base:7.2-apache | ||
|
||
WORKDIR /tmp | ||
|
||
ENV PS_HANDLE_DYNAMIC_DOMAIN 0 | ||
ENV PS_INSTALL_AUTO 1 | ||
ENV PS_DEV_MODE 1 | ||
ENV PS_COUNTRY fr | ||
ENV TRAVIS_BUILD_DIR /var/www/html | ||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
# Install dependencies | ||
RUN apt-get update | ||
RUN apt-get install -y apt-utils | ||
RUN apt install -y \ | ||
gnupg2 \ | ||
curl \ | ||
git \ | ||
software-properties-common \ | ||
nodejs | ||
|
||
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer | ||
|
||
COPY /wait-for-it.sh /tmp/wait-for-it.sh | ||
|
||
# Repository update | ||
WORKDIR /var/www/html | ||
|
||
RUN usermod -u 1000 www-data | ||
|
||
COPY docker_run.sh /tmp/docker_run.sh | ||
|
||
CMD /tmp/wait-for-it.sh --timeout=60 --strict db:3306 -- /tmp/docker_run.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/sh | ||
|
||
if [ "$DB_SERVER" = "<to be defined>" -a $PS_INSTALL_AUTO = 1 ]; then | ||
echo >&2 'error: You requested automatic PrestaShop installation but MySQL server address is not provided ' | ||
echo >&2 ' You need to specify DB_SERVER in order to proceed' | ||
exit 1 | ||
fi | ||
|
||
# init if empty | ||
cp -n -R /tmp/data-ps/prestashop/* /var/www/html | ||
|
||
if [ -f /var/www/html/config/settings.inc.php -o -f /var/www/html/app/config/parameters.php ]; then | ||
echo "\n* Remove PrestaShop configuraiton files..."; | ||
rm -f /var/www/html/config/settings.inc.php | ||
rm -f /var/www/html/app/config/parameters.php | ||
fi | ||
|
||
if [ $PS_DEV_MODE -ne 0 ]; then | ||
echo "\n* Enabling DEV mode ..."; | ||
sed -ie "s/define('_PS_MODE_DEV_', false);/define('_PS_MODE_DEV_',\ true);/g" /var/www/html/config/defines.inc.php | ||
fi | ||
|
||
if [ $PS_HOST_MODE -ne 0 -a ! $(grep "define('_PS_HOST_MODE_', true);" /var/www/html/config/defines.inc.php) ]; then | ||
echo "\n* Enabling HOST mode ..."; | ||
echo "define('_PS_HOST_MODE_', true);" >> /var/www/html/config/defines.inc.php | ||
fi | ||
|
||
if [ "$PS_FOLDER_INSTALL" != "install" -a -d /var/www/html/install ]; then | ||
echo "\n* Renaming install folder as $PS_FOLDER_INSTALL ..."; | ||
mv /var/www/html/install /var/www/html/$PS_FOLDER_INSTALL/ | ||
fi | ||
|
||
if [ "$PS_FOLDER_ADMIN" != "admin" -a -d /var/www/html/admin ]; then | ||
echo "\n* Renaming admin folder as $PS_FOLDER_ADMIN ..."; | ||
mv /var/www/html/admin /var/www/html/$PS_FOLDER_ADMIN/ | ||
fi | ||
|
||
if [ $PS_HANDLE_DYNAMIC_DOMAIN = 1 ]; then | ||
cp /tmp/docker_updt_ps_domains.php /var/www/html | ||
sed -ie "s/DirectoryIndex\ index.php\ index.html/DirectoryIndex\ docker_updt_ps_domains.php\ index.php\ index.html/g" $APACHE_CONFDIR/conf-available/docker-php.conf | ||
fi | ||
|
||
if [ $PS_INSTALL_AUTO = 1 ]; then | ||
RET=1 | ||
while [ $RET -ne 0 ]; do | ||
mysql -h $DB_SERVER -P $DB_PORT -u $DB_USER -p$DB_PASSWD -e "status" > /dev/null 2>&1 | ||
RET=$? | ||
if [ $RET -ne 0 ]; then | ||
echo "\n* Waiting for confirmation of MySQL service startup"; | ||
sleep 5 | ||
fi | ||
done | ||
|
||
echo "\n* Installing PrestaShop, this may take a while ..."; | ||
if [ $PS_ERASE_DB = 1 ]; then | ||
echo "\n* Drop & recreate mysql database..."; | ||
if [ $DB_PASSWD = "" ]; then | ||
mysqladmin -h $DB_SERVER -P $DB_PORT -u $DB_USER drop $DB_NAME --force | ||
mysqladmin -h $DB_SERVER -P $DB_PORT -u $DB_USER create $DB_NAME --force | ||
else | ||
mysqladmin -h $DB_SERVER -P $DB_PORT -u $DB_USER -p$DB_PASSWD drop $DB_NAME --force | ||
mysqladmin -h $DB_SERVER -P $DB_PORT -u $DB_USER -p$DB_PASSWD create $DB_NAME --force | ||
fi | ||
fi | ||
|
||
if [ "$PS_DOMAIN" = "<to be defined>" ]; then | ||
export PS_DOMAIN=$(hostname -i) | ||
fi | ||
|
||
cd /var/www/html | ||
echo "\n* Install Dependencies..."; | ||
/usr/bin/composer install | ||
|
||
echo "\n* Install PrestaShop..."; | ||
php /var/www/html/$PS_FOLDER_INSTALL/index_cli.php --domain="$PS_DOMAIN" --db_server=$DB_SERVER:$DB_PORT --db_name="$DB_NAME" --db_user=$DB_USER \ | ||
--db_password=$DB_PASSWD --prefix="$DB_PREFIX" --firstname="John" --lastname="Doe" \ | ||
--password=$ADMIN_PASSWD --email="$ADMIN_MAIL" --language=$PS_LANGUAGE --country=$PS_COUNTRY \ | ||
--newsletter=0 --send_email=0 | ||
fi | ||
|
||
chown -hR www-data:www-data /var/www/html | ||
|
||
echo "\n* Almost ! Starting web server now\n"; | ||
exec apache2-foreground |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
#!/usr/bin/env bash | ||
# Use this script to test if a given TCP host/port are available | ||
|
||
CMD_NAME=$(basename $0) | ||
|
||
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } | ||
|
||
usage() | ||
{ | ||
cat << USAGE >&2 | ||
Usage: | ||
$CMD_NAME host:port [-s] [-t timeout] [-- command args] | ||
-h HOST | --host=HOST Host or IP under test | ||
-p PORT | --port=PORT TCP port under test | ||
Alternatively, you specify the host and port as host:port | ||
-s | --strict Only execute subcommand if the test succeeds | ||
-q | --quiet Don't output any status messages | ||
-t TIMEOUT | --timeout=TIMEOUT | ||
Timeout in seconds, zero for no timeout | ||
-- COMMAND ARGS Execute command with args after the test finishes | ||
USAGE | ||
exit 1 | ||
} | ||
|
||
wait_for() | ||
{ | ||
if [[ $TIMEOUT -gt 0 ]]; then | ||
echoerr "$CMD_NAME: waiting $TIMEOUT seconds for $HOST:$PORT" | ||
else | ||
echoerr "$CMD_NAME: waiting for $HOST:$PORT without a timeout" | ||
fi | ||
start_ts=$(date +%s) | ||
while : | ||
do | ||
if [[ $ISBUSY -eq 1 ]]; then | ||
nc -z $HOST $PORT | ||
result=$? | ||
else | ||
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1 | ||
result=$? | ||
fi | ||
if [[ $result -eq 0 ]]; then | ||
end_ts=$(date +%s) | ||
echoerr "$CMD_NAME: $HOST:$PORT is available after $((end_ts - start_ts)) seconds" | ||
break | ||
fi | ||
sleep 1 | ||
done | ||
return $result | ||
} | ||
|
||
wait_for_wrapper() | ||
{ | ||
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 | ||
if [[ $QUIET -eq 1 ]]; then | ||
timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & | ||
else | ||
timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & | ||
fi | ||
PID=$! | ||
trap "kill -INT -$PID" INT | ||
wait $PID | ||
RESULT=$? | ||
if [[ $RESULT -ne 0 ]]; then | ||
echoerr "$CMD_NAME: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT" | ||
fi | ||
return $RESULT | ||
} | ||
|
||
# process arguments | ||
while [[ $# -gt 0 ]] | ||
do | ||
case "$1" in | ||
*:* ) | ||
hostport=(${1//:/ }) | ||
HOST=${hostport[0]} | ||
PORT=${hostport[1]} | ||
shift 1 | ||
;; | ||
--child) | ||
CHILD=1 | ||
shift 1 | ||
;; | ||
-q | --quiet) | ||
QUIET=1 | ||
shift 1 | ||
;; | ||
-s | --strict) | ||
STRICT=1 | ||
shift 1 | ||
;; | ||
-h) | ||
HOST="$2" | ||
if [[ $HOST == "" ]]; then break; fi | ||
shift 2 | ||
;; | ||
--host=*) | ||
HOST="${1#*=}" | ||
shift 1 | ||
;; | ||
-p) | ||
PORT="$2" | ||
if [[ $PORT == "" ]]; then break; fi | ||
shift 2 | ||
;; | ||
--port=*) | ||
PORT="${1#*=}" | ||
shift 1 | ||
;; | ||
-t) | ||
TIMEOUT="$2" | ||
if [[ $TIMEOUT == "" ]]; then break; fi | ||
shift 2 | ||
;; | ||
--timeout=*) | ||
TIMEOUT="${1#*=}" | ||
shift 1 | ||
;; | ||
--) | ||
shift | ||
CLI="$@" | ||
break | ||
;; | ||
--help) | ||
usage | ||
;; | ||
*) | ||
echoerr "Unknown argument: $1" | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
if [[ "$HOST" == "" || "$PORT" == "" ]]; then | ||
echoerr "Error: you need to provide a host and port to test." | ||
usage | ||
fi | ||
|
||
TIMEOUT=${TIMEOUT:-15} | ||
STRICT=${STRICT:-0} | ||
CHILD=${CHILD:-0} | ||
QUIET=${QUIET:-0} | ||
|
||
# check to see if timeout is from busybox? | ||
# check to see if timeout is from busybox? | ||
TIMEOUT_PATH=$(realpath $(which timeout)) | ||
if [[ $TIMEOUT_PATH =~ "busybox" ]]; then | ||
ISBUSY=1 | ||
BUSYTIMEFLAG="-t" | ||
else | ||
ISBUSY=0 | ||
BUSYTIMEFLAG="" | ||
fi | ||
|
||
if [[ $CHILD -gt 0 ]]; then | ||
wait_for | ||
RESULT=$? | ||
exit $RESULT | ||
else | ||
if [[ $TIMEOUT -gt 0 ]]; then | ||
wait_for_wrapper | ||
RESULT=$? | ||
else | ||
wait_for | ||
RESULT=$? | ||
fi | ||
fi | ||
|
||
if [[ $CLI != "" ]]; then | ||
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then | ||
echoerr "$CMD_NAME: strict mode, refusing to execute subprocess" | ||
exit $RESULT | ||
fi | ||
exec $CLI | ||
else | ||
exit $RESULT | ||
fi |
Oops, something went wrong.