Skip to content

Commit

Permalink
build: standarize the domain names
Browse files Browse the repository at this point in the history
  • Loading branch information
AlcidesRC committed Sep 11, 2024
1 parent 76fcfc5 commit bd163dd
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 44 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

#---

Expand Down Expand Up @@ -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 ""
Expand Down
53 changes: 30 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.


Expand All @@ -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 <env=[dev|prod]>
· up Docker: starts the service <env=[dev|prod]>
Expand Down Expand Up @@ -253,23 +251,32 @@ This project uses Caddy as main web server which <u>provides HTTPS by default</u

##### Default Domain

The default website domain is `https://website.localhost`.
The default website domains are:

| Environment | Domain Name |
|---------------|------------------------------------------------------------------|
| `development` | [https://dev.website.localhost](https://dev.website.localhost) |
| `production ` | [https://prod.website.localhost](https://prod.website.localhost) |


Any `.localhost` TLD resolves by default to `127.0.0.1` so no any additional action is required on your *host*.

> [!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.


Expand Down
24 changes: 20 additions & 4 deletions build/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
(generic) {
(common) {
encode zstd gzip
respond /healthcheck 200
root * /var/www/html/public
file_server
}

(ssl) {
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
}
}
14 changes: 2 additions & 12 deletions docker-compose.override.dev.yml
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 12 additions & 2 deletions docker-compose.override.prod.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bd163dd

Please sign in to comment.