Skip to content

Commit c1b109d

Browse files
committed
fixed startup so that the app is env aware
1 parent df3352c commit c1b109d

File tree

10 files changed

+96
-114
lines changed

10 files changed

+96
-114
lines changed

Dockerfile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ FROM serversideup/php:8.1-fpm-nginx
33
# Install addition packages
44
RUN apt-get update && apt-get install -y \
55
cron \
6-
supervisor \
76
php8.1-bcmath \
87
php8.1-pgsql \
98
&& apt-get clean \
10-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
11-
&& rm -f /etc/cont-init.d/50-laravel-automations
9+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
1210

1311
# Install Speedtest cli
1412
RUN curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash \
1513
&& apt-get install -y speedtest
1614

1715
# Copy package configs
1816
COPY docker/deploy/cron/scheduler /etc/cron.d/scheduler
19-
COPY docker/deploy/entrypoint /usr/local/bin/entrypoint
20-
COPY docker/deploy/etc/cont-init.d/ /etc/cont-init.d/
21-
COPY docker/deploy/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
22-
23-
RUN chmod 0644 /etc/cron.d/scheduler \
24-
&& crontab /etc/cron.d/scheduler \
25-
&& chmod +x /usr/local/bin/entrypoint
17+
COPY docker/deploy/etc/services.d/ /etc/services.d/
2618

2719
# Copy app
2820
COPY . /var/www/html
2921
COPY .env.docker .env
3022

3123
# Install app dependencies
3224
RUN composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev \
33-
&& chown -R 9999:9999 /var/www/html
25+
&& mkdir -p /app \
26+
&& mkdir -p storage/logs \
27+
&& php artisan optimize:clear \
28+
&& chown -R webuser:webgroup /var/www/html \
29+
&& rm -rf /etc/cont-init.d/50-laravel-automations \
30+
&& chmod 0644 /etc/cron.d/scheduler \
31+
&& crontab /etc/cron.d/scheduler \
32+
&& cp docker/deploy/entrypoint.sh /entrypoint \
33+
&& chmod +x /entrypoint
3434

35-
ENTRYPOINT ["entrypoint"]
35+
ENTRYPOINT ["/entrypoint"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ docker run -itd --name speedtest-tracker \
1616
-p 8080:80 \
1717
-e "PHP_POOL_NAME=speedtest-tracker_php" \
1818
-e "DB_CONNECTION=sqlite" \
19-
-e "DB_DATABASE=/appdata/database.sqlite" \
20-
-v speedtest-tracker_app:/appdata \
19+
-e "DB_DATABASE=/app/database.sqlite" \
20+
-v speedtest-tracker_app:/app \
2121
speedtest-tracker
2222
```
2323

app/Jobs/SearchForSpeedtests.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Foundation\Bus\Dispatchable;
1010
use Illuminate\Queue\InteractsWithQueue;
1111
use Illuminate\Queue\SerializesModels;
12+
use Illuminate\Support\Facades\File;
1213
use Symfony\Component\Yaml\Yaml;
1314

1415
class SearchForSpeedtests implements ShouldQueue
@@ -32,9 +33,15 @@ public function __construct()
3233
*/
3334
public function handle()
3435
{
35-
$config = Yaml::parseFile(
36-
base_path().'/config.yml'
37-
);
36+
if (File::exists(base_path().'/config.yml')) {
37+
$config = Yaml::parseFile(
38+
base_path().'/config.yml'
39+
);
40+
}
41+
42+
if (File::exists('/app/config.yml')) {
43+
$config = Yaml::parseFile('/app/config.yml');
44+
}
3845

3946
$speedtest = $config['speedtest'];
4047

docker/deploy/cron/scheduler

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* * * * * webuser cd /var/www/html && php artisan schedule:run >/dev/null 2>&1
1+
* * * * * webuser cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1

docker/deploy/entrypoint

Lines changed: 0 additions & 6 deletions
This file was deleted.

docker/deploy/entrypoint.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env sh
2+
3+
if [ $# -gt 0 ];then
4+
# If we passed a command, run it as root
5+
exec "$@"
6+
else
7+
echo ""
8+
echo ""
9+
echo "🐇 Configuring Speedtest Tracker..."
10+
11+
if [ ${DB_CONNECTION:="sqlite"} == "sqlite" ]; then
12+
# Check for database
13+
if [ ! -f /app/database.sqlite ]; then
14+
echo "🙄 Database file not found, creating..."
15+
16+
touch /app/database.sqlite
17+
else
18+
echo "✅ Database exists"
19+
fi
20+
fi
21+
22+
# Check for config yaml file
23+
if [ ! -f /app/config.yml ]; then
24+
echo "🙄 Config file not found, creating..."
25+
cp /var/www/html/config.example.yml /app/config.yml
26+
else
27+
echo "✅ Config file exists"
28+
fi
29+
30+
# Check for app key
31+
if grep -E "APP_KEY=[0-9A-Za-z:+\/=]{1,}" /var/www/html/.env > /dev/null; then
32+
echo "✅ App key exists"
33+
else
34+
echo "⏳ Generating app key..."
35+
php /var/www/html/artisan key:generate --no-ansi -q
36+
fi
37+
38+
# Link storage
39+
echo "📦 Linking storage..."
40+
php /var/www/html/artisan storage:link --no-ansi -q
41+
42+
# Build cache
43+
echo "💰 Building the cache..."
44+
php /var/www/html/artisan config:cache --no-ansi -q
45+
php /var/www/html/artisan route:cache --no-ansi -q
46+
47+
# Migrate database
48+
echo "🚛 Migrating the database..."
49+
php /var/www/html/artisan migrate --force --no-ansi -q
50+
51+
# Fix permissions again, just in case
52+
echo "🔑 Fixing permissions..."
53+
chown -R webuser:webgroup /var/www/html
54+
55+
# App install done, show a message
56+
echo "✅ All set, starting Speedtest Tracker container..."
57+
echo ""
58+
echo ""
59+
60+
exec /init
61+
fi

docker/deploy/etc/cont-init.d/50-speedtest-automations

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
exec cron -f -l 8
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# Switch to web user
4+
su webuser
5+
6+
# Bring up PHP queue worker
7+
exec php /var/www/html/artisan queue:work --tries=3 --no-ansi -q

docker/deploy/supervisord.conf

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)