Laravel container update.
This commit is contained in:
parent
db3aa4a5c4
commit
f613924f1a
8 changed files with 136 additions and 8 deletions
26
.github/workflows/laravel.yml
vendored
26
.github/workflows/laravel.yml
vendored
|
|
@ -19,6 +19,13 @@ jobs:
|
|||
build:
|
||||
name: "Bake Laravel Container"
|
||||
runs-on: self-hosted
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
version:
|
||||
- "8.0"
|
||||
- "8.1"
|
||||
- "8.2"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: docker/setup-qemu-action@v2
|
||||
|
|
@ -35,5 +42,22 @@ jobs:
|
|||
platforms: linux/amd64,linux/arm64
|
||||
pull: true
|
||||
push: true
|
||||
build-args: |
|
||||
PHP_VERSION=${{ matrix.version }}
|
||||
tags: |
|
||||
matthewbaggett/laravel
|
||||
matthewbaggett/laravel:${{ matrix.version }}
|
||||
|
||||
latest:
|
||||
name: "Bake Laravel Container"
|
||||
runs-on: self-hosted
|
||||
needs: [ build ]
|
||||
steps:
|
||||
- uses: docker/login-action@v2
|
||||
name: Login to Docker Hub
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
|
||||
- run: |
|
||||
docker pull matthewbaggett/laravel:8.2
|
||||
docker tag matthewbaggett/laravel:8.2 matthewbaggett/laravel:latest
|
||||
docker push matthewbaggett/laravel:latest
|
||||
|
|
@ -1,7 +1,15 @@
|
|||
FROM benzine/php:nginx-8.0
|
||||
FROM benzine/php:nginx-${PHP_VERSION}
|
||||
LABEL maintainer="Matthew Baggett <matthew@baggett.me>" \
|
||||
org.label-schema.vcs-url="https://github.com/benzine-framework/docker" \
|
||||
org.opencontainers.image.source="https://github.com/benzine-framework/docker"
|
||||
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install -yqq \
|
||||
php8.1-mailparse \
|
||||
cpulimit
|
||||
COPY laravel.runit /etc/service/laravel/run
|
||||
RUN chmod +x /etc/service/laravel/run
|
||||
COPY laravel-horizon.runit /etc/service/horizon/run
|
||||
COPY laravel-horizon.finish /etc/service/horizon/finish
|
||||
COPY laravel-scheduler.runit /etc/service/scheduler/run
|
||||
COPY migrate.runit /etc/service/migrate/run
|
||||
COPY wait-for-mysql /usr/bin/wait-for-mysql
|
||||
RUN chmod +x /etc/service/*/run /etc/service/*/finish /usr/bin/wait-for-mysql
|
||||
2
laravel/laravel-horizon.finish
Normal file
2
laravel/laravel-horizon.finish
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
sleep 20;
|
||||
22
laravel/laravel-horizon.runit
Normal file
22
laravel/laravel-horizon.runit
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
rm -f /var/lock/laravel_horizon_started
|
||||
|
||||
# If horizon is present, publish the frontend assets, if HORIZON_UI is set to "on"
|
||||
if [[ -f "/app/config/horizon.php" ]]; then
|
||||
echo "[HORIZON] Waiting until Migration Complete."
|
||||
until [ -f /var/lock/laravel_migration_complete ]
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
echo "[HORIZON] Migration is complete, running Horizon."
|
||||
if [ "${HORIZON_UI,,}" = "on" ]; then
|
||||
echo "[HORIZON] Publishing horizon frontend assets"
|
||||
artisan horizon:publish
|
||||
fi
|
||||
echo "[HORIZON] Running laravel horizon runner"
|
||||
cpulimit -l 30 -- artisan horizon
|
||||
touch /var/lock/laravel_horizon_started
|
||||
else
|
||||
echo "[HORIZON] Horizon is not present"
|
||||
fi
|
||||
sleep infinity
|
||||
12
laravel/laravel-scheduler.runit
Normal file
12
laravel/laravel-scheduler.runit
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
cd /app
|
||||
echo "[SCHEDULER] Waiting until Migration Complete."
|
||||
until [ -f /var/lock/laravel_migration_complete ]
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
echo "[SCHEDULER] Migrations complete, starting scheduler"
|
||||
while true; do
|
||||
artisan schedule:run
|
||||
sleep 59;
|
||||
done
|
||||
|
|
@ -1,16 +1,24 @@
|
|||
#!/bin/bash
|
||||
echo "Fixing laravel application permissions"
|
||||
mkdir -f -p /app/storage /app/bootstrap/cache
|
||||
#!/usr/bin/env bash
|
||||
rm -f /var/lock/laravel_ready
|
||||
echo "[LARAVEL-FIXER] Fixing laravel application permissions"
|
||||
mkdir -p /app/storage /app/bootstrap/cache
|
||||
find /app/storage -type d -exec chmod 777 {} \;
|
||||
find /app/bootstrap/cache -type d -exec chmod 777 {} \;
|
||||
find /app/storage -type f -not -name ".gitignore" -exec chmod 666 {} \;
|
||||
find /app/bootstrap/cache -type f -exec chmod 666 {} \;
|
||||
|
||||
touch /app/storage/logs/laravel.log
|
||||
chmod 777 -R /app/storage
|
||||
chmod +x /app/artisan
|
||||
|
||||
echo "[LARAVEL-FIXER] Waiting for mysql..."
|
||||
/usr/bin/wait-for-mysql
|
||||
echo "[LARAVEL-FIXER] Mysql Ready, Laravel Ready."
|
||||
|
||||
touch /var/lock/laravel_ready
|
||||
|
||||
# Output the laravel log to the docker terminal.
|
||||
tail -f /app/storage/logs/laravel-*.log /app/storage/logs/laravel.log &
|
||||
tail -n0 -f /app/storage/logs/laravel-*.log /app/storage/logs/laravel.log &
|
||||
|
||||
# Sleep forever (and sleep again incase the sleep process is killed)
|
||||
while true; do
|
||||
|
|
|
|||
38
laravel/migrate.runit
Normal file
38
laravel/migrate.runit
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env bash
|
||||
rm -f /var/lock/laravel_migration_underway \
|
||||
/var/lock/laravel_migration_complete
|
||||
|
||||
# Give a moment for services to wake up
|
||||
echo "[MIGRATION] Waiting until Laravel Ready."
|
||||
sleep 3
|
||||
until [ -f /var/lock/laravel_ready ]
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
echo "[MIGRATION] Laravel is ready, running migrations..."
|
||||
|
||||
cd /app
|
||||
|
||||
# Run migration
|
||||
touch /var/lock/laravel_migration_underway
|
||||
|
||||
if [ "${MIGRATE_CLEAN,,}" = "on" ]; then
|
||||
artisan migrate:fresh --force
|
||||
artisan migrate --force # First run will fail due to permissions. We can ignore, but need to migrate again to finish.
|
||||
else
|
||||
# If we run this on first commit, it is the same as migrate:fresh, first run may fail and we need to try one more time.
|
||||
artisan migrate --force || artisan migrate --force
|
||||
fi
|
||||
|
||||
if [ "${SEEDERS,,}" = "on" ]; then
|
||||
artisan db:seed -q
|
||||
fi
|
||||
|
||||
rm /var/lock/laravel_migration_underway
|
||||
touch /var/lock/laravel_migration_complete
|
||||
echo "[MIGRATION] Migration complete!";
|
||||
|
||||
# Sleep forever (and sleep again in case the sleep process is killed)
|
||||
while true; do
|
||||
sleep infinity
|
||||
done
|
||||
14
laravel/wait-for-mysql
Normal file
14
laravel/wait-for-mysql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
MYSQL_HOST=${MYSQL_HOST:-"localhost"}
|
||||
MYSQL_PORT=${MYSQL_PORT:-3306}
|
||||
echo -n "Waiting for MySQL..."
|
||||
while ! mysqladmin ping -h"$MYSQL_HOST" -P"$MYSQL_PORT" --silent; do
|
||||
sleep 1
|
||||
echo -n "."
|
||||
done
|
||||
sleep 1;
|
||||
while ! mysqladmin ping -h"$MYSQL_HOST" -P"$MYSQL_PORT" --silent; do
|
||||
sleep 1
|
||||
echo -n "."
|
||||
done
|
||||
echo -e "\nConnected to MySQL!"
|
||||
Loading…
Reference in a new issue