Skip to content

Commit 538b01b

Browse files
authored
Alternative Docker support (it)
1 parent d0321f5 commit 538b01b

18 files changed

Lines changed: 656 additions & 245 deletions

.docker-it/Dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# ---it--- multi-stage build
2+
3+
# ----------------------------------------------------------
4+
# Node
5+
FROM node:14-alpine AS node-stage
6+
WORKDIR /app
7+
COPY package* ./
8+
RUN npm install
9+
#RUN npm ci
10+
#COPY .docker-it/node ./.docker-it/node
11+
COPY assets ./assets
12+
#RUN npm run sass
13+
COPY Gruntfile.js ./
14+
RUN npm run build
15+
16+
# ----------------------------------------------------------
17+
# PHP
18+
FROM php:7.3-fpm AS php-stage
19+
20+
ARG BUILD_ENV=production
21+
ENV BUILD_ENV=$BUILD_ENV
22+
23+
# Install git for composer, locales for intl extension
24+
RUN apt-get update && \
25+
apt-get install -y git locales-all
26+
27+
# Install project's required extensions (https://github.com/mlocati/docker-php-extension-installer)
28+
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
29+
RUN chmod +x /usr/local/bin/install-php-extensions && \
30+
install-php-extensions gd intl mysqli imagick opcache zip redis
31+
32+
RUN if [ "$BUILD_ENV" = "development" ] ; then install-php-extensions xdebug-^2 ; fi
33+
34+
# php.ini development vs production
35+
RUN mv "$PHP_INI_DIR/php.ini-$BUILD_ENV" "$PHP_INI_DIR/php.ini"
36+
# + custom php.ini
37+
COPY .docker-it/php/conf.d/php.ini "$PHP_INI_DIR/conf.d/"
38+
39+
# test ENV
40+
# https://vsupalov.com/docker-build-pass-environment-variables/
41+
RUN if [ "$BUILD_ENV" = "development" ] ; then touch /_is_build_dev.txt ; else touch /_is_build_prod.txt ; fi
42+
RUN echo "BUILD_ENV is: $BUILD_ENV" >> /_BUILD_ENV.txt
43+
44+
WORKDIR /var/www/html
45+
46+
# Install and run composer
47+
# (according to composer image doc: "(optimal) create your own build image and install Composer inside it.")
48+
RUN install-php-extensions @composer-2
49+
COPY composer.* ./
50+
RUN composer install --no-interaction
51+
52+
# Copy node built artifacts
53+
COPY --from=node-stage /app/assets ./assets
54+
55+
# Copy source code
56+
COPY . .
57+
58+
# Set rw permissions for www-data to logs folder
59+
RUN chown www-data:www-data application/logs
60+
61+
# Set rw permissions for www-data to these mount points
62+
#RUN mkdir uploads && chown www-data:www-data uploads
63+
#RUN mkdir cache && chown www-data:www-data cache
64+
65+
# ----------------------------------------------------------
66+
# Nginx
67+
FROM nginx:1.25 AS nginx-stage
68+
COPY ./.docker-it/nginx/templates /etc/nginx/templates
69+
COPY --from=php-stage /var/www/html /var/www/html
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/
2+
# https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/
3+
server {
4+
server_name ${APP_DOMAIN};
5+
6+
root /var/www/html;
7+
index index.html index.php;
8+
client_max_body_size 16M;
9+
10+
# set expiration of assets to MAX for caching
11+
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
12+
expires max;
13+
log_not_found off;
14+
# route to index.php if the asset is not found
15+
try_files $uri $uri/ /index.php;
16+
}
17+
18+
location / {
19+
# Check if a file or directory index file exists, else route it to index.php.
20+
try_files $uri $uri/ /index.php;
21+
}
22+
23+
location ~* \.php$ {
24+
fastcgi_pass php.${COMPOSE_PROJECT_NAME}_default:9000; # use the php container to interpret PHP files
25+
include fastcgi_params;
26+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
27+
fastcgi_param PATH_INFO $fastcgi_path_info;
28+
fastcgi_read_timeout ${NGINX_TIMEOUT};
29+
}
30+
}

.docker-it/php/conf.d/php.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
post_max_size=16M
2+
upload_max_filesize=15M
3+
max_execution_time=${PHP_TIMEOUT}

.docker-it/php/conf.d/xdebug.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
xdebug.remote_host=${XDEBUG_REMOTE_HOST}
2+
xdebug.remote_port=${XDEBUG_REMOTE_PORT}
3+
xdebug.remote_enable=1
4+
xdebug.remote_autostart=1

.env.template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
APP_ENV=development # development / production
2+
APP_DOMAIN=invoiceplane_it.localhost
3+
APP_DOMAIN_LAN=invoiceplane_it-192-168-1-10.devns.me # https://devns.me/
4+
APP_DOMAIN_WAN=SUBDOMAIN.ngrok-free.app # https://ngrok.com/
5+
#APP_HOST_PORT=80 # optional, for direct map to localhost instead of traefik
6+
PROXY_NETWORK=traefik_network
7+
DB_DATABASE=invoiceplane_it
8+
DB_ROOT_PASSWORD=test
9+
#DB_HOST_PORT=3306 # optional, for direct map to localhost instead of traefik
10+
XDEBUG_REMOTE_HOST=host.docker.internal
11+
XDEBUG_REMOTE_PORT=9003
12+
#NGINX_TIMEOUT=180 # optional
13+
#PHP_TIMEOUT=300 # optional

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ adminer.php
1818
/nbproject
1919
/.php_cs.cache
2020
/doc
21+
22+
# ---it---inizio
23+
/.env
24+
/.vscode/launch.json
25+
# ---it---fine

.vscode/launch.json.example

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Listen for Xdebug",
6+
"type": "php",
7+
"request": "launch",
8+
"port": 9000,
9+
"xdebugSettings": {
10+
"max_data": -1
11+
}
12+
},
13+
{
14+
"name": "Listen for Xdebug on Docker",
15+
"type": "php",
16+
"request": "launch",
17+
"port": 9003,
18+
"pathMappings": {
19+
"/var/www/html": "${workspaceFolder}"
20+
},
21+
"hostname": "localhost",
22+
"xdebugSettings": {
23+
"max_data": -1
24+
}
25+
}
26+
]
27+
}

.vscode/settings.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"files.associations": {
3+
"*.php.example": "php"
4+
},
5+
"search.exclude": {
6+
"application/logs": true
7+
},
8+
"intelephense.files.exclude": [
9+
"**/.git/**",
10+
"**/.svn/**",
11+
"**/.hg/**",
12+
"**/CVS/**",
13+
"**/.DS_Store/**",
14+
"**/node_modules/**",
15+
"**/bower_components/**",
16+
"**/vendor/**/{Tests,tests}/**",
17+
"**/.history/**",
18+
"**/vendor/**/vendor/**",
19+
"application/logs/**"
20+
],
21+
// https://code.visualstudio.com/docs/containers/docker-compose#_command-customization
22+
"containers.commands.composeUp": [
23+
{
24+
"label": "Compose Up (override)",
25+
"template": "${composeCommand} -f docker-compose-it.yml ${configurationFile} up ${detached} ${build}",
26+
"match": "-it.override|-it.dev|-it.prod"
27+
}
28+
],
29+
"containers.commands.composeUpSubset": [
30+
{
31+
"label": "Compose Up (override)",
32+
"template": "${composeCommand} -f docker-compose-it.yml ${configurationFile} up ${detached} ${build} ${serviceList}",
33+
"match": "-it.override|-it.dev|-it.prod"
34+
}
35+
],
36+
"containers.commands.composeDown": [
37+
{
38+
"label": "Compose Down (override)",
39+
"template": "${composeCommand} -f docker-compose-it.yml ${configurationFile} down",
40+
"match": "-it.override|-it.dev|-it.prod"
41+
}
42+
]
43+
}

cmd/compile-scss-watch.cmd

Lines changed: 0 additions & 7 deletions
This file was deleted.

cmd/compile-scss.cmd

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)