Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ ENV PHP_OPEN_BASEDIR=$WEBUSER_HOME:/config/:/dev/stdout:/tmp
# Enable mixed ssl mode so port 80 or 443 can be used
ENV SSL_MODE="mixed"

# Install addition packages
RUN apt-get update && apt-get install -y \
cron \
gnupg \
php8.1-gd \
php8.1-pgsql \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install addition packages and cron file
RUN apt-get update \
&& apt-get install -y --no-install-recommends cron gnupg php8.1-gd php8.1-pgsql \
&& echo "MAILTO=\"\"\n* * * * * webuser /usr/bin/php /var/www/html/artisan schedule:run" > /etc/cron.d/laravel

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

# Clean up package lists
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# Copy package configs
COPY --chmod=644 docker/deploy/cron/scheduler /etc/cron.d/scheduler
COPY --chmod=755 docker/deploy/etc/s6-overlay/ /etc/s6-overlay/

WORKDIR /var/www/html
Expand All @@ -32,7 +31,6 @@ COPY --chown=webuser:webgroup . /var/www/html
RUN composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev \
&& mkdir -p storage/logs \
&& php artisan optimize:clear \
&& chown -R webuser:webgroup /var/www/html \
&& crontab /etc/cron.d/scheduler
&& chown -R webuser:webgroup /var/www/html

VOLUME /config
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
depends_on:
- mysql
- mailpit
- pgsql
mysql:
image: 'mysql/mysql-server:8.0'
ports:
Expand Down Expand Up @@ -55,9 +56,36 @@ services:
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
pgsql:
image: 'postgres:15'
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: '${DB_PASSWORD:-secret}'
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
volumes:
- 'sail-pgsql:/var/lib/postgresql/data'
- './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql'
networks:
- sail
healthcheck:
test:
- CMD
- pg_isready
- '-q'
- '-d'
- '${DB_DATABASE}'
- '-U'
- '${DB_USERNAME}'
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local
sail-pgsql:
driver: local
2 changes: 0 additions & 2 deletions docker/deploy/cron/scheduler

This file was deleted.

1 change: 0 additions & 1 deletion docker/deploy/etc/s6-overlay/s6-rc.d/cron/dependencies

This file was deleted.

1 change: 0 additions & 1 deletion docker/deploy/etc/s6-overlay/s6-rc.d/cron/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/command/with-contenv bash
echo "⏰ Starting the cron service..."
s6-setuidgid root /usr/sbin/cron -f -l 8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runas-user
configure-ssl

This file was deleted.

1 change: 0 additions & 1 deletion docker/deploy/etc/s6-overlay/s6-rc.d/queue-worker/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/command/with-contenv bash
echo "💪 Starting the queue worker..."
s6-setuidgid webuser php $WEBUSER_HOME/artisan queue:work --tries=3 --no-ansi -q
2 changes: 0 additions & 2 deletions docker/deploy/etc/s6-overlay/s6-rc.d/startup/dependencies

This file was deleted.

1 change: 0 additions & 1 deletion docker/deploy/etc/s6-overlay/s6-rc.d/startup/type

This file was deleted.

1 change: 0 additions & 1 deletion docker/deploy/etc/s6-overlay/s6-rc.d/startup/up

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
# Exit on error
set -e

echo ""
echo "🐇 Configuring Speedtest Tracker..."
echo ""

if [ ${DB_CONNECTION:="sqlite"} == "sqlite" ]; then
# Check for database
if [ ! -f /config/database.sqlite ]; then
echo "🙄 Database file not found, creating..."
touch /config/database.sqlite
echo "🙄 SQLite database not found, creating..."
s6-setuidgid webuser touch /config/database.sqlite
echo "✅ SQLite database created."
else
echo "✅ Database exists"
echo "✅ Database already exists."
fi
echo ""

# create symlinks
echo "🔗 Creating database symlink"
echo "🔗 Creating database symlink..."
symlinks=( \
/var/www/html/database/database.sqlite \
)
Expand All @@ -29,18 +33,24 @@ if [ ${DB_CONNECTION:="sqlite"} == "sqlite" ]; then
ln -s /config/"$(basename "$i")" "$i"
fi
done

echo "✅ Database symlink created."
echo ""
fi

# Check for env file
if [ ! -f /config/.env ]; then
echo "🙄 Environment file not found, creating..."
cp $WEBUSER_HOME/.env.example /config/.env
s6-setuidgid webuser cp $WEBUSER_HOME/.env.example /config/.env
echo "✅ Environment file created."
else
echo "✅ Environment file exists"
echo "✅ Environment file exists."
fi

echo ""

# create symlinks
echo "🔗 Creating symlinks to config and log files"
echo "🔗 Creating symlinks for config and log files..."
symlinks=( \
/var/www/html/.env \
/var/www/html/storage/logs/laravel.log
Expand All @@ -56,29 +66,48 @@ do
fi
done

echo "✅ Symlinks created."
echo ""

# Check for app key
if grep -E "APP_KEY=[0-9A-Za-z:+\/=]{1,}" $WEBUSER_HOME/.env > /dev/null; then
echo "✅ App key exists"
else
echo "⏳ Generating app key..."
php $WEBUSER_HOME/artisan key:generate --no-ansi -q
s6-setuidgid webuser php $WEBUSER_HOME/artisan key:generate --no-ansi -q
echo "✅ App key generated."
fi

echo ""

# Fix permissions
echo "🔒 Fixing app path file permissions"
echo "🔒 Fixing app path file permissions..."
chmod -R 755 /config
chown -R webuser:webgroup /config
chown -R webuser:webgroup $WEBUSER_HOME
echo "✅ Permissions fixed."
echo ""

# create storage symlink
echo "🔐 Linking the storage..."
s6-setuidgid webuser php $WEBUSER_HOME/artisan storage:link --no-ansi -q
echo "✅ Storage linked."
echo ""

# Build cache
echo "💰 Building the cache..."
s6-setuidgid webuser php $WEBUSER_HOME/artisan config:cache --no-ansi -q
s6-setuidgid webuser php $WEBUSER_HOME/artisan route:cache --no-ansi -q
s6-setuidgid webuser php $WEBUSER_HOME/artisan view:cache --no-ansi -q
echo "✅ Cache set."
echo ""

# Migrate database
echo "🚛 Migrating the database..."
s6-setuidgid webuser php $WEBUSER_HOME/artisan migrate --force --no-ansi -q
echo "✅ Database migrated."
echo ""

# App install done, show a message
echo "✅ All set, starting Speedtest Tracker container..."

exit 0
echo "✅ All set, Speedtest Tracker started."
echo ""
47 changes: 47 additions & 0 deletions docker/deploy/etc/s6-overlay/scripts/runas-user
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/command/with-contenv bash

PUID=${PUID:-9999}
PGID=${PGID:-9999}
WEBUSER_HOME=${WEBUSER_HOME:-"/var/www/html"}

if [[ $PUID != 9999 || $PGID != 9999 ]]; then

# Change the group ID
groupmod -o -g "$PGID" webgroup

# Change the User ID
usermod -o -u "$PUID" webuser

# Make sure the home directory is updated with the proper UID & GID
chown webuser:webgroup $WEBUSER_HOME
fi

if [[ $S6_LOGGING != 1 ]]; then
echo '
--------------------------------------------------------------------

_______ __ __ __
| __|.-----.-----.-----.--| | |_.-----.-----.| |_
|__ || _ | -__| -__| _ | _| -__|__ --|| _|
|_______|| __|_____|_____|_____|____|_____|_____||____|
|__|
_______ __
|_ _|.----.---.-.----.| |--.-----.----.
| | | _| _ | __|| <| -__| _|
|___| |__| |___._|____||__|__|_____|__|


--------------------------------------------------------------------'

echo '
To support Speedtest Tracker visit:
https://github.com/alexjustesen/speedtest-tracker
-------------------------------------
GID/UID
-------------------------------------'
echo "
User uid: $(id -u webuser)
User gid: $(id -g webuser)
-------------------------------------
"
fi