Skip to content

Commit 5026142

Browse files
committed
Add init scripts to Docker image
1 parent 9a2ba63 commit 5026142

File tree

14 files changed

+124
-31
lines changed

14 files changed

+124
-31
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ COPY docker/php.ini /etc/php82/conf.d/
7676
COPY docker/php-fpm.conf /etc/php82/
7777
COPY docker/supervisord.conf /etc/
7878
COPY docker/process /srv/process/
79+
COPY docker/scripts /srv/scripts/
7980

8081
USER dirigent
8182

docker/init.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@
22

33
set -e
44

5+
# Run init scripts
6+
for file in $(find "/srv/scripts/init" -type f | sort -t '-' -k1,1n)
7+
do
8+
echo "Execute init script: $file"
9+
sh "$file"
10+
done
11+
12+
# Start Supervisor
513
exec supervisord

docker/process/consumer.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
set -e
44

5-
while [ -z "$(netstat -an | grep :9000)" ]; do
6-
echo "Waiting for app";
7-
sleep 5;
8-
done;
5+
while [ ! "$(netstat -an | grep :9000)" ]; do
6+
echo "Worker is waiting for application"
97

10-
exec /srv/app/bin/console messenger:consume async scheduler_packages --sleep 10
8+
sleep 5
9+
done
10+
11+
function shutdown() {
12+
bin/console messenger:stop-workers
13+
}
14+
15+
trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP
16+
17+
exec bin/console messenger:consume async scheduler_packages --sleep 10

docker/process/fpm.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22

33
set -e
44

5-
composer run-script --no-ansi --no-interaction auto-scripts
5+
while [ ! $(pg_isready) ]; do
6+
echo "Application is waiting for the database"
67

7-
# todo temporary timeout for database connection
8-
while ! nc -z localhost 5432; do
9-
echo "Waiting for database connection";
10-
sleep 3;
11-
done;
12-
13-
bin/console doctrine:database:create --if-not-exists --no-ansi --no-interaction
14-
bin/console doctrine:migrations:migrate --allow-no-migration --no-ansi --no-interaction
8+
sleep 3
9+
done
1510

1611
exec php-fpm

docker/process/postgresql.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
set -e
44

5-
function shutdown()
6-
{
5+
function shutdown() {
76
pkill postgres
87
}
98

10-
if [ ! -d "/srv/data/postgresql" ]; then
11-
mkdir -p /srv/data/postgresql
12-
initdb /srv/data/postgresql
13-
fi
14-
159
trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP
1610

1711
exec postgres -D /srv/data/postgresql
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ -d "/srv/data/postgresql" ]; then
6+
echo "Database directory found"
7+
8+
# Start Postgres server
9+
pg_ctl start -D /srv/data/postgresql
10+
11+
exit 0
12+
fi
13+
14+
echo "Creating PostgreSQL database..."
15+
16+
# Create database directory
17+
mkdir -p /srv/data/postgresql
18+
19+
# Initialize database storage
20+
initdb /srv/data/postgresql
21+
22+
# Start Postgres server
23+
pg_ctl start -D /srv/data/postgresql
24+
25+
# Create database
26+
createdb dirigent
27+
28+
echo "Created PostgreSQL database"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
composer run-script --no-ansi --no-interaction auto-scripts
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
bin/console doctrine:migrations:sync-metadata-storage --no-ansi --no-interaction
6+
bin/console doctrine:migrations:migrate --allow-no-migration --no-ansi --no-interaction
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# Stop Postgres server
6+
pg_ctl stop -D /srv/data/postgresql

tests/Docker/Standalone/ConsoleTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44

55
class ConsoleTest extends DockerStandaloneTestCase
66
{
7-
public function testComposerPlatformRequirements(): void
8-
{
9-
$this->assertCommandSuccessful(
10-
['composer', 'check-platform-reqs', '--no-dev'],
11-
'Platform requirements of Composer packages must be met.',
12-
);
13-
}
14-
157
public function testConsole(): void
168
{
179
$this->assertCommandSuccessful(

0 commit comments

Comments
 (0)