Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .docker-it/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ---it--- multi-stage build

# ----------------------------------------------------------
# Node
FROM node:14-alpine AS node-stage
WORKDIR /app
COPY package* ./
RUN npm install
#RUN npm ci
#COPY .docker-it/node ./.docker-it/node
COPY assets ./assets
#RUN npm run sass
COPY Gruntfile.js ./
RUN npm run build

# ----------------------------------------------------------
# PHP
FROM php:7.3-fpm AS php-stage

ARG BUILD_ENV=production
ENV BUILD_ENV=$BUILD_ENV

# Install git for composer, locales for intl extension
RUN apt-get update && \
apt-get install -y git locales-all

# Install project's required extensions (https://github.com/mlocati/docker-php-extension-installer)
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions gd intl mysqli imagick opcache zip redis

RUN if [ "$BUILD_ENV" = "development" ] ; then install-php-extensions xdebug-^2 ; fi

# php.ini development vs production
RUN mv "$PHP_INI_DIR/php.ini-$BUILD_ENV" "$PHP_INI_DIR/php.ini"
# + custom php.ini
COPY .docker-it/php/conf.d/php.ini "$PHP_INI_DIR/conf.d/"

# test ENV
# https://vsupalov.com/docker-build-pass-environment-variables/
RUN if [ "$BUILD_ENV" = "development" ] ; then touch /_is_build_dev.txt ; else touch /_is_build_prod.txt ; fi
RUN echo "BUILD_ENV is: $BUILD_ENV" >> /_BUILD_ENV.txt

WORKDIR /var/www/html

# Install and run composer
# (according to composer image doc: "(optimal) create your own build image and install Composer inside it.")
RUN install-php-extensions @composer-2
COPY composer.* ./
RUN composer install --no-interaction

# Copy node built artifacts
COPY --from=node-stage /app/assets ./assets

# Copy source code
COPY . .

# Set rw permissions for www-data to logs folder
RUN chown www-data:www-data application/logs

# Set rw permissions for www-data to these mount points
#RUN mkdir uploads && chown www-data:www-data uploads
#RUN mkdir cache && chown www-data:www-data cache

# ----------------------------------------------------------
# Nginx
FROM nginx:1.25 AS nginx-stage
COPY ./.docker-it/nginx/templates /etc/nginx/templates
COPY --from=php-stage /var/www/html /var/www/html
30 changes: 30 additions & 0 deletions .docker-it/nginx/templates/default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/
# https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/
server {
server_name ${APP_DOMAIN};

root /var/www/html;
index index.html index.php;
client_max_body_size 16M;

# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
# route to index.php if the asset is not found
try_files $uri $uri/ /index.php;
}

location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}

location ~* \.php$ {
fastcgi_pass php.${COMPOSE_PROJECT_NAME}_default:9000; # use the php container to interpret PHP files
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_read_timeout ${NGINX_TIMEOUT};
}
}
3 changes: 3 additions & 0 deletions .docker-it/php/conf.d/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
post_max_size=16M
upload_max_filesize=15M
max_execution_time=${PHP_TIMEOUT}
4 changes: 4 additions & 0 deletions .docker-it/php/conf.d/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
xdebug.remote_host=${XDEBUG_REMOTE_HOST}
xdebug.remote_port=${XDEBUG_REMOTE_PORT}
xdebug.remote_enable=1
xdebug.remote_autostart=1
13 changes: 13 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
APP_ENV=development # development / production
APP_DOMAIN=invoiceplane_it.localhost
APP_DOMAIN_LAN=invoiceplane_it-192-168-1-10.devns.me # https://devns.me/
APP_DOMAIN_WAN=SUBDOMAIN.ngrok-free.app # https://ngrok.com/
#APP_HOST_PORT=80 # optional, for direct map to localhost instead of traefik
PROXY_NETWORK=traefik_network
DB_DATABASE=invoiceplane_it
DB_ROOT_PASSWORD=test
#DB_HOST_PORT=3306 # optional, for direct map to localhost instead of traefik
XDEBUG_REMOTE_HOST=host.docker.internal
XDEBUG_REMOTE_PORT=9003
#NGINX_TIMEOUT=180 # optional
#PHP_TIMEOUT=300 # optional
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ adminer.php
/nbproject
/.php_cs.cache
/doc

# ---it---inizio
/.env
/.vscode/launch.json
# ---it---fine
27 changes: 27 additions & 0 deletions .vscode/launch.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9000,
"xdebugSettings": {
"max_data": -1
}
},
{
"name": "Listen for Xdebug on Docker",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}"
},
"hostname": "localhost",
"xdebugSettings": {
"max_data": -1
}
}
]
}
43 changes: 43 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"files.associations": {
"*.php.example": "php"
},
"search.exclude": {
"application/logs": true
},
"intelephense.files.exclude": [
"**/.git/**",
"**/.svn/**",
"**/.hg/**",
"**/CVS/**",
"**/.DS_Store/**",
"**/node_modules/**",
"**/bower_components/**",
"**/vendor/**/{Tests,tests}/**",
"**/.history/**",
"**/vendor/**/vendor/**",
"application/logs/**"
],
// https://code.visualstudio.com/docs/containers/docker-compose#_command-customization
"containers.commands.composeUp": [
{
"label": "Compose Up (override)",
"template": "${composeCommand} -f docker-compose-it.yml ${configurationFile} up ${detached} ${build}",
"match": "-it.override|-it.dev|-it.prod"
}
],
"containers.commands.composeUpSubset": [
{
"label": "Compose Up (override)",
"template": "${composeCommand} -f docker-compose-it.yml ${configurationFile} up ${detached} ${build} ${serviceList}",
"match": "-it.override|-it.dev|-it.prod"
}
],
"containers.commands.composeDown": [
{
"label": "Compose Down (override)",
"template": "${composeCommand} -f docker-compose-it.yml ${configurationFile} down",
"match": "-it.override|-it.dev|-it.prod"
}
]
}
7 changes: 0 additions & 7 deletions cmd/compile-scss-watch.cmd

This file was deleted.

8 changes: 0 additions & 8 deletions cmd/compile-scss.cmd

This file was deleted.

6 changes: 0 additions & 6 deletions cmd/grunt-dev-build.cmd

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/init-composer.cmd

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/init-npm.cmd

This file was deleted.

1 change: 0 additions & 1 deletion composer_install.cmd

This file was deleted.

78 changes: 78 additions & 0 deletions docker-compose-it.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
services:
web:
build:
dockerfile: .docker-it/Dockerfile
args:
BUILD_ENV: development # for php-stage used by nginx-stage
volumes:
- ./assets:/var/www/html/assets
networks:
default:
aliases: # https://community.traefik.io/t/12673 (not needed when really online)
- ${APP_DOMAIN}
- ${APP_DOMAIN_LAN}
ports:
- ${APP_HOST_PORT-}:80
labels: # support for traefik.me or ngrok
- traefik.http.routers.${COMPOSE_PROJECT_NAME}-web-dev.rule=Host(`${APP_DOMAIN_LAN}`) || Host(`${APP_DOMAIN_WAN}`)
- traefik.http.routers.${COMPOSE_PROJECT_NAME}-web-dev-https.rule=Host(`${APP_DOMAIN_LAN}`) || Host(`${APP_DOMAIN_WAN}`)
- traefik.http.routers.${COMPOSE_PROJECT_NAME}-web-dev-https.tls=true
php:
build:
dockerfile: .docker-it/Dockerfile
args:
BUILD_ENV: development
volumes:
- ./.docker-it/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
- ./application:/var/www/html/application
#- ./system:/var/www/html/system
- ./assets:/var/www/html/assets
#- ./sql:/var/www/html/sql
- ./index.php:/var/www/html/index.php
- ./composer.json:/var/www/html/composer.json
- ./composer.lock:/var/www/html/composer.lock
- ./ipconfig.php:/var/www/html/ipconfig.php
environment:
- XDEBUG_REMOTE_HOST
- XDEBUG_REMOTE_PORT
depends_on:
- node
command: sh -c "composer install --no-interaction
&& chown -R www-data:www-data application/logs
&& php-fpm"
node:
#image: node:14-alpine
build:
context: ./
dockerfile: .docker-it/Dockerfile
target: node-stage
volumes:
- ./:/app
#working_dir: /app
#command: sh -c "npm ci && npm run dev" # ("tail -f /dev/null" to keep running without watching)
command: sh -c "npm install && npm run build"
db:
volumes:
- ./.docker-it/mysql/initdb:/docker-entrypoint-initdb.d
ports:
- ${DB_HOST_PORT-}:3306
phpmyadmin:
image: phpmyadmin:5
environment:
- PMA_HOST=db.${COMPOSE_PROJECT_NAME}_default
networks:
- default
- proxy
labels:
- traefik.enable=true
- traefik.http.routers.${COMPOSE_PROJECT_NAME}-pma.rule=Host(`pma.${APP_DOMAIN}`)
#redis-admin:
# image: s2software/redis-admin
# environment:
# - REDIS_HOST=redis.${COMPOSE_PROJECT_NAME}_default
# networks:
# - default
# - proxy
# labels:
# - traefik.enable=true
# - traefik.http.routers.${COMPOSE_PROJECT_NAME}-ra.rule=Host(`ra.${APP_DOMAIN}`)
69 changes: 69 additions & 0 deletions docker-compose-it.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
services:
web:
#image: nginx:1.25.0
build:
context: ./
dockerfile: .docker-it/Dockerfile
target: nginx-stage
environment:
- APP_DOMAIN
- COMPOSE_PROJECT_NAME
- NGINX_TIMEOUT=${NGINX_TIMEOUT-180}
depends_on:
- php
networks:
- default
- proxy
#volumes:
# - uploads:/var/www/html/uploads
# - cache:/var/www/html/cache
labels: # cross project Traefik (s2s/docker-tools/traefik)
- traefik.enable=true
- traefik.http.routers.${COMPOSE_PROJECT_NAME}-web.rule=Host(`${APP_DOMAIN}`)
- traefik.http.routers.${COMPOSE_PROJECT_NAME}-web-https.rule=Host(`${APP_DOMAIN}`)
- traefik.http.routers.${COMPOSE_PROJECT_NAME}-web-https.tls=true
php:
#image: php:7.3-fpm
build:
context: ./
dockerfile: .docker-it/Dockerfile
target: php-stage
environment:
- CI_ENV=${APP_ENV}
- PHP_TIMEOUT=${PHP_TIMEOUT-300}
#volumes:
# - uploads:/var/www/html/uploads
# - cache:/var/www/html/cache
depends_on:
- db
db:
image: mysql:5.7
volumes:
- database:/var/lib/mysql
# https://stackoverflow.com/questions/40425568/incorrect-datetime-value-0000-00-00-000000-date-sub-in-having
# https://github.com/docker-library/mysql/issues/541
command: --sql-mode= --character-set-server=utf8 --collation-server=utf8_general_ci
environment:
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
#redis:
# image: redis:5-alpine
# volumes:
# - redis_data:/data
#localstack:
# extends:
# file: docker-compose-localstack.yml
# service: localstack

volumes:
database:
#uploads:
#cache:
#redis_data:
#localstack_data:

networks:
default:
proxy:
name: ${PROXY_NETWORK}
external: true
Loading
Loading