Gestita compilazione multistage in docker

This commit is contained in:
2025-01-27 09:49:20 +01:00
parent 553c5e655d
commit c5f190f6b9
14 changed files with 433 additions and 895 deletions

8
.dockerignore Normal file
View File

@@ -0,0 +1,8 @@
.git*
.idea
.env
.eslint*
**/node_modules/
**/dist
**/cache
docker-compose.yml

View File

@@ -1,4 +1,4 @@
APP_ENV=DEV
NODE_ENV=development
AZIENDA=integry
ENABLED_PROFILES=

View File

@@ -1,6 +1,91 @@
FROM php:7.4-fpm
# syntax=docker/dockerfile:1
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
ARG NODE_VERSION="20"
ARG PHP_VERSION="7.4"
ARG AZIENDA="INTEGRY"
ARG NODE_ENV="production"
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions gd opcache xdebug imagick zip
# Compilatore js
FROM node:${NODE_VERSION}-alpine AS builder
WORKDIR /app
COPY . .
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
RUN npm install \
&& npm run build
RUN ./build.sh
# Unzip compilati
FROM alpine AS exports
ARG AZIENDA
ENV AZIENDA=$AZIENDA
COPY --from=builder app/exports/_base.zip .
RUN unzip _base.zip -d ./unzip
COPY --from=builder app/exports/${AZIENDA}.zip .
RUN unzip ${AZIENDA}.zip -d ./unzip
# Immagine finale
FROM php:${PHP_VERSION}-apache-bullseye AS final
ARG AZIENDA
ENV AZIENDA=$AZIENDA
ENV SERVICES_BASE_URL="http://192.168.2.18:8080"
ENV PUBLIC_URL="http://192.168.2.18/pvm"
# Enable Apache modules to ensure proper functionality
RUN a2enmod rewrite
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
COPY docker/php/php.ini $PHP_INI_DIR/php.ini
# Imposto la lingua delle date
ENV LC_TIME=it_IT.UTF-8
RUN apt-get update && apt-get install -y --no-install-recommends locales \
&& apt-get clean \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
&& echo it_IT.UTF-8 UTF-8 >> /etc/locale.gen \
&& locale-gen
RUN install-php-extensions \
gd \
imagick \
zip
COPY docker/apache/000-default.conf $APACHE_CONFDIR/sites-available/000-default.conf
WORKDIR /var/www/html
FROM final AS final-dev
COPY docker/php/conf.d/error_reporting.ini /usr/local/etc/php/conf.d/error_reporting.ini
RUN install-php-extensions xdebug
COPY docker/php/conf.d/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
COPY --from=builder app ./pvm
RUN touch pvm/.env \
&& printenv | sed 's/\(^[^=]*\)=\(.*\)/\1="\2"/' > pvm/.env
EXPOSE 80
EXPOSE 9003
FROM final AS final-prod
RUN install-php-extensions opcache
COPY --from=exports unzip .
RUN touch .env \
&& printenv | sed 's/\(^[^=]*\)=\(.*\)/\1="\2"/' > .env
EXPOSE 80

View File

@@ -226,7 +226,7 @@ module.exports = function (grunt) {
timestamp: date.getTime()
}
};
grunt.file.write("public_html/build.json", JSON.stringify(build));
grunt.file.write("exports/tmp/build.json", JSON.stringify(build));
});
_arr_aziende.forEach(azienda => {
let nomeAzienda = azienda.n.toLowerCase();

5
build.sh Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
if [ "${NODE_ENV}" = "production" ]; then
npm run grunt -- BuildAll
fi

View File

@@ -1,23 +1,12 @@
version: "3.9"
services:
php-fpm:
php-apache:
restart: unless-stopped
extra_hosts:
- host.docker.internal:host-gateway
build: ./
volumes:
- ./:/var/www/html/pvm
- ./docker/php/php.ini:/usr/local/etc/php/php.ini
- ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
apache:
restart: unless-stopped
build:
context: .
dockerfile: ./docker/apache/Dockerfile
dockerfile: ./Dockerfile
target: final-dev
ports:
- "80:80"
volumes:
- ./:/var/www/html/pvm
depends_on:
- php-fpm
- .:/var/www/html/pvm

View File

@@ -0,0 +1,51 @@
ServerName localhost
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
# ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
# Directory configuration for the DocumentRoot
<Directory /var/www/html/>
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# Proxy PHP requests to port 9000 PHP-FPM container
<IfModule mod_proxy.c>
ProxyTimeout 259200
<FilesMatch \.php$>
Require all granted
SetHandler proxy:fcgi://${PHP_HOST}:${PHP_PORT}
</FilesMatch>
</IfModule>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

View File

@@ -1,15 +0,0 @@
FROM httpd:2.4
COPY ./docker/apache/apache.vhost.conf /usr/local/apache2/conf/extra/apache.vhost.conf
RUN echo "Include /usr/local/apache2/conf/extra/apache.vhost.conf" >> /usr/local/apache2/conf/httpd.conf
# Enable Apache modules to ensure proper functionality
RUN sed -i \
# Uncomment the configuration for mod_deflate to enable compression
-e '/#LoadModule deflate_module/s/^#//g' \
# Uncomment the configuration for mod_proxy to enable proxying capabilities
-e '/#LoadModule proxy_module/s/^#//g' \
# Uncomment the configuration for mod_proxy_fcgi to enable FastCGI proxy module
-e '/#LoadModule proxy_fcgi_module/s/^#//g' \
-e '/#LoadModule rewrite_module/s/^#//g' \
/usr/local/apache2/conf/httpd.conf

View File

@@ -1,30 +0,0 @@
# Set the ServerName to localhost
ServerName localhost
# Configure a VirtualHost to handle requests on port 80
<VirtualHost *:80>
# Proxy PHP requests to port 9000 PHP-FPM container
<IfModule mod_proxy.c>
ProxyTimeout 259200
<FilesMatch \.php$>
Require all granted
SetHandler proxy:fcgi://php-fpm:9000
</FilesMatch>
</IfModule>
# Set the DocumentRoot for the virtual host
DocumentRoot /var/www/html/
# Directory configuration for the DocumentRoot
<Directory /var/www/html/>
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Define the CustomLog and ErrorLog destinations
CustomLog /proc/self/fd/1 common
ErrorLog /proc/self/fd/2
</VirtualHost>

View File

@@ -640,7 +640,7 @@ report_memleaks = On
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order
variables_order = "GPCS"
variables_order = "EGPCS"
; This directive determines which super global data (G,P & C) should be
; registered into the super global array REQUEST. If so, it also determines
@@ -1766,20 +1766,20 @@ ldap.max_links = -1
[opcache]
; Determines if Zend OPCache is enabled
;opcache.enable=1
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
;opcache.enable_cli=0
; The OPcache shared memory storage size.
;opcache.memory_consumption=128
opcache.memory_consumption=128
; The amount of memory for interned strings in Mbytes.
;opcache.interned_strings_buffer=8
opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 1000000 are allowed.
;opcache.max_accelerated_files=10000
opcache.max_accelerated_files=4000
; The maximum percentage of "wasted" memory until a restart is scheduled.
;opcache.max_wasted_percentage=5
@@ -1797,17 +1797,17 @@ ldap.max_links = -1
; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
;opcache.revalidate_freq=2
opcache.revalidate_freq=60
; Enables or disables file search in include_path optimization
;opcache.revalidate_path=0
; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
;opcache.save_comments=1
opcache.save_comments=0
; Allow file existence override (file_exists, etc.) performance feature.
;opcache.enable_file_override=0
opcache.enable_file_override=1
; A bitmask, where each bit enables or disables the appropriate OPcache
; passes

1062
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,17 +8,18 @@
"test": "test"
},
"scripts": {
"postinstall": "node postinstall.js",
"clean": "rimraf public_html/dist",
"lint": "eslint . --fix --cache",
"clean": "del-cli public_html/dist",
"build": "npm run clean && tsc",
"build:watch": "npm run build -- --watch",
"grunt": "grunt",
"lint": "eslint . --fix --cache",
"postinstall": "node postinstall.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"pre-commit": [
"lint"
],
"devDependencies": {
"dependencies": {
"@ihvh/air-datepicker-types": "^2.0.2",
"@types/bootstrap": "^3.3.42",
"@types/chart.js": "^2.9.37",
@@ -29,6 +30,7 @@
"@types/tableau": "^2.2.4",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"del-cli": "^6.0.0",
"eslint": "^8.37.0",
"grunt": "^0.4.5",
"grunt-cli": "^1.2.0",
@@ -52,12 +54,9 @@
"grunt-string-replace": "^1.3.1",
"number-ticker": "file:public_html/assets/number-ticker",
"pre-commit": "^1.2.2",
"rimraf": "^4.4.1",
"sass": "^1.76.0",
"typescript": "~5.0.3"
},
"author": "",
"license": "ISC",
"dependencies": {
"sass": "^1.76.0"
}
"license": "ISC"
}

View File

@@ -1,7 +1,3 @@
if (process.env.NODE_ENV === "production") {
process.exit();
}
const {spawn} = require('child_process');
const cmd = "cd public_html && npm install";

View File

@@ -75,7 +75,7 @@ class PVM {
}
public static function isDevClient() {
return array_key_exists("APP_ENV", $_ENV) ? $_ENV["APP_ENV"] == "DEV" : self::rootFileExists("Gruntfile.js") !== false;
return array_key_exists("NODE_ENV", $_ENV) ? $_ENV["NODE_ENV"] == "development" : self::rootFileExists("Gruntfile.js") !== false;
}
private static function rootFileExists($filename, $upTo = 5) {