Compare commits

...

2 Commits

Author SHA1 Message Date
be60c6a506 Cache page assets during CI/CD
Some checks failed
Create Docker Image / Test Application (x86_64) (push) Successful in 1m12s
Create Docker Image / Final Docker Image Manifest (push) Has been cancelled
Create Docker Image / Build Docker Image (x86_64) (push) Has been cancelled
Create Docker Image / Build Docker Image (arm64) (push) Has been cancelled
2025-01-03 23:25:54 +11:00
6180a2b2da Swap out base docker container for dunglas/frankenphp 2025-01-03 23:12:11 +11:00
2 changed files with 73 additions and 52 deletions

View File

@ -6,32 +6,38 @@ env:
DOCKER_HOST: tcp://127.0.0.1:2375 DOCKER_HOST: tcp://127.0.0.1:2375
jobs: jobs:
# test: test:
# strategy: strategy:
# matrix: matrix:
# arch: arch:
# - x86_64 - x86_64
# # arm64 # arm64
#
# name: Test Application name: Test Application
# runs-on: docker-${{ matrix.arch }} runs-on: docker-${{ matrix.arch }}
# container: container:
# image: docker:dind image: docker:dind
# privileged: true privileged: true
#
# steps: steps:
# - name: Environment Setup - name: Environment Setup
# run: | run: |
# # If we have a proxy use it # If we have a proxy use it
# if [ -n "${HTTP_PROXY}" ]; then echo "HTTP PROXY [${HTTP_PROXY}]"; sed -i -e s'/https/http/' /etc/apk/repositories; fi if [ -n "${HTTP_PROXY}" ]; then echo "HTTP PROXY [${HTTP_PROXY}]"; sed -i -e s'/https/http/' /etc/apk/repositories; fi
# # Some pre-reqs # Some pre-reqs
# apk add git nodejs npm apk add git nodejs npm
# ## Some debugging info ## Some debugging info
# # env|sort # env|sort
#
# - name: Code Checkout - name: Code Checkout
# uses: actions/checkout@v4 uses: actions/checkout@v4
#
- name: Build Assets
run: |
# Build assets
npm i
npm run prod
# - name: Run Tests # - name: Run Tests
# run: | # run: |
# mv .env.testing .env # mv .env.testing .env
@ -43,19 +49,32 @@ jobs:
# php artisan key:generate # php artisan key:generate
# php artisan migrate # php artisan migrate
# php artisan db:seed # php artisan db:seed
# # Build assets
# npm i
# npm run prod
# # run laravel tests # # run laravel tests
# # XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text --colors=never # # XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text --colors=never
- name: Cache page assets
id: cache-page-assets
uses: actions/cache@v3
env:
cache-name: page-assets
with:
path: |
public/css/app.css
key:
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
build: build:
strategy: strategy:
matrix: matrix:
arch: arch:
- x86_64 - x86_64
- arm64 - arm64
# needs: [test] needs: [test]
name: Build Docker Image name: Build Docker Image
runs-on: docker-${{ matrix.arch }} runs-on: docker-${{ matrix.arch }}
@ -95,11 +114,12 @@ jobs:
- name: Code Checkout - name: Code Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Build Assets - if: ${{ steps.cache-page-assets.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: | run: |
# Build assets ls -al
npm i ls -al public/css/
npm run prod
- name: Record version and Delete Unnecessary files - name: Record version and Delete Unnecessary files
run: | run: |

View File

@ -6,8 +6,12 @@ env=${APP_ENV:-production}
php=${PHP_DIR:-/var/www/html} php=${PHP_DIR:-/var/www/html}
composer=${COMPOSER_HOME:-/var/cache/composer} composer=${COMPOSER_HOME:-/var/cache/composer}
RUN_USER=$(id -u -n)
SITE_USER=${SITE_USER:-www-data} SITE_USER=${SITE_USER:-www-data}
MEMCACHED_START=${MEMCACHED_START:-FALSE} MEMCACHED_START=${MEMCACHED_START:-FALSE}
[ "${RUN_USER}" = "deon" ] && USE_SU=1
(( [ -n "${USE_SU}" ] && echo su ${SITE_USER} -s /bin/sh -c command ${USE_SU} ) || echo comman ${USE_SU}) && echo extra command
exit 1
# To run a local queue, running jobs from the queue "hostname" # To run a local queue, running jobs from the queue "hostname"
LOCAL_QUEUE=${LOCAL_QUEUE:-FALSE} LOCAL_QUEUE=${LOCAL_QUEUE:-FALSE}
@ -87,7 +91,8 @@ if [ -r artisan -a -e ${php}/.env ]; then
[ -n "${FORCE_PERMS}" -o "${env}" != "local" -a -z "${SKIP_PERM}" ] && chmod g+w ${php} [ -n "${FORCE_PERMS}" -o "${env}" != "local" -a -z "${SKIP_PERM}" ] && chmod g+w ${php}
fi fi
su ${SITE_USER} -s /bin/sh -c "composer install --optimize-autoloader ${NODEV}" && ( test -e .composer.refresh && rm -f .composer.refresh ) CMD="composer install --optimize-autoloader ${NODEV}"
(( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}) && ( test -e .composer.refresh && rm -f .composer.refresh )
[ -n "${FORCE_PERMS}" -o "${env}" != "local" -a -z "${SKIP_PERM}" ] && [ ${mp} -eq 0 ] && chmod g-w ${php} [ -n "${FORCE_PERMS}" -o "${env}" != "local" -a -z "${SKIP_PERM}" ] && [ ${mp} -eq 0 ] && chmod g-w ${php}
fi fi
@ -95,7 +100,8 @@ if [ -r artisan -a -e ${php}/.env ]; then
mp=$(mp ${php}) mp=$(mp ${php})
if [ ${mp} -eq 1 ]; then if [ ${mp} -eq 1 ]; then
echo " - Caching configuration..." echo " - Caching configuration..."
su ${SITE_USER} -s /bin/sh -c "(php artisan optimize)" CMD="php artisan optimize"
( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}
fi fi
if [ "${role}" = "app" ]; then if [ "${role}" = "app" ]; then
@ -108,7 +114,8 @@ if [ -r artisan -a -e ${php}/.env ]; then
wait_for_db wait_for_db
su ${SITE_USER} -s /bin/sh -c "php artisan migrate" && rm -f .migrate CMD="php artisan migrate"
(( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}) && rm -f .migrate
fi fi
else else
[ -r .migrate ] && echo "! NOTE: Migration ignored due to IGNORE_MIGRATION" [ -r .migrate ] && echo "! NOTE: Migration ignored due to IGNORE_MIGRATION"
@ -118,20 +125,20 @@ if [ -r artisan -a -e ${php}/.env ]; then
if [ -d ${php}/vendor/laravel/passport ]; then if [ -d ${php}/vendor/laravel/passport ]; then
echo " - Generating OAUTH keys ..." echo " - Generating OAUTH keys ..."
set +e set +e
su ${SITE_USER} -s /bin/sh -c "php artisan passport:keys" CMD="php artisan passport:keys"
( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}
set -e set -e
fi fi
fi fi
if [ "${LOCAL_QUEUE}" = "TRUE" ]; then if [ "${LOCAL_QUEUE}" = "TRUE" ]; then
echo " - Starting local queue for [$(hostname)${LOCAL_QUEUES:+,${LOCAL_QUEUES}}] with job timeout of [${WORK_TIMEOUT:-90}], trying [${WORK_TRIES:-1}] times..." echo " - Starting local queue for [$(hostname)${LOCAL_QUEUES:+,${LOCAL_QUEUES}}] with job timeout of [${WORK_TIMEOUT:-90}], trying [${WORK_TRIES:-1}] times..."
su ${SITE_USER} -s /bin/sh -c " CMD="(while true; do php ${PHP_OPTIONS} artisan queue:work --verbose --tries=${WORK_TRIES:-1} --timeout=${WORK_TIMEOUT:-90} --queue=$(hostname)${LOCAL_QUEUES:+,${LOCAL_QUEUES}} ${WORK_MEMORY:+--memory=${WORK_MEMORY}} ${WORK_ONCE:+--once}; done) &"
(while true; do php ${PHP_OPTIONS} artisan queue:work --verbose --tries=${WORK_TRIES:-1} --timeout=${WORK_TIMEOUT:-90} --queue=$(hostname)${LOCAL_QUEUES:+,${LOCAL_QUEUES}} ${WORK_MEMORY:+--memory=${WORK_MEMORY}} ${WORK_ONCE:+--once}; done) & ( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}
"
fi fi
set +e set +e
[ -x init-php.sh ] && su ${SITE_USER} -s /bin/sh "init-php.sh" & [ -x init-php.sh ] && (( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "init-php.sh &" ) || init-php.sh &)
exec /usr/local/bin/docker-php-entrypoint "$@" exec /usr/local/bin/docker-php-entrypoint "$@"
@ -148,22 +155,16 @@ if [ -r artisan -a -e ${php}/.env ]; then
wait_for_db wait_for_db
su ${SITE_USER} -s /bin/sh -c " CMD="while true; do php ${PHP_OPTIONS} artisan queue:${QUEUE_CMD} --verbose --tries=${WORK_TRIES:-1} --timeout=${WORK_TIMEOUT:-90} ${WORK_QUEUES:+--queue=${WORK_QUEUES}} ${WORK_MEMORY:+--memory=${WORK_MEMORY}} ${WORK_ONCE:+--once}; done"
while true; do ( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}
php ${PHP_OPTIONS} artisan queue:${QUEUE_CMD} --verbose --tries=${WORK_TRIES:-1} --timeout=${WORK_TIMEOUT:-90} ${WORK_QUEUES:+--queue=${WORK_QUEUES}} ${WORK_MEMORY:+--memory=${WORK_MEMORY}} ${WORK_ONCE:+--once}
done
"
elif [ "$role" = "scheduler" ]; then elif [ "$role" = "scheduler" ]; then
echo " - Running the scheduler..." echo " - Running the scheduler..."
# We'll delay starting in case the app is caching # We'll delay starting in case the app is caching
sleep 15 sleep 15
su ${SITE_USER} -s /bin/sh -c " CMD="while true; do php ${PHP_OPTIONS} artisan schedule:work --verbose --no-interaction; done"
while true; do ( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}
php ${PHP_OPTIONS} artisan schedule:work --verbose --no-interaction
done
"
fi fi
else else