Files
SAE-BUT2-docker/docker/php/scripts/init-prod.sh
T
2026-02-11 16:07:28 +01:00

72 lines
1.6 KiB
Bash

set -e
APP_DIR=/var/www/app
GIT_URL="https://oauth2:${GIT_TOKEN}@${BACKEND_GIT_REPO}"
BRANCH="${BACKEND_GIT_BRANCH:-main}"
FORCE_CLONE="${FORCE_CLONE:-false}"
git config --global --add safe.directory "$APP_DIR"
if [ ! -d "$APP_DIR/.git" ]; then
mkdir -p "$APP_DIR"
echo "azy"
git clone -b "$BRANCH" "$GIT_URL" "$APP_DIR"
echo "a"
else
cd "$APP_DIR"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" = "$BRANCH" ]; then
echo "b"
git fetch origin
git reset --hard origin/"$CURRENT_BRANCH"
else
if [ "$FORCE_CLONE" = "true" ]; then
cd ..
rm -rf "$APP_DIR"
mkdir -p "$APP_DIR"
git clone -b "$BRANCH" "$GIT_URL" "$APP_DIR"
else
git fetch origin
git reset --hard origin/"$BRANCH"
fi
fi
fi
cd "$APP_DIR"
mkdir -p /var/www/.composer/cache
chown -R www-data:www-data /var/www/.composer
if [ -f composer.json ]; then
composer install --no-interaction --prefer-dist
fi
cp /tmp/app.env .env
/usr/local/bin/wait-typesense.sh
TYPESENSE_API_KEY=$(cat /typesense-data/api-key)
sed -i "s/^TYPESENSE_API_KEY=.*/TYPESENSE_API_KEY=$TYPESENSE_API_KEY/" .env
chown www-data:www-data .env
chmod 640 .env
/usr/local/bin/wait-mariadb.sh
php artisan key:generate --force
php artisan config:clear
php artisan cache:clear
php artisan migrate --force
php artisan db:seed --class=ProdSeeder
chown root:root .env
chmod 440 .env
chown -R www-data:www-data "$APP_DIR/storage" "$APP_DIR/bootstrap/cache"
chmod -R 775 "$APP_DIR/storage" "$APP_DIR/bootstrap/cache"