Skip to content

Commit

Permalink
No need to download composer during dockerfile build because we can u…
Browse files Browse the repository at this point in the history
…se a multi-stage COPY FROM composer.

Rewrote the docker-php-entrypoint to support other functions such as the queue worker if some other module starts using the queue functionality.
Remove the hybrid vite build because i removed the global search component.
Fix error "vite manifest component not found Pages/x"
docker compose configuration now includes queue and scheduler containers as options.
  • Loading branch information
mosen committed Jan 5, 2024
1 parent b5dd3f2 commit 4f66011
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 50 deletions.
10 changes: 4 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM node:lts as frontend
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN npm install && npm run build
RUN npm install && NODE_ENV=production npm run build

FROM php:8.1-apache
FROM php:8.3-apache
LABEL maintainer="MunkiReport PHP Team <munkireport@noreply.users.github.com>"
LABEL architecture="x86_64" \
io.k8s.display-name="MunkiReport" \
Expand All @@ -18,10 +18,7 @@ ENV COMPOSER_HOME /tmp

ENV AUTH_METHODS LOCAL
ENV APP_URL http://localhost:8080
ENV APP_NAME MunkiReport
ENV ENABLE_BUSINESS_UNITS FALSE
ENV LOG_CHANNEL stderr
ENV MODULES ard, bluetooth, disk_report, munkireport, managedinstalls, munkiinfo, network, security, warranty

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

Expand Down Expand Up @@ -53,7 +50,8 @@ RUN a2enmod rewrite
COPY build/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint
RUN cp "build/php.d/upload.ini" "$PHP_INI_DIR/conf.d/"

RUN ./build/setup_composer.sh
COPY --from=composer /usr/bin/composer /usr/bin/composer
#RUN ./build/setup_composer.sh

USER www-data

Expand Down
129 changes: 109 additions & 20 deletions build/docker-php-entrypoint
Original file line number Diff line number Diff line change
@@ -1,31 +1,120 @@
#!/bin/bash
set -e

if [ -z "${APP_KEY}" ]; then
echo "The environment variable APP_KEY was not supplied, you can use the key generated below in your container environment:"
php please key:generate --show
##################################
# Ensure that required Environment Variables are set and required configuration is valid
#
# Globals:
# APP_KEY
# APP_ENV
# Arguments:
# None
# Outputs:
# Writes warnings to stdout
##################################
function preflight() {
if [[ -z "${APP_KEY}" ]]; then
echo "The environment variable APP_KEY was not supplied, you can use the key generated below in your container environment:"
php please key:generate --show

echo "Please include the base64 portion, eg: APP_KEY=base64:aabbbcc"
else
echo "APP_KEY supplied. Not generating an APP_KEY."
fi
echo "Please include the base64 portion, eg: APP_KEY=base64:aabbbcc"
else
echo "APP_KEY supplied. Not generating an APP_KEY."
fi

echo "Sleeping 2 seconds for MariaDB" # TODO put a health check in
sleep 2
if [[ "${APP_ENV}" != "production" ]]; then
echo "WARNING: This application is running with APP_ENV: '${APP_ENV}', error pages could display more information than necessary about your system."
fi
}

php please config:debug
php please migrate --force
php please db:seed
##################################
# Run database migrations (at start) on the currently configured database connection "default".
# Displays current configuration to stdout.
#
# Arguments:
# None
# Outputs:
# Writes warnings to stdout
##################################
function run_migrations() {
echo "Running Database Migrations..."
echo "Sleeping 2 seconds for MariaDB" # TODO put a health check in
sleep 2

if [[ -z "${APP_URL}" || "${APP_URL}" == "http://localhost:8080" ]]; then
echo "APP_URL not set, or APP_URL set to default (http://localhost:8080). Please fix this otherwise you may be redirected to a nonexistent host"
fi
php please config:debug
php please migrate --force
php please db:seed # Refuses to run in APP_ENV=production
}

##################################
# Start the container as a web application
#
# Also performs caching of assets to increase performance.
#
# Globals:
# APP_URL
# Arguments:
# None
# Outputs:
# Writes warnings to stdout
##################################
function start_web() {

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- apache2-foreground "$@"
fi
echo "Caching configuration..."
(cd /var/munkireport && php please config:cache && php please route:cache) # && php please view:cache

exec "$@"
if [[ -z "${APP_URL}" || "${APP_URL}" == "http://localhost:8080" ]]; then
echo "APP_URL not set, or APP_URL set to default (http://localhost:8080). Please fix this otherwise you may be redirected to a nonexistent host"
fi

exec apache2-foreground
}

##################################
# Start the container as a command scheduler
#
# Arguments:
# None
# Outputs:
# Writes warnings to stdout
##################################
function start_scheduler() {
echo "Running Scheduler..."
while true; do
php /var/munkireport/please schedule:run --verbose --no-interaction &
sleep 60
done
}

##################################
# Start the container as a queue worker
#
# Arguments:
# None
# Outputs:
# Writes warnings to stdout
##################################
function start_queue_worker() {
echo "Running Queue Worker..."
php /var/munkireport/please queue:work --verbose --tries=3 --timeout=90
}

preflight

case "${1}" in
app)
run_migrations
start_web
;;
scheduler)
start_scheduler
;;
queue)
start_queue_worker
;;
*)
echo "No command matches '${1}', running as web application"
run_migrations
start_web
;;
esac
17 changes: 0 additions & 17 deletions build/setup_composer.sh

This file was deleted.

34 changes: 34 additions & 0 deletions docker-compose.wip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ services:
volumes:
- ./munkireport-db/:/var/munkireport/app/db
- ./user//:/var/munkireport/local/users

# Queue Worker (If you are using Queues)
queue:
image: munkireport-php:wip
restart: always
depends_on:
- munkireport
command:
- queue
environment:
- APP_URL=http://localhost:8080
- DB_CONNECTION=mysql
- DB_HOST=mariadb
- DB_USERNAME=munkireport
- DB_PASSWORD=munkireport
- DB_DATABASE=munkireport

# Scheduler (Optional)
scheduler:
image: munkireport-php:wip
restart: always
depends_on:
- munkireport
command:
- scheduler
environment:
- APP_URL=http://localhost:8080
- DB_CONNECTION=mysql
- DB_HOST=mariadb
- DB_USERNAME=munkireport
- DB_PASSWORD=munkireport
- DB_DATABASE=munkireport


mariadb:
image: mariadb:10.10
restart: always
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/inertia.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
@endif

@routes
@vite(['resources/js/app.ts', "resources/js/Pages/{$page['component']}.vue"])
@vite(['resources/js/app.ts'])
@inertiaHead
</head>
<body class="mr-inertia-layout">
Expand Down
1 change: 0 additions & 1 deletion resources/views/layouts/mr.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,5 @@ function onSubmit(token) {
</script>

@stack('scripts')
@vite('resources/js/app-hybrid.ts')
</body>
</html>
6 changes: 1 addition & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ export default defineConfig({
rollupOptions: {
input: {
// This entry point is for full SPA
app: resolve(__dirname, 'resources/js/app.ts'),

// This entry point for hybrid jQuery/Vue pages where Vue is only used on part of the page eg.
// For the search box. These components are globally registered.
hybrid: resolve(__dirname, 'resources/js/app-hybrid.ts'),
app: resolve(__dirname, 'resources/js/app.ts')
}
}
}
Expand Down

0 comments on commit 4f66011

Please sign in to comment.