Skip to content

Commit

Permalink
Merge pull request PrestaShop#36250 from jolelievre/debug-ci
Browse files Browse the repository at this point in the history
Stabilise CI and docker initialisation
  • Loading branch information
jolelievre authored Jun 2, 2024
2 parents 52f6c73 + 440941e commit 82a7a39
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 39 deletions.
11 changes: 6 additions & 5 deletions .docker/docker_run_git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ if [ "${DISABLE_MAKE}" != "1" ]; then
mkdir -p /var/www/.composer
chown -R www-data:www-data /var/www/.composer
runuser -g www-data -u www-data -- php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" && php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer && rm -rf /tmp/composer-setup.php

echo "\n* Running composer ...";
COMPOSER_PROCESS_TIMEOUT=600 runuser -g www-data -u www-data -- /usr/local/bin/composer install --no-interaction
if [ $? -ne 0]; then
echo Composer install failed
if [ ! -f /usr/local/bin/composer ]; then
echo Composer installation failed
exit 1
fi

echo "\n* Running composer ...";
export COMPOSER_PROCESS_TIMEOUT=600
runuser -g www-data -u www-data -- /usr/local/bin/composer install --ansi --prefer-dist --no-interaction --no-progress

echo "\n* Build assets ...";
runuser -g www-data -u www-data -- /usr/bin/make assets

Expand Down
42 changes: 14 additions & 28 deletions .docker/wait-for-it.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,32 @@ wait_for()
start_ts=$(date +%s)
while :
do
if [[ $ISBUSY -eq 1 ]]; then
# Special check for mysql
if [[ "$PORT" = "3306" ]]; then
echoerr "$CMD_NAME: Fetching status from docker mysql"
mysql -h$HOST -uroot -pprestashop -e "status"
result=$?
elif [[ $ISBUSY -eq 1 ]]; then
nc -z $HOST $PORT
result=$?
else
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
fi
end_ts=$(date +%s)
ELAPSED_TIME=$((end_ts - start_ts))
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$CMD_NAME: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
echoerr "$CMD_NAME: $HOST:$PORT is available after $ELAPSED_TIME seconds"
break
elif [[ $TIMEOUT -gt 0 && $ELAPSED_TIME -gt $TIMEOUT ]]; then
echoerr "$CMD_NAME: $HOST:$PORT is still not available after $ELAPSED_TIME 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
Expand Down Expand Up @@ -157,13 +148,8 @@ if [[ $CHILD -gt 0 ]]; then
RESULT=$?
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
wait_for
RESULT=$?
fi
wait_for
RESULT=$?
fi

if [[ $CLI != "" ]]; then
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/create_diff_for_autoupgrade_pr_label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
run: docker compose build prestashop-git

- name: Fetch dependencies
run: docker compose run --rm prestashop-git composer install --ansi --prefer-dist --no-interaction --no-progress
run: COMPOSER_PROCESS_TIMEOUT=600 docker compose run --rm prestashop-git composer install --ansi --prefer-dist --no-interaction --no-progress --no-dev

- name: Waiting for database
run: ./.docker/wait-for-it.sh --timeout=60 --strict localhost:3306
run: docker compose run --rm prestashop-git /tmp/wait-for-it.sh --timeout=60 --strict mysql:3306

- name: Create base database
run: docker compose run --rm mysql mysql -hmysql -uroot -pprestashop -e "CREATE DATABASE presta_${{ matrix.branch }};"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron_js_routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: COMPOSER_PROCESS_TIMEOUT=600 composer install --prefer-dist
run: COMPOSER_PROCESS_TIMEOUT=600 composer install --ansi --prefer-dist --no-interaction --no-progress

- name: Build assets
run: make assets
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron_php_update_modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Install Composer dependencies
run: |
composer self-update --stable
COMPOSER_PROCESS_TIMEOUT=600 composer install --prefer-dist
COMPOSER_PROCESS_TIMEOUT=600 composer install --ansi --prefer-dist --no-interaction --no-progress
- name: Install NPM dependencies
working-directory: ./tests/UI
Expand Down
2 changes: 1 addition & 1 deletion config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/* in dev mode - check if composer was executed */
if (is_dir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'admin-dev') && (!is_dir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'vendor') ||
!file_exists(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'))) {
die('Error : please install <a href="https://getcomposer.org/">composer</a>. Then run "php composer.phar install"');
die('Config check Error : please install <a href="https://getcomposer.org/">composer</a>. Then run "php composer.phar install"');
}

/* No settings file? goto installer... */
Expand Down
2 changes: 1 addition & 1 deletion install-dev/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
/* in dev mode - check if composer was executed */
if ((!is_dir(_PS_CORE_DIR_ . DIRECTORY_SEPARATOR . 'vendor') ||
!file_exists(_PS_CORE_DIR_ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'))) {
die('Error : please install <a href="https://getcomposer.org/">composer</a>. Then run "php composer.phar install"');
die('Init Install Error : please install <a href="https://getcomposer.org/">composer</a>. Then run "php composer.phar install"');
}

require_once _PS_CORE_DIR_ . '/config/defines.inc.php';
Expand Down
22 changes: 22 additions & 0 deletions tools/assets/wait-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if [[ ! -d $ADMIN_DIR ]]; then
return 1
fi

neededFiles=""
buildLocks=""
if test $# -gt 0; then
case $1 in
admin-default)
Expand All @@ -32,9 +34,14 @@ if test $# -gt 0; then
echo ">>> Waiting for classic theme assets..."
buildLocks="$PROJECT_PATH/themes/classic/_dev/buildLock"
;;
composer)
echo ">>> Waiting for composer install..."
neededFiles="$PROJECT_PATH/vendor/autoload.php"
;;
all)
echo ">>> Waiting for all assets..."
buildLocks="$ADMIN_DIR/themes/default/buildLock $ADMIN_DIR/themes/new-theme/buildLock $PROJECT_PATH/themes/classic/_dev/buildLock $PROJECT_PATH/themes/buildLock"
neededFiles="$PROJECT_PATH/vendor/autoload.php"
;;
*)
echo "Unknown asset to wait $1"
Expand All @@ -44,9 +51,11 @@ if test $# -gt 0; then
else
echo ">>> Waiting for all assets..."
buildLocks="$ADMIN_DIR/themes/default/buildLock $ADMIN_DIR/themes/new-theme/buildLock $PROJECT_PATH/themes/classic/_dev/buildLock $PROJECT_PATH/themes/buildLock"
neededFiles="$PROJECT_PATH/vendor/autoload.php"
fi

echo Checking for all these lock files $buildLocks
# Wait for lock files to disappear
for lockFile in $buildLocks; do
if [ -f $lockFile ]; then
echo Wait for $lockFile to be removed
Expand All @@ -58,3 +67,16 @@ for lockFile in $buildLocks; do
fi
echo $lockFile is no longer present
done

# Wait for needed files to be present
for neededFile in $neededFiles; do
if [ ! -f $neededFile ]; then
echo Wait for $neededFile to be generated
sleep 1
while [ ! -f $neededFile ]; do
echo $neededFile still not present wait a bit more
sleep 1
done
fi
echo $neededFile is present
done

0 comments on commit 82a7a39

Please sign in to comment.