diff --git a/Makefile b/Makefile index c5bea87..ebe894e 100644 --- a/Makefile +++ b/Makefile @@ -28,12 +28,12 @@ endif #--- -SERVICE_APP = app1 SERVICE_CADDY = caddy +SERVICE_APP = app1 #--- -WEBSITE_URL = https://website.localhost +WEBSITE_URL = https://dev.website.localhost #--- @@ -105,9 +105,10 @@ help: @echo "║ $(call pad,32) ${YELLOW}.:${RESET} AVAILABLE COMMANDS ${YELLOW}:.${BLACK} $(call pad,32) ║" @echo "║ $(call pad,96) ║" @echo "╚════════════════════════════════════════════════════════════════════════════════════════════════════════╝" + @echo "${BLACK}·${RESET} ${MAGENTA}DOMAIN(s)${BLACK} .... ${CYAN}$(WEBSITE_URL)${BLACK}" + @echo "${BLACK}·${RESET} ${MAGENTA}SERVICE(s)${BLACK} ... ${CYAN}$(SERVICE_CADDY)${BLACK}, ${CYAN}$(SERVICE_APP)${BLACK}" @echo "${BLACK}·${RESET} ${MAGENTA}USER${BLACK} ......... ${WHITE}(${CYAN}$(HOST_USER_ID)${WHITE})${BLACK} ${CYAN}$(HOST_USER_NAME)${BLACK}" @echo "${BLACK}·${RESET} ${MAGENTA}GROUP${BLACK} ........ ${WHITE}(${CYAN}$(HOST_GROUP_ID)${WHITE})${BLACK} ${CYAN}$(HOST_GROUP_NAME)${BLACK}" - @echo "${BLACK}·${RESET} ${MAGENTA}SERVICE(s)${BLACK} ... ${CYAN}$(SERVICE_APP)${BLACK}, ${CYAN}$(SERVICE_CADDY)${BLACK}" @echo "${RESET}" @grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "${BLACK}·${RESET} ${YELLOW}%-35s${RESET} %s\n", $$1, $$2}' @echo "" diff --git a/README.md b/README.md index 4689b1a..49a824d 100644 --- a/README.md +++ b/README.md @@ -167,23 +167,20 @@ The container service logs to `STDOUT` by default. #### Project Structure ```text -├── build # Docker-related configuration files -│ ├── dev -│ │ └── Caddyfile # Caddy's configuration file for development environment -│ ├── prod -│ │ └── Caddyfile # Caddy's configuration file for production environment -│ ├── healthcheck.sh # Shell script for Docker's HEALTHCHECK directive -│ ├── www.conf # PHP-FPM configuration file -│ └── xdebug.ini # xDebug configuration file -├── coverage # Code Coverage HTML report target folder -├── src # PHP application folder -├── caddy-root-ca-authority.crt # Generated certificate file with Caddy Root CA Authority details -├── docker-compose.yml # Docker Compose base file -├── docker-compose-dev.yml # Override Docker Compose file for development environment -├── docker-compose-prod.yml # Override Docker Compose file for production environment +├── build # Docker-related configuration files +│ ├── Caddyfile # Caddy's configuration file +│ ├── healthcheck.sh # Shell script for Docker's HEALTHCHECK directive +│ ├── www.conf # PHP-FPM configuration file +│ └── xdebug.ini # xDebug configuration file +├── coverage # Code Coverage HTML report target folder +├── src # PHP application folder +├── caddy-root-ca-authority.crt # Generated certificate file with Caddy Root CA Authority details +├── docker-compose.yml # Docker Compose base file +├── docker-compose.override.dev.yml # Docker Compose file for development environment +├── docker-compose.override.prod.yml # Docker Compose file for production environment ├── Dockerfile ├── Makefile -└── README.md # This file +└── README.md ``` ##### Volumes @@ -199,13 +196,13 @@ There are some volumes created between the *host* and the container service: > [!NOTE] > -> Review the `docker-compose.yml` and volumes to your convenience. +> Review the `docker-compose.xxx` files and adjust the volumes to your convenience. > [!IMPORTANT] > -> Remember to restart the container service if you make any change in `docker-compose.yml`. +> Remember to rebuild the Docker image if you make any change on `Dockerfile` file. @@ -222,9 +219,10 @@ A *Makefile* is provided with following commands: ║ .: AVAILABLE COMMANDS :. ║ ║ ║ ╚════════════════════════════════════════════════════════════════════════════════════════════════════════╝ +· DOMAIN(s) .... https://dev.website.localhost +· SERVICE(s) ... caddy, app1 · USER ......... (1000) alcidesrc · GROUP ........ (1000) alcidesrc -· SERVICE(s) ... app, caddy · build Docker: builds the service · up Docker: starts the service @@ -253,23 +251,32 @@ This project uses Caddy as main web server which provides HTTPS by default [!TIP] +> +> Any `.localhost` TLD resolves by default to `127.0.0.1` so no any additional action is required on your *host*. > [!NOTE] > -> Review the `build/Caddyfile` and apply the changes based on your preferences. +> You can customize the domain name in `docker-compose.override.xxx.yml` > -> Review the `Makefile` to ensure `WEBSITE_URL` constant has the desired domain URL. +> Review as well the `Makefile` to ensure `WEBSITE_URL` constant has the desired domain name for development environment. > [!IMPORTANT] > -> Remember to restart the container service if you make any change in `build/Caddyfile` file. +> Remember to restart the container service(s) if you make any change on any Docker file. diff --git a/build/Caddyfile b/build/Caddyfile index c28d985..a84b0ab 100644 --- a/build/Caddyfile +++ b/build/Caddyfile @@ -1,7 +1,6 @@ -(generic) { +(common) { encode zstd gzip respond /healthcheck 200 - root * /var/www/html/public file_server } @@ -9,9 +8,26 @@ tls internal } +(cache-security) { + header { + Cache-Control "public, max-age=3600" + } +} + {$HOSTNAME} { - import generic + import common + import cache-security import ssl - php_fastcgi {$PHP_FPM_GATEWAYS} + root * /var/www/html/public + + php_fastcgi {$PHP_FPM_GATEWAYS} { + index index.php + + resolve_root_symlink + + dial_timeout 60s + read_timeout 300s + write_timeout 300s + } } diff --git a/docker-compose.override.dev.yml b/docker-compose.override.dev.yml index 878f3cb..213afcf 100644 --- a/docker-compose.override.dev.yml +++ b/docker-compose.override.dev.yml @@ -1,16 +1,6 @@ services: caddy: environment: - - HOSTNAME=website.localhost - - PHP_FPM_GATEWAYS=app1:9000 app2:9000 + - HOSTNAME=dev.website.localhost healthcheck: - test: ["CMD", "wget", "--spider", "https://website.localhost/healthcheck"] - depends_on: - - app1 - - app2 - - app2: - extends: - file: docker-compose.yml - service: app1 - container_name: app2 + test: ["CMD", "wget", "--spider", "https://dev.website.localhost/healthcheck"] diff --git a/docker-compose.override.prod.yml b/docker-compose.override.prod.yml index 17bb38d..e2378d1 100644 --- a/docker-compose.override.prod.yml +++ b/docker-compose.override.prod.yml @@ -1,6 +1,16 @@ services: caddy: environment: - - HOSTNAME=acme.com + - HOSTNAME=prod.website.localhost + - PHP_FPM_GATEWAYS=app1:9000 app2:9000 healthcheck: - test: ["CMD", "wget", "--spider", "https://acme.com/healthcheck"] + test: ["CMD", "wget", "--spider", "https://prod.website.localhost/healthcheck"] + depends_on: + - app1 + - app2 + + app2: + extends: + file: docker-compose.yml + service: app1 + container_name: app2