Files
SAE-BUT2-docker/docker/frontend/entrypoint.sh
T
2026-01-28 15:16:07 +01:00

43 lines
861 B
Bash

#!/bin/sh
set -e
FRONTEND_DIR=/app
APP_DIR=/var/www/app
PUBLIC_DIR="$APP_DIR/public"
GIT_URL="https://oauth2:${GIT_TOKEN}@${FRONTEND_GIT_REPO}"
MAX_WAIT=300
WAITED=0
while [ ! -f "$APP_DIR/composer.json" ] || [ ! -d "$APP_DIR/vendor" ] || [ ! -d "$APP_DIR/public" ]; do
if [ $WAITED -ge $MAX_WAIT ]; then
exit 1
fi
sleep 3
WAITED=$((WAITED + 3))
done
if [ ! -d "$FRONTEND_DIR/.git" ]; then
git clone -b "${FRONTEND_GIT_BRANCH:-main}" "$GIT_URL" "$FRONTEND_DIR"
else
cd "$FRONTEND_DIR"
git fetch origin
git reset --hard origin/"${FRONTEND_GIT_BRANCH:-main}"
fi
cd "$FRONTEND_DIR"
if [ -f package.json ]; then
npm ci --prefer-offline --no-audit
fi
npm run build
if [ ! -d "dist" ]; then
exit 1
fi
find "$PUBLIC_DIR" -mindepth 1 ! -name '.gitkeep' ! -name 'index.php' ! -name '.htaccess' -delete
cp -r dist/* "$PUBLIC_DIR/"
exit 0