Skip to content

Commit

Permalink
Fix App/Packages to work with v6 style modules, not tested.
Browse files Browse the repository at this point in the history
More optimisation to the docker build process.
  • Loading branch information
mosen committed Jan 5, 2024
1 parent 4f66011 commit 8d972ca
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 27 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:lts as frontend
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN npm install && NODE_ENV=production npm run build
RUN npm install && npm run build

FROM php:8.3-apache
LABEL maintainer="MunkiReport PHP Team <[email protected]>"
Expand Down Expand Up @@ -35,10 +35,9 @@ RUN apt-get update && \
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-install -j$(nproc) curl pdo_mysql soap ldap zip opcache

COPY . $APP_DIR
COPY --from=frontend /usr/src/app/public/ /var/munkireport/public/
COPY --chown=www-data:www-data . $APP_DIR
COPY --chown=www-data:www-data --from=frontend /usr/src/app/public/ /var/munkireport/public/
WORKDIR $APP_DIR
RUN chown -R www-data:www-data $APP_DIR

RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/000-default.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
Expand All @@ -51,13 +50,14 @@ COPY build/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint
RUN cp "build/php.d/upload.ini" "$PHP_INI_DIR/conf.d/"

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

USER www-data

RUN composer install --no-dev && \
composer dumpautoload -o
composer dumpautoload -o && \
composer clear-cache

# You should not use this directory for SQLite as Laravel defines one. However, it is provided for backwards compatibility.
RUN mkdir -p app/db && \
touch app/db/db.sqlite

Expand Down
12 changes: 8 additions & 4 deletions app/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()

// When invoked from the web application, Composer will assume public/ contains a composer.json
// So, we need to hint the actual location of composer.json
$composer = Factory::create($io);
$composer = Factory::create($io, base_path('/composer.local.json'));

$this->composer = $composer;
$this->io = $io;
Expand Down Expand Up @@ -79,7 +79,7 @@ public function index()
*
* @return array|null
*/
public function modules()
public function modules(bool $includeLegacy = false)
{
$mr = $this->composer->getPackage();

Expand All @@ -99,8 +99,12 @@ public function modules()
if (Arr::has($p->getExtra(), 'munkireport')) {
$packages[] = $p;
} else {
if (!Str::startsWith($p->getName(), 'munkireport/')) continue;
$packages[] = $p;
if ($includeLegacy) {
if (!Str::startsWith($p->getName(), 'munkireport/')) {
continue;
}
$packages[] = $p;
}
}
}
}
Expand Down
66 changes: 53 additions & 13 deletions app/lib/munkireport/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace munkireport\lib;

use App\Packages;
use Illuminate\Foundation\PackageManifest;
use Illuminate\Support\Arr;
use Symfony\Component\Yaml\Yaml;

Expand All @@ -16,22 +18,22 @@ class Modules
/**
* @var array The complete list of available modules with their listings, widgets, etc.
*/
private $moduleList = [];
private array $moduleList = [];

/**
* @var array The complete list of available widgets (probably superseded by Widgets class)
*/
private $widgetList = [];
private array $widgetList = [];

/**
* @var array A list of paths that may be scanned for v5 modules.
*/
private $moduleSearchPaths = [];
private array $moduleSearchPaths = [];

/**
* @var string[] A list of modules that are always enabled effectively, without being declared.
*/
private $allowedModules = [
private array $allowedModules = [
'machine',
'reportdata',
'tag',
Expand All @@ -42,7 +44,7 @@ class Modules
/**
* @var bool When generating a list of modules, whether to skip modules not explicitly enabled.
*/
private $skipInactiveModules = False;
private bool $skipInactiveModules = False;

public function __construct()
{
Expand Down Expand Up @@ -79,7 +81,7 @@ public function __construct()
* Widgets have been omitted because addModuleWidgets() always assumes views are in the same path as the module.
* There is a function called addCoreWidgets() which adds them separately.
*/
protected function addCoreModules()
protected function addCoreModules(): void
{
$this->moduleList['reportdata'] = [
'detail_widgets' => [
Expand Down Expand Up @@ -181,7 +183,7 @@ protected function addCoreModules()
*
* @return array
*/
public function getModuleSearchPaths()
public function getModuleSearchPaths(): array
{
return $this->moduleSearchPaths;
}
Expand Down Expand Up @@ -457,13 +459,18 @@ public function addWidgets(array &$widgetArray, ?array $detailWidgetList = [])
/**
* Get data to create dropdown nav
*
* Change in v6.0 beta to support item data key `url` which replaces the auto generated path with a specific, absolute
* URL.
* As of v6, the URL to the target is not automatically always $base/$module/$item.
* Each module may provide an extra key as the link of the dropdown item:
*
* * `url` - an absolute URL to use for the link
* * `route` - a route alias to use for the link
*
* If both of these are missing, the behaviour falls back to v5 (the link is constructed using the module name)
*
* @param string $kind 'reports' or 'listings'
* @param string $baseUrl 'show/report' or 'show/listing'
* @param string $page current page url path
* @return array
* @return array An array of (object) that contain a `url`, `name`, `class` and `i18n` property, sorted alphabetically.
*/
public function getDropdownData(string $kind, string $baseUrl, string $page): array
{
Expand All @@ -476,11 +483,20 @@ public function getDropdownData(string $kind, string $baseUrl, string $page): ar
if(isset($itemData['hide_from_menu']) && $itemData['hide_from_menu']){
continue;
}
$i18n = isset($itemData['i18n']) ? $itemData['i18n'] : 'nav.' . $kind . '.' . $itemName;
$i18n = $itemData['i18n'] ?? 'nav.' . $kind . '.' . $itemName;

if (isset($itemData['url'])) {
$url = $itemData['url'];
} else if (isset($itemData['route'])) {
$url = route($itemData['route']);
} else {
$url = mr_url($baseUrl.'/'.$module.'/'.$itemName);
}

$out[] = (object) [
'url' => isset($itemData['url']) ? $itemData['url'] : mr_url($baseUrl.'/'.$module.'/'.$itemName),
'url' => $url,
'name' => $itemName,
'class' => $page == $baseUrl.'/'.$module.'/'.$itemName ? 'active' : '',
'class' => $page == $url ? 'active' : '',
'i18n' => $i18n,
];
}
Expand Down Expand Up @@ -593,6 +609,30 @@ private function collectModuleInfo(array $modulePaths, bool $skipInactiveModules
}
}
}

$this->collectPackageInformation();
}

/**
* Collect information from all v6 modules which use the Laravel Package Auto-Discovery mechanism
* (composer.json extra.munkireport section)
*
* @return void
*/
private function collectPackageInformation()
{
$packages = new Packages();
$modulePackages = $packages->modules();

foreach ($modulePackages as $mp) {
if (Arr::has($mp->getExtra(), 'munkireport')) {
$meta = $mp->getExtra()['munkireport'];
$this->moduleList[$mp->getName()] = [
'listings' => Arr::get($meta, 'navigation.listings', []),
'path' => ''
];
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion build/docker-php-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function run_migrations() {
function start_web() {

echo "Caching configuration..."
(cd /var/munkireport && php please config:cache && php please route:cache) # && php please view:cache
(cd /var/munkireport && php please config:cache && php please route:cache && php please lighthouse:cache) # && php please view:cache

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"
Expand Down
1 change: 1 addition & 0 deletions build/php.d/upload.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
; Required so that clients can submit POST body with their entire inventory
upload_max_filesize = 64M
post_max_size = 64M
6 changes: 3 additions & 3 deletions docker-compose.wip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ services:
ports:
- 8080:8080 # You should avoid privileged ports, here and in kubernetes
volumes:
- ./munkireport-db/:/var/munkireport/app/db
- ./user//:/var/munkireport/local/users

- ./.docker/db:/var/munkireport/app/db
- ./.docker/local:/var/munkireport/local
- ./.docker/storage:/var/munkireport/storage
# Queue Worker (If you are using Queues)
queue:
image: munkireport-php:wip
Expand Down

0 comments on commit 8d972ca

Please sign in to comment.