Merge pull request #624 from MyIgel/version
Added version to credits and metrics page
This commit is contained in:
commit
1e16f4c47e
|
@ -38,7 +38,9 @@ build-image:
|
||||||
<<: *docker_definition
|
<<: *docker_definition
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
- docker build --pull --build-arg NGINX_IMAGE="${TEST_IMAGE}-nginx" -t "${TEST_IMAGE}" -f contrib/Dockerfile .
|
- apk -q add git
|
||||||
|
- VERSION="$(git describe --abbrev=0 --tags)-${CI_COMMIT_REF_NAME}+${CI_PIPELINE_ID}.${CI_COMMIT_SHORT_SHA}"
|
||||||
|
- docker build --pull --build-arg NGINX_IMAGE="${TEST_IMAGE}-nginx" --build-arg VERSION="${VERSION}" -t "${TEST_IMAGE}" -f contrib/Dockerfile .
|
||||||
- docker push "${TEST_IMAGE}"
|
- docker push "${TEST_IMAGE}"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
|
|
@ -28,6 +28,7 @@ return [
|
||||||
\Engelsystem\Http\Validation\ValidationServiceProvider::class,
|
\Engelsystem\Http\Validation\ValidationServiceProvider::class,
|
||||||
|
|
||||||
// Additional services
|
// Additional services
|
||||||
|
\Engelsystem\Helpers\VersionServiceProvider::class,
|
||||||
\Engelsystem\Mail\MailerServiceProvider::class,
|
\Engelsystem\Mail\MailerServiceProvider::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@ COPY --from=composer /app/composer.lock /app/
|
||||||
RUN find /app/storage/ -type f -not -name .gitignore -exec rm {} \;
|
RUN find /app/storage/ -type f -not -name .gitignore -exec rm {} \;
|
||||||
RUN rm -f /app/import/* /app/config/config.php
|
RUN rm -f /app/import/* /app/config/config.php
|
||||||
|
|
||||||
|
ARG VERSION
|
||||||
|
RUN if [[ ! -f /app/storage/app/VERSION ]] && [[ ! -z "${VERSION}" ]]; then echo -n "${VERSION}" > /app/storage/app/VERSION; fi
|
||||||
|
|
||||||
# Build the PHP container
|
# Build the PHP container
|
||||||
FROM php:7-fpm-alpine
|
FROM php:7-fpm-alpine
|
||||||
WORKDIR /var/www
|
WORKDIR /var/www
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<h2>Source code</h2>
|
<h2>Source code</h2>
|
||||||
|
<p>Version: <i>{{ version }}</i></p>
|
||||||
<p>
|
<p>
|
||||||
The original engelsystem was written by
|
The original engelsystem was written by
|
||||||
<a href="https://github.com/cookieBerlin/engelsystem">cookie</a>.
|
<a href="https://github.com/cookieBerlin/engelsystem">cookie</a>.
|
||||||
|
|
|
@ -111,6 +111,7 @@ class Application extends Container
|
||||||
$this->instance('path.lang', $this->get('path.resources') . DIRECTORY_SEPARATOR . 'lang');
|
$this->instance('path.lang', $this->get('path.resources') . DIRECTORY_SEPARATOR . 'lang');
|
||||||
$this->instance('path.views', $this->get('path.resources') . DIRECTORY_SEPARATOR . 'views');
|
$this->instance('path.views', $this->get('path.resources') . DIRECTORY_SEPARATOR . 'views');
|
||||||
$this->instance('path.storage', $appPath . DIRECTORY_SEPARATOR . 'storage');
|
$this->instance('path.storage', $appPath . DIRECTORY_SEPARATOR . 'storage');
|
||||||
|
$this->instance('path.storage.app', $this->get('path.storage') . DIRECTORY_SEPARATOR . 'app');
|
||||||
$this->instance('path.cache', $this->get('path.storage') . DIRECTORY_SEPARATOR . 'cache');
|
$this->instance('path.cache', $this->get('path.storage') . DIRECTORY_SEPARATOR . 'cache');
|
||||||
$this->instance('path.cache.routes', $this->get('path.cache') . DIRECTORY_SEPARATOR . 'routes.cache.php');
|
$this->instance('path.cache.routes', $this->get('path.cache') . DIRECTORY_SEPARATOR . 'routes.cache.php');
|
||||||
$this->instance('path.cache.views', $this->get('path.cache') . DIRECTORY_SEPARATOR . 'views');
|
$this->instance('path.cache.views', $this->get('path.cache') . DIRECTORY_SEPARATOR . 'views');
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Engelsystem\Controllers;
|
namespace Engelsystem\Controllers;
|
||||||
|
|
||||||
use Engelsystem\Config\Config;
|
use Engelsystem\Config\Config;
|
||||||
|
use Engelsystem\Helpers\Version;
|
||||||
use Engelsystem\Http\Response;
|
use Engelsystem\Http\Response;
|
||||||
|
|
||||||
class CreditsController extends BaseController
|
class CreditsController extends BaseController
|
||||||
|
@ -13,14 +14,19 @@ class CreditsController extends BaseController
|
||||||
/** @var Response */
|
/** @var Response */
|
||||||
protected $response;
|
protected $response;
|
||||||
|
|
||||||
|
/** @var Version */
|
||||||
|
protected $version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param Config $config
|
* @param Config $config
|
||||||
|
* @param Version $version
|
||||||
*/
|
*/
|
||||||
public function __construct(Response $response, Config $config)
|
public function __construct(Response $response, Config $config, Version $version)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->response = $response;
|
$this->response = $response;
|
||||||
|
$this->version = $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +36,10 @@ class CreditsController extends BaseController
|
||||||
{
|
{
|
||||||
return $this->response->withView(
|
return $this->response->withView(
|
||||||
'pages/credits.twig',
|
'pages/credits.twig',
|
||||||
['credits' => $this->config->get('credits')]
|
[
|
||||||
|
'credits' => $this->config->get('credits'),
|
||||||
|
'version' => $this->version->getVersion(),
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Engelsystem\Controllers\Metrics;
|
||||||
|
|
||||||
use Engelsystem\Config\Config;
|
use Engelsystem\Config\Config;
|
||||||
use Engelsystem\Controllers\BaseController;
|
use Engelsystem\Controllers\BaseController;
|
||||||
|
use Engelsystem\Helpers\Version;
|
||||||
use Engelsystem\Http\Exceptions\HttpForbidden;
|
use Engelsystem\Http\Exceptions\HttpForbidden;
|
||||||
use Engelsystem\Http\Request;
|
use Engelsystem\Http\Request;
|
||||||
use Engelsystem\Http\Response;
|
use Engelsystem\Http\Response;
|
||||||
|
@ -26,25 +27,31 @@ class Controller extends BaseController
|
||||||
/** @var Stats */
|
/** @var Stats */
|
||||||
protected $stats;
|
protected $stats;
|
||||||
|
|
||||||
|
/** @var Version */
|
||||||
|
protected $version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param MetricsEngine $engine
|
* @param MetricsEngine $engine
|
||||||
* @param Config $config
|
* @param Config $config
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Stats $stats
|
* @param Stats $stats
|
||||||
|
* @param Version $version
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Response $response,
|
Response $response,
|
||||||
MetricsEngine $engine,
|
MetricsEngine $engine,
|
||||||
Config $config,
|
Config $config,
|
||||||
Request $request,
|
Request $request,
|
||||||
Stats $stats
|
Stats $stats,
|
||||||
|
Version $version
|
||||||
) {
|
) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->response = $response;
|
$this->response = $response;
|
||||||
$this->stats = $stats;
|
$this->stats = $stats;
|
||||||
|
$this->version = $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,6 +75,18 @@ class Controller extends BaseController
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
$this->config->get('app_name') . ' stats',
|
$this->config->get('app_name') . ' stats',
|
||||||
|
'info' => [
|
||||||
|
'type' => 'gauge',
|
||||||
|
'help' => 'About the environment',
|
||||||
|
[
|
||||||
|
'labels' => [
|
||||||
|
'os' => PHP_OS_FAMILY,
|
||||||
|
'php' => implode('.', [PHP_MAJOR_VERSION, PHP_MINOR_VERSION]),
|
||||||
|
'version' => $this->version->getVersion(),
|
||||||
|
],
|
||||||
|
'value' => 1,
|
||||||
|
],
|
||||||
|
],
|
||||||
'users' => [
|
'users' => [
|
||||||
'type' => 'gauge',
|
'type' => 'gauge',
|
||||||
['labels' => ['state' => 'incoming'], 'value' => $this->stats->newUsers()],
|
['labels' => ['state' => 'incoming'], 'value' => $this->stats->newUsers()],
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Helpers;
|
||||||
|
|
||||||
|
use Engelsystem\Config\Config;
|
||||||
|
|
||||||
|
class Version
|
||||||
|
{
|
||||||
|
/** @var Config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/** @vat string */
|
||||||
|
protected $storage;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $versionFile = 'VERSION';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $storage
|
||||||
|
* @param Config $config
|
||||||
|
*/
|
||||||
|
public function __construct(string $storage, Config $config)
|
||||||
|
{
|
||||||
|
$this->storage = $storage;
|
||||||
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getVersion()
|
||||||
|
{
|
||||||
|
$file = $this->storage . DIRECTORY_SEPARATOR . $this->versionFile;
|
||||||
|
|
||||||
|
$version = 'n/a';
|
||||||
|
if (file_exists($file)) {
|
||||||
|
$version = trim(file_get_contents($file));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->config->get('version', $version);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Helpers;
|
||||||
|
|
||||||
|
use Engelsystem\Container\ServiceProvider;
|
||||||
|
|
||||||
|
class VersionServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->when(Version::class)
|
||||||
|
->needs('$storage')
|
||||||
|
->give($this->app->get('path.storage.app'));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
/*
|
||||||
|
!.gitignore
|
|
@ -4,9 +4,10 @@ namespace Engelsystem\Test\Unit\Controllers;
|
||||||
|
|
||||||
use Engelsystem\Config\Config;
|
use Engelsystem\Config\Config;
|
||||||
use Engelsystem\Controllers\CreditsController;
|
use Engelsystem\Controllers\CreditsController;
|
||||||
|
use Engelsystem\Helpers\Version;
|
||||||
use Engelsystem\Http\Response;
|
use Engelsystem\Http\Response;
|
||||||
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class CreditsControllerTest extends TestCase
|
class CreditsControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -19,12 +20,17 @@ class CreditsControllerTest extends TestCase
|
||||||
/** @var Response|MockObject $response */
|
/** @var Response|MockObject $response */
|
||||||
$response = $this->createMock(Response::class);
|
$response = $this->createMock(Response::class);
|
||||||
$config = new Config(['foo' => 'bar', 'credits' => ['lor' => 'em']]);
|
$config = new Config(['foo' => 'bar', 'credits' => ['lor' => 'em']]);
|
||||||
|
/** @var Version|MockObject $version */
|
||||||
|
$version = $this->createMock(Version::class);
|
||||||
|
|
||||||
$response->expects($this->once())
|
$this->setExpects(
|
||||||
->method('withView')
|
$response,
|
||||||
->with('pages/credits.twig', ['credits' => ['lor' => 'em']]);
|
'withView',
|
||||||
|
['pages/credits.twig', ['credits' => ['lor' => 'em'], 'version' => '42.1.0-test']]
|
||||||
|
);
|
||||||
|
$this->setExpects($version, 'getVersion', [], '42.1.0-test');
|
||||||
|
|
||||||
$controller = new CreditsController($response, $config);
|
$controller = new CreditsController($response, $config, $version);
|
||||||
$controller->index();
|
$controller->index();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Engelsystem\Config\Config;
|
||||||
use Engelsystem\Controllers\Metrics\Controller;
|
use Engelsystem\Controllers\Metrics\Controller;
|
||||||
use Engelsystem\Controllers\Metrics\MetricsEngine;
|
use Engelsystem\Controllers\Metrics\MetricsEngine;
|
||||||
use Engelsystem\Controllers\Metrics\Stats;
|
use Engelsystem\Controllers\Metrics\Stats;
|
||||||
|
use Engelsystem\Helpers\Version;
|
||||||
use Engelsystem\Http\Exceptions\HttpForbidden;
|
use Engelsystem\Http\Exceptions\HttpForbidden;
|
||||||
use Engelsystem\Http\Request;
|
use Engelsystem\Http\Request;
|
||||||
use Engelsystem\Http\Response;
|
use Engelsystem\Http\Response;
|
||||||
|
@ -28,7 +29,8 @@ class ControllerTest extends TestCase
|
||||||
/** @var MetricsEngine|MockObject $engine */
|
/** @var MetricsEngine|MockObject $engine */
|
||||||
/** @var Stats|MockObject $stats */
|
/** @var Stats|MockObject $stats */
|
||||||
/** @var Config $config */
|
/** @var Config $config */
|
||||||
list($response, $request, $engine, $stats, $config) = $this->getMocks();
|
/** @var Version|MockObject $version */
|
||||||
|
list($response, $request, $engine, $stats, $config, $version) = $this->getMocks();
|
||||||
|
|
||||||
$request->server = new ServerBag();
|
$request->server = new ServerBag();
|
||||||
$request->server->set('REQUEST_TIME_FLOAT', 0.0123456789);
|
$request->server->set('REQUEST_TIME_FLOAT', 0.0123456789);
|
||||||
|
@ -37,6 +39,7 @@ class ControllerTest extends TestCase
|
||||||
->method('get')
|
->method('get')
|
||||||
->willReturnCallback(function ($path, $data) use ($response) {
|
->willReturnCallback(function ($path, $data) use ($response) {
|
||||||
$this->assertEquals('/metrics', $path);
|
$this->assertEquals('/metrics', $path);
|
||||||
|
$this->assertArrayHasKey('info', $data);
|
||||||
$this->assertArrayHasKey('users', $data);
|
$this->assertArrayHasKey('users', $data);
|
||||||
$this->assertArrayHasKey('licenses', $data);
|
$this->assertArrayHasKey('licenses', $data);
|
||||||
$this->assertArrayHasKey('users_working', $data);
|
$this->assertArrayHasKey('users_working', $data);
|
||||||
|
@ -122,7 +125,9 @@ class ControllerTest extends TestCase
|
||||||
'XL' => 'X Large',
|
'XL' => 'X Large',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$controller = new Controller($response, $engine, $config, $request, $stats);
|
$this->setExpects($version, 'getVersion', [], '0.42.42');
|
||||||
|
|
||||||
|
$controller = new Controller($response, $engine, $config, $request, $stats, $version);
|
||||||
$controller->metrics();
|
$controller->metrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +142,8 @@ class ControllerTest extends TestCase
|
||||||
/** @var MetricsEngine|MockObject $engine */
|
/** @var MetricsEngine|MockObject $engine */
|
||||||
/** @var Stats|MockObject $stats */
|
/** @var Stats|MockObject $stats */
|
||||||
/** @var Config $config */
|
/** @var Config $config */
|
||||||
list($response, $request, $engine, $stats, $config) = $this->getMocks();
|
/** @var Version|MockObject $version */
|
||||||
|
list($response, $request, $engine, $stats, $config, $version) = $this->getMocks();
|
||||||
|
|
||||||
$response->expects($this->once())
|
$response->expects($this->once())
|
||||||
->method('withHeader')
|
->method('withHeader')
|
||||||
|
@ -168,7 +174,7 @@ class ControllerTest extends TestCase
|
||||||
$this->setExpects($stats, 'arrivedUsers', null, 10, $this->exactly(2));
|
$this->setExpects($stats, 'arrivedUsers', null, 10, $this->exactly(2));
|
||||||
$this->setExpects($stats, 'currentlyWorkingUsers', null, 5);
|
$this->setExpects($stats, 'currentlyWorkingUsers', null, 5);
|
||||||
|
|
||||||
$controller = new Controller($response, $engine, $config, $request, $stats);
|
$controller = new Controller($response, $engine, $config, $request, $stats, $version);
|
||||||
$controller->stats();
|
$controller->stats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +188,8 @@ class ControllerTest extends TestCase
|
||||||
/** @var MetricsEngine|MockObject $engine */
|
/** @var MetricsEngine|MockObject $engine */
|
||||||
/** @var Stats|MockObject $stats */
|
/** @var Stats|MockObject $stats */
|
||||||
/** @var Config $config */
|
/** @var Config $config */
|
||||||
list($response, $request, $engine, $stats, $config) = $this->getMocks();
|
/** @var Version|MockObject $version */
|
||||||
|
list($response, $request, $engine, $stats, $config, $version) = $this->getMocks();
|
||||||
|
|
||||||
$request->expects($this->once())
|
$request->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
|
@ -191,7 +198,7 @@ class ControllerTest extends TestCase
|
||||||
|
|
||||||
$config->set('api_key', 'fooBar!');
|
$config->set('api_key', 'fooBar!');
|
||||||
|
|
||||||
$controller = new Controller($response, $engine, $config, $request, $stats);
|
$controller = new Controller($response, $engine, $config, $request, $stats, $version);
|
||||||
|
|
||||||
$this->expectException(HttpForbidden::class);
|
$this->expectException(HttpForbidden::class);
|
||||||
$this->expectExceptionMessage(json_encode(['error' => 'The api_key is invalid']));
|
$this->expectExceptionMessage(json_encode(['error' => 'The api_key is invalid']));
|
||||||
|
@ -212,7 +219,8 @@ class ControllerTest extends TestCase
|
||||||
/** @var Stats|MockObject $stats */
|
/** @var Stats|MockObject $stats */
|
||||||
$stats = $this->createMock(Stats::class);
|
$stats = $this->createMock(Stats::class);
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
|
$version = $this->createMock(Version::class);
|
||||||
|
|
||||||
return [$response, $request, $engine, $stats, $config];
|
return [$response, $request, $engine, $stats, $config, $version];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
0.42.0-testing
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Helpers;
|
||||||
|
|
||||||
|
use Engelsystem\Application;
|
||||||
|
use Engelsystem\Helpers\Version;
|
||||||
|
use Engelsystem\Helpers\VersionServiceProvider;
|
||||||
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
||||||
|
|
||||||
|
class VersionServiceProviderTest extends ServiceProviderTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Helpers\VersionServiceProvider::register
|
||||||
|
*/
|
||||||
|
public function testRegister()
|
||||||
|
{
|
||||||
|
$app = new Application();
|
||||||
|
$app->instance('path.storage.app', '/tmp');
|
||||||
|
|
||||||
|
$serviceProvider = new VersionServiceProvider($app);
|
||||||
|
$serviceProvider->register();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey(Version::class, $app->contextual);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Helpers;
|
||||||
|
|
||||||
|
use Engelsystem\Config\Config;
|
||||||
|
use Engelsystem\Helpers\Version;
|
||||||
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
||||||
|
|
||||||
|
class VersionTest extends ServiceProviderTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Helpers\Version::__construct
|
||||||
|
* @covers \Engelsystem\Helpers\Version::getVersion
|
||||||
|
*/
|
||||||
|
public function testGetVersion()
|
||||||
|
{
|
||||||
|
$config = new Config();
|
||||||
|
$version = new Version(__DIR__ . '/Stub', $config);
|
||||||
|
|
||||||
|
$this->assertEquals('n/a', $version->getVersion());
|
||||||
|
|
||||||
|
$version = new Version(__DIR__ . '/Stub/files', $config);
|
||||||
|
$this->assertEquals('0.42.0-testing', $version->getVersion());
|
||||||
|
|
||||||
|
$config->set('version', '1.2.3-dev');
|
||||||
|
$this->assertEquals('1.2.3-dev', $version->getVersion());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue