Compare commits

...

3 Commits

Author SHA1 Message Date
2f242b1162 Swap out base docker container for dunglas/frankenphp
All checks were successful
Create Docker Image / Test Application (x86_64) (push) Successful in 35s
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 1m24s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 3m23s
Create Docker Image / Final Docker Image Manifest (push) Successful in 11s
2025-01-04 18:44:21 +11:00
77ca130ce3 Cache page assets during CI/CD
All checks were successful
Create Docker Image / Test Application (x86_64) (push) Successful in 3m35s
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 1m24s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 3m23s
Create Docker Image / Final Docker Image Manifest (push) Successful in 11s
2025-01-04 18:17:21 +11:00
8379e48e80 Swap out base docker container for dunglas/frankenphp 2025-01-04 17:06:45 +11:00
2 changed files with 91 additions and 53 deletions

View File

@ -6,32 +6,38 @@ env:
DOCKER_HOST: tcp://127.0.0.1:2375
jobs:
# test:
# strategy:
# matrix:
# arch:
# - x86_64
# # arm64
#
# name: Test Application
# runs-on: docker-${{ matrix.arch }}
# container:
# image: docker:dind
# privileged: true
#
# steps:
# - name: Environment Setup
# run: |
# # 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
# # Some pre-reqs
# apk add git nodejs npm
# ## Some debugging info
# # env|sort
#
# - name: Code Checkout
# uses: actions/checkout@v4
#
test:
strategy:
matrix:
arch:
- x86_64
# arm64
name: Test Application
runs-on: docker-${{ matrix.arch }}
container:
image: docker:dind
privileged: true
steps:
- name: Environment Setup
run: |
# 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
# Some pre-reqs
apk add git nodejs npm tar zstd
## Some debugging info
# env|sort
- name: Code Checkout
uses: actions/checkout@v4
- name: Build Assets
run: |
# Build assets
npm i
npm run prod
# - name: Run Tests
# run: |
# mv .env.testing .env
@ -43,19 +49,31 @@ jobs:
# php artisan key:generate
# php artisan migrate
# php artisan db:seed
# # Build assets
# npm i
# npm run prod
# # run laravel tests
# # 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
public/js/app.js
public/js/vendor.js
#key: build-pla-page-assets-${{ hashFiles('**/package-lock.json') }}
key: build-pla-page-assets
#restore-keys: |
# build-pla-page-assets-
build:
strategy:
matrix:
arch:
- x86_64
- arm64
# needs: [test]
needs: [test]
name: Build Docker Image
runs-on: docker-${{ matrix.arch }}
@ -72,7 +90,7 @@ jobs:
# 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
# Some pre-reqs
apk add git curl nodejs npm
apk add git curl nodejs npm tar zstd
# Start docker
( dockerd --host=tcp://0.0.0.0:2375 --tls=false & ) && sleep 3
## Some debugging info
@ -95,16 +113,35 @@ jobs:
- name: Code Checkout
uses: actions/checkout@v4
- name: Build Assets
- name: Cache page assets
id: cache-page-assets
uses: actions/cache@v3
# env:
# cache-name: page-assets
with:
path: |
public/css/app.css
public/js/app.js
public/js/vendor.js
#key: build-pla-page-assets-${{ hashFiles('**/package-lock.json') }}
key: build-pla-page-assets
#restore-keys: |
# build-pla-page-assets-
- if: ${{ steps.cache-page-assets.outputs.cache-hit != 'true' }}
name: List the state of page assets
continue-on-error: false
run: |
# Build assets
npm i
npm run prod
echo CACHE-HIT:${{ steps.cache-page-assets.outputs.cache-hit }}
ls -al public/css/
ls -al public/js/
- name: Record version and Delete Unnecessary files
run: |
echo ${GITHUB_SHA::8} > VERSION
rm -rf .git* tests/ storage/app/test/
ls -al public/css/
ls -al public/js/
- name: Build and Push Docker Image
uses: docker/build-push-action@v5

View File

@ -6,8 +6,10 @@ env=${APP_ENV:-production}
php=${PHP_DIR:-/var/www/html}
composer=${COMPOSER_HOME:-/var/cache/composer}
RUN_USER=$(id -u -n)
SITE_USER=${SITE_USER:-www-data}
MEMCACHED_START=${MEMCACHED_START:-FALSE}
[ "${RUN_USER}" = "deon" ] && USE_SU=1
# To run a local queue, running jobs from the queue "hostname"
LOCAL_QUEUE=${LOCAL_QUEUE:-FALSE}
@ -33,6 +35,8 @@ function wait_for_db() {
fi
}
echo "* Started with [$@]"
# Run any container setup
[ -x /sbin/init-container ] && /sbin/init-container
@ -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}
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}
fi
@ -95,7 +100,8 @@ if [ -r artisan -a -e ${php}/.env ]; then
mp=$(mp ${php})
if [ ${mp} -eq 1 ]; then
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
if [ "${role}" = "app" ]; then
@ -108,7 +114,8 @@ if [ -r artisan -a -e ${php}/.env ]; then
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
else
[ -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
echo " - Generating OAUTH keys ..."
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
fi
fi
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..."
su ${SITE_USER} -s /bin/sh -c "
(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) &
"
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) &"
( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}
fi
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 "$@"
@ -148,22 +155,16 @@ if [ -r artisan -a -e ${php}/.env ]; then
wait_for_db
su ${SITE_USER} -s /bin/sh -c "
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
"
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"
( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}
elif [ "$role" = "scheduler" ]; then
echo " - Running the scheduler..."
# We'll delay starting in case the app is caching
sleep 15
su ${SITE_USER} -s /bin/sh -c "
while true; do
php ${PHP_OPTIONS} artisan schedule:work --verbose --no-interaction
done
"
CMD="while true; do php ${PHP_OPTIONS} artisan schedule:work --verbose --no-interaction; done"
( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}
fi
else