Skip to content
Snippets Groups Projects
Commit 01a52476 authored by Fabrice Gangler's avatar Fabrice Gangler :art:
Browse files

feat: display software version

parent d912b5d6
No related branches found
No related tags found
No related merge requests found
Pipeline #76564 failed
...@@ -370,7 +370,8 @@ php8.1_release-build: ...@@ -370,7 +370,8 @@ php8.1_release-build:
- echo "${CI_PROJECT_TITLE}" >> "${PHP_WEBAPP_DIR}/README.txt" - echo "${CI_PROJECT_TITLE}" >> "${PHP_WEBAPP_DIR}/README.txt"
- echo "${DOC_URL}" >> "${PHP_WEBAPP_DIR}/README.txt" - echo "${DOC_URL}" >> "${PHP_WEBAPP_DIR}/README.txt"
- echo "APP_ENV=prod" > "${PHP_WEBAPP_DIR}/.env.local" - echo "APP_ENV=prod" > "${PHP_WEBAPP_DIR}/.env.local"
- sed -i "s/major.minor.patch/${CI_COMMIT_TAG}/" "${PHP_WEBAPP_DIR}/config/services.yaml" - sed -i "s/version_major.minor.patch/${CI_COMMIT_TAG}/" "${PHP_WEBAPP_DIR}/.env"
# - sed -i "s/version_major.minor.patch/${CI_COMMIT_TAG}/" "${PHP_WEBAPP_DIR}/config/services.yaml"
- cat "${PHP_WEBAPP_DIR}/config/services.yaml" - cat "${PHP_WEBAPP_DIR}/config/services.yaml"
- mkdir -p "${CI_PROJECT_DIR}/build-result/${BUILD_NAME}" - mkdir -p "${CI_PROJECT_DIR}/build-result/${BUILD_NAME}"
- mkdir -p "${CI_PROJECT_DIR}/build-result/${BUILD_NAME}/bin" - mkdir -p "${CI_PROJECT_DIR}/build-result/${BUILD_NAME}/bin"
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
# - APP_SECRET Application secret to generate CSRF tokens # - APP_SECRET Application secret to generate CSRF tokens
# - DATABASE_URL Database configuration (PostgreSQL) # - DATABASE_URL Database configuration (PostgreSQL)
# - MAILER_DSN SMTP configuration # - MAILER_DSN SMTP configuration
########################################################################################################################
# - WEBAPP_DEFAULT_URI Default URI used to generate URLs in a non-HTTP context # - WEBAPP_DEFAULT_URI Default URI used to generate URLs in a non-HTTP context
# - WEBAPP_EMAIL_FROM Sender's email address to send emails from the web application # - WEBAPP_EMAIL_FROM Sender's email address to send emails from the web application
# - WEBAPP_EMAIL_ALERTING_TO Email address for alert notifications (web application not working properly, ...) # - WEBAPP_EMAIL_ALERTING_TO Email address for alert notifications (web application not working properly, ...)
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
####################################################################################################################### #######################################################################################################################
# - WEBAPP_USER_CONFIG_RESET_PASSWORD_TOKEN_LIFETIME Lifetime of reset password token in seconds (default: 1200 = 20 minutes). # - WEBAPP_USER_CONFIG_RESET_PASSWORD_TOKEN_LIFETIME Lifetime of reset password token in seconds (default: 1200 = 20 minutes).
# - WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH Minimum user password length (default: 12) # - WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH Minimum user password length (default: 12)
# - WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY Public display of software version (default: true)
####################################################################################################################### #######################################################################################################################
###> symfony/framework-bundle ### ###> symfony/framework-bundle ###
...@@ -80,6 +82,7 @@ WEBAPP_SESSION_LIFETIME=3600 ...@@ -80,6 +82,7 @@ WEBAPP_SESSION_LIFETIME=3600
WEBAPP_TIMEZONE='Europe/Paris' WEBAPP_TIMEZONE='Europe/Paris'
WEBAPP_USER_CONFIG_PASSWORD_RESET_TOKEN_LIFETIME=1200 WEBAPP_USER_CONFIG_PASSWORD_RESET_TOKEN_LIFETIME=1200
WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH=12 WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH=12
WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY=true
####################################################################### #######################################################################
# Webapp - List of allowed domains and IP to prevent HTTP Host header attacks # Webapp - List of allowed domains and IP to prevent HTTP Host header attacks
...@@ -100,3 +103,15 @@ WEBAPP_TRUSTED_HOSTS='' ...@@ -100,3 +103,15 @@ WEBAPP_TRUSTED_HOSTS=''
# Only allow incoming requests for all subdomains of example.org # Only allow incoming requests for all subdomains of example.org
# WEBAPP_TRUSTED_HOSTS='^(.+\.)?example\.org$' # WEBAPP_TRUSTED_HOSTS='^(.+\.)?example\.org$'
################################################################################################## ##################################################################################################
#######################################################################################################################
#######################################################################################################################
# We strongly recommend leaving the following environment variables unchanged
SOFTWARE_NAME='Comptoir'
SOFTWARE_RELEASE='version_major.minor.patch'
##################################################################################################
# Do not modify if you have not identified
# the technical implications: HTTP headers using theses values, ...
##################################################################################################
...@@ -62,4 +62,15 @@ MAILER_DSN=smtp://127.0.0.1:1025 ...@@ -62,4 +62,15 @@ MAILER_DSN=smtp://127.0.0.1:1025
# error 500 ---> Connection could not be established with host "0.0.0.0:9091": # error 500 ---> Connection could not be established with host "0.0.0.0:9091":
# stream_socket_client(): unable to connect to 0.0.0.0:9091 (Connection refused) # stream_socket_client(): unable to connect to 0.0.0.0:9091 (Connection refused)
################################################################################################## ##################################################################################################
#######################################################################
#######################################################################################################################
#######################################################################################################################
# We strongly recommend leaving the following environment variables unchanged
SOFTWARE_NAME='Comptoir-DEV-Software'
##################################################################################################
# Do not modify if you have not identified
# the technical implications: HTTP headers using this value, ...
##################################################################################################
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
# - APP_SECRET Application secret to generate CSRF tokens # - APP_SECRET Application secret to generate CSRF tokens
# - DATABASE_URL Database configuration (PostgreSQL) # - DATABASE_URL Database configuration (PostgreSQL)
# - MAILER_DSN SMTP configuration # - MAILER_DSN SMTP configuration
######################################################################################################################## - WEBAPP_DEFAULT_URI Default URI used to generate URLs in a non-HTTP context ########################################################################################################################
# - WEBAPP_DEFAULT_URI Default URI used to generate URLs in a non-HTTP context
# - WEBAPP_EMAIL_FROM Sender's email address to send emails from the web application # - WEBAPP_EMAIL_FROM Sender's email address to send emails from the web application
# - WEBAPP_EMAIL_ALERTING_TO Email address for alert notifications (web application not working properly, ...) # - WEBAPP_EMAIL_ALERTING_TO Email address for alert notifications (web application not working properly, ...)
# - WEBAPP_NAME Name of web application displayed to users # - WEBAPP_NAME Name of web application displayed to users
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
####################################################################################################################### #######################################################################################################################
# - WEBAPP_USER_CONFIG_RESET_PASSWORD_TOKEN_LIFETIME Lifetime of reset password token in seconds (default: 1200 = 20 minutes). # - WEBAPP_USER_CONFIG_RESET_PASSWORD_TOKEN_LIFETIME Lifetime of reset password token in seconds (default: 1200 = 20 minutes).
# - WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH Minimum user password length (default: 12) # - WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH Minimum user password length (default: 12)
# - WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY Public display of software version (default: true)
####################################################################################################################### #######################################################################################################################
# Environment # Environment
...@@ -106,4 +108,7 @@ WEBAPP_USER_CONFIG_PASSWORD_RESET_TOKEN_LIFETIME=1200 ...@@ -106,4 +108,7 @@ WEBAPP_USER_CONFIG_PASSWORD_RESET_TOKEN_LIFETIME=1200
# Minimum user password length # Minimum user password length
WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH=12 WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH=12
# Public display of software version (default: true)
WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY=true
####################################################################################################################### #######################################################################################################################
...@@ -18,3 +18,16 @@ WEBAPP_I18N_DEFAULT_LOCALE='en' ...@@ -18,3 +18,16 @@ WEBAPP_I18N_DEFAULT_LOCALE='en'
####################################################################### #######################################################################
MAILER_DSN=null://null MAILER_DSN=null://null
####################################################################### #######################################################################
#######################################################################################################################
#######################################################################################################################
# We strongly recommend leaving the following environment variables unchanged
# We strongly recommend leaving the following environment variables unchanged
SOFTWARE_NAME='Comptoir-TEST-Software'
##################################################################################################
# Do not modify if you have not identified
# the technical implications: HTTP headers using this value, ...
##################################################################################################
...@@ -2,6 +2,10 @@ twig: ...@@ -2,6 +2,10 @@ twig:
file_name_pattern: '*.twig' file_name_pattern: '*.twig'
globals: globals:
app_name: '%env(WEBAPP_NAME)%' app_name: '%env(WEBAPP_NAME)%'
app_shortname: '%env(WEBAPP_SHORTNAME)%'
software_name: '%env(SOFTWARE_NAME)%'
software_release: '%env(SOFTWARE_RELEASE)%'
software_release_allow_public_display: '%env(bool:WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY)%'
when@test: when@test:
twig: twig:
......
...@@ -10,7 +10,10 @@ parameters: ...@@ -10,7 +10,10 @@ parameters:
app.shortname: '%env(WEBAPP_SHORTNAME)%' app.shortname: '%env(WEBAPP_SHORTNAME)%'
app.email.alerting_to: '%env(WEBAPP_EMAIL_ALERTING_TO)%' app.email.alerting_to: '%env(WEBAPP_EMAIL_ALERTING_TO)%'
app.email.from: '%env(WEBAPP_EMAIL_FROM)%' app.email.from: '%env(WEBAPP_EMAIL_FROM)%'
app.software.name: 'Comptoir' app.software.name: '%env(SOFTWARE_NAME)%'
app.software.release: '%env(SOFTWARE_RELEASE)%'
app.software.release.display.public: '%env(bool:WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY)%'
services: services:
# default configuration for services in *this* file # default configuration for services in *this* file
_defaults: _defaults:
......
...@@ -37,7 +37,10 @@ class HealthCheckController extends AbstractController ...@@ -37,7 +37,10 @@ class HealthCheckController extends AbstractController
)] )]
public function healthCheck(Request $request, Connection $dbConnection): Response public function healthCheck(Request $request, Connection $dbConnection): Response
{ {
$displayRelease = $this->getParameter('app.software.release.display.public');
$softwareRelease = $this->getParameter('app.software.release');
$softwareName = $this->getParameter('app.software.name'); $softwareName = $this->getParameter('app.software.name');
$httpCode = Response::HTTP_OK; $httpCode = Response::HTTP_OK;
$dbStatusCode = "SUCCESSFUL"; $dbStatusCode = "SUCCESSFUL";
try { try {
...@@ -47,10 +50,13 @@ public function healthCheck(Request $request, Connection $dbConnection): Respons ...@@ -47,10 +50,13 @@ public function healthCheck(Request $request, Connection $dbConnection): Respons
$dbStatusCode = "FAILED"; $dbStatusCode = "FAILED";
} }
$slugSoftwareName = strtolower((new AsciiSlugger())->slug("$softwareName")->toString()) ; $slugSoftwareName = strtolower((new AsciiSlugger())->slug("$softwareName")->toString());
$headers = [ $headers = [];
"x-$slugSoftwareName-database-status" => "DB_CONNECTION_$dbStatusCode", $headers["x-$slugSoftwareName-database-status"] = "DB_CONNECTION_$dbStatusCode";
]; if($displayRelease === true){
$headers["x-$slugSoftwareName-version"] = $softwareRelease;
}
if ($request->getMethod() === "HEAD") { if ($request->getMethod() === "HEAD") {
return new Response(status: $httpCode, headers: $headers); return new Response(status: $httpCode, headers: $headers);
} else { } else {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
{% block body %} {% block body %}
{% set db_status_cssClass = 'table-danger' %} {% set db_status_cssClass = 'table-danger' %}
{% set db_status_i18n = 'public.health-check.status.failed'|trans %} {% set db_status_i18n = 'public.health-check.status.failed'|trans %}
{% if dbStatusCode == 'SUCCESSFUL' %} {% if dbStatusCode == 'SUCCESSFUL' %}
...@@ -34,4 +35,11 @@ ...@@ -34,4 +35,11 @@
</table> </table>
</div> </div>
<hr>
{% if software_release_allow_public_display == true %}
{{ software_name }} <strong>{{ software_release }} </strong>
{% endif %}
{% endblock %} {% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment