-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdocker_run.sh
More file actions
executable file
·106 lines (85 loc) · 3.58 KB
/
docker_run.sh
File metadata and controls
executable file
·106 lines (85 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# This is what gets run when we start the restarters Docker container.
#
# We install composer dependencies in here rather than during the build step so that if we switch branches
# and restart the container, it works.
USER_ID=${UID:-1000}
GROUP_ID=${GID:-1000}
if [ ! -f .env ]
then
cp .env.example .env
fi
rm -rf vendor
composer install
# Point at the DB server
sed -i 's/DB_HOST=.*$/DB_HOST=restarters_db/g' .env
sed -i 's/DB_DATABASE=.*$/DB_DATABASE=restarters_db_test/g' .env
# Turn off session domain, which causes problems in a Docker environment.
sed -i 's/SESSION_DOMAIN=.*$/SESSION_DOMAIN=/g' .env
# Change the Discourse host to point at the one defined in docker-compose
sed -i 's/DISCOURSE_URL=.*$/DISCOURSE_URL=http:\/\/restarters_discourse:80/g' .env
# Change the Discourse secret to be the value we set up in Discourse itself.
sed -i 's/DISCOURSE_SECRET=.*$/DISCOURSE_SECRET=mustbetencharacters/g' .env
# Change the database environment used for automated tests.
sed -i 's/SESSION_DOMAIN=.*$/SESSION_DOMAIN=/g' phpunit.xml
sed -i 's/DB_TEST_HOST=.*$/DB_TEST_HOST=restarters_db/g' phpunit.xml
# Generic wait function that takes: service_name, check_command, max_attempts, sleep_interval
wait_for_service() {
local service_name="$1"
local check_command="$2"
local max_attempts="$3"
local sleep_interval="$4"
echo "Waiting for $service_name..."
local attempt=0
while [ $attempt -lt $max_attempts ]; do
if eval "$check_command" >/dev/null 2>&1; then
echo "✓ $service_name is ready"
return 0
fi
echo " $service_name not ready, waiting... (attempt $((attempt + 1))/$max_attempts)"
sleep "$sleep_interval"
attempt=$((attempt + 1))
done
echo "❌ $service_name failed to start after $max_attempts attempts"
exit 1
}
# Ensure storage directories exist and have correct permissions
mkdir -p storage/framework/cache/data
mkdir -p storage/framework/sessions
mkdir -p storage/framework/views
mkdir -p storage/logs
mkdir -p bootstrap/cache
mkdir -p uploads
mkdir -p public/uploads
# Only change ownership of directories that need it, excluding .git and other system files
# This prevents permission errors on files owned by the host system
echo "Fixing file permissions with ${USER_ID}:${GROUP_ID}"
for dir in storage bootstrap/cache vendor node_modules uploads public/uploads; do
if [ -d "$dir" ]; then
chown -R ${USER_ID}:${GROUP_ID} "$dir" 2>/dev/null || true
fi
done
# Wait for MySQL database to be ready before running migrations
wait_for_service "MySQL database" "mysqladmin ping -h restarters_db --skip-ssl --silent" 60 5
php artisan migrate:fresh --seed
npm install --legacy-peer-deps
npm rebuild node-sass
# Install Playwright for testing (system deps already in Dockerfile)
npm install -D @playwright/test
npx playwright install
# Start Vite dev server in the background with logging
echo "Starting Vite dev server..."
nohup npm run dev > /tmp/vite.log 2>&1 &
echo "Vite dev server started with PID $!"
php artisan key:generate
php artisan cache:clear
php artisan config:clear
# Generate OpenAPI documentation needed for tests
php artisan l5-swagger:generate
# Ensure we have the admin user
echo "User::firstOrCreate(['email'=>'jane@bloggs.net'], ['name'=>'Jane Bloggs','password'=>Hash::make('passw0rd'),'role'=>2,'consent_past_data'=>'2021-01-01','consent_future_data'=>'2021-01-01','consent_gdpr'=>'2021-01-01']);" | php artisan tinker
# Ensure we have a test group tag
echo "\App\GroupTags::firstOrCreate(['tag_name'=>'Test Tag'], ['description'=>'A test tag for development']);" | php artisan tinker
php-fpm
# In case everything else bombs out.
sleep infinity