Can now make changes to default.conf without overwrite if changing project name.

This commit is contained in:
Jonathan Rosenbaum 2025-06-08 22:57:34 +00:00
parent 4ace5fb035
commit d58cd6e879
2 changed files with 19 additions and 6 deletions

View File

@ -55,18 +55,15 @@ HTML_VOLUME=test_html_staging
Two important Nginx configuration files are available in the project directory. After editing, perform a restart:
```bash
./default.conf # Automatically generated each time the script runs
./default.conf # generate-compose-nginx.sh respects user added changes
./nginx.conf # Manually customizable configuration
```
⚠️ **Warning:** `default.conf` is regenerated every time `generate-compose-nginx.sh` runs.
Make a backup before modifying if you plan to change the project name.
---
## 🚀 Usage
### **Initialize a Project with a Unique `COMPOSE_PROJECT_NAME`**
### **Initialize a Project with a Unique `COMPOSE_PROJECT_NAME`; expects one word**
Run the following script to generate the required files:
```bash
./generate-compose-nginx.sh

View File

@ -16,4 +16,20 @@ fi
export SERVICE_SUFFIX=${COMPOSE_PROJECT_NAME:-main}
export COMPOSE_PROJECT_NAME
envsubst < docker-compose.template.yml > docker-compose.yml
# Define the new value for the database host
export new_wp="wordpress_${COMPOSE_PROJECT_NAME}"
# If default.conf doesn't exist, create it from the template (using envsubst restricted to COMPOSE_PROJECT_NAME)
if [ ! -f default.conf ]; then
echo "default.conf not found, creating from default.template.conf..."
envsubst '${COMPOSE_PROJECT_NAME}' < default.template.conf > default.conf
fi
# Check if the existing default.conf contains a database hostname matching the pattern (it may or may not contain the env variable placeholder)
if grep -qE "\bwordpress_\w+(?::\d+)?\b" default.conf; then
# Update in-place only the portion that matches the database host pattern.
# sed -i "s/\bwordpress_\w+(?::\d+)?\b/${new_wp}/g" default.conf
perl -pi -e 's/\bwordpress_\w+(?::(\d+))?\b/$ENV{"new_wp"} . (defined($1) ? ":$1" : "")/eg' default.conf
echo "default.conf updated with COMPOSE_PROJECT_NAME='${COMPOSE_PROJECT_NAME}'."
fi