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
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# Core application settings
# --------------------------------------------------

# Docker container name prefix
CONTAINER_NAME=app

# --------------------------------------------------
# Database (MySQL)
# --------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ The stack is driven by environment variables defined in the `.env` file. This ap

| Variable | Description |
| :--- | :--- |
| `CONTAINER_NAME` | Prefix used for all containers in the stack (e.g., `app`). |
| `SERVER_NAME` | Domain or hostname for the application (e.g., `localhost`). |
| `HTTP_PORT` | Host port mapped to the Nginx entry point (e.g., `8000`). |

Expand Down
3 changes: 0 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
services:

Check warning on line 1 in docker-compose.dev.yml

View workflow job for this annotation

GitHub Actions / Docker Compose lint

1:1 [document-start] missing document start "---"
database:
volumes:
- ./db/init:/docker-entrypoint-initdb.d
Expand Down Expand Up @@ -31,7 +31,6 @@
depends_on:
- wordpress
- database
container_name: ${CONTAINER_NAME}-wp-cli
image: wordpress:cli
env_file: .env
environment:
Expand All @@ -51,7 +50,6 @@
db-cli:
depends_on:
- database
container_name: ${CONTAINER_NAME}-db-cli
image: mysql:8.4.7
env_file: .env
environment:
Expand All @@ -72,7 +70,6 @@
phpmyadmin:
depends_on:
- database
container_name: ${CONTAINER_NAME}-phpmyadmin
image: phpmyadmin:5.2.3
restart: unless-stopped
env_file: .env
Expand Down
1 change: 0 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x-logging: &default-logging

Check warning on line 1 in docker-compose.prod.yml

View workflow job for this annotation

GitHub Actions / Docker Compose lint

1:1 [document-start] missing document start "---"
logging:
driver: json-file
options:
Expand Down Expand Up @@ -83,7 +83,6 @@
certbot:
<<: *default-logging
image: certbot/certbot:v5.2.2
container_name: ${CONTAINER_NAME}-certbot
env_file: .env
environment:
SERVER_NAME: ${SERVER_NAME}
Expand Down
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
services:

Check warning on line 1 in docker-compose.yml

View workflow job for this annotation

GitHub Actions / Docker Compose lint

1:1 [document-start] missing document start "---"
database:
container_name: ${CONTAINER_NAME}-database
image: mysql:8.4.7
restart: unless-stopped
env_file: .env
Expand All @@ -23,7 +22,6 @@
wordpress:
depends_on:
- database
container_name: ${CONTAINER_NAME}-wordpress
image: wordpress:6.9.0-fpm-alpine
restart: unless-stopped
env_file: .env
Expand All @@ -40,7 +38,6 @@
nginx:
depends_on:
- wordpress
container_name: ${CONTAINER_NAME}-nginx
image: nginx:1.29.2-alpine
restart: unless-stopped
env_file: .env
Expand All @@ -55,7 +52,6 @@
depends_on:
- wordpress
- database
container_name: ${CONTAINER_NAME}-wp-init
image: wordpress:cli
env_file: .env
environment:
Expand All @@ -72,7 +68,6 @@
db-backup:
depends_on:
- database
container_name: ${CONTAINER_NAME}-db-backup
image: mysql:8.4.7
env_file: .env
environment:
Expand Down
46 changes: 23 additions & 23 deletions nginx/dev.conf.template
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
server {
listen 80;
server_name ${SERVER_NAME};
listen 80;
server_name ${SERVER_NAME};

root /var/www/html;
index index.php index.html;
root /var/www/html;
index index.php index.html;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";

location / {
try_files $uri $uri/ /index.php?$args;
}
location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
include fastcgi_params;
try_files $uri =404;
location ~ \.php$ {
include fastcgi_params;
try_files $uri =404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}

location ~ /\.ht {
deny all;
}
}
location ~ /\.ht {
deny all;
}
}
78 changes: 39 additions & 39 deletions nginx/prod.conf.template
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
server {
listen 80;
server_name ${SERVER_NAME};
listen 80;
server_name ${SERVER_NAME};

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location / {
return 301 https://$host$request_uri;
}
location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl;
http2 on;
server_name ${SERVER_NAME};
listen 443 ssl;
http2 on;
server_name ${SERVER_NAME};

root /var/www/html;
index index.php;
root /var/www/html;
index index.php;

ssl_certificate /etc/letsencrypt/live/${SERVER_NAME}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${SERVER_NAME}/privkey.pem;
ssl_certificate /etc/letsencrypt/live/${SERVER_NAME}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${SERVER_NAME}/privkey.pem;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options SAMEORIGIN;
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy strict-origin-when-cross-origin;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options SAMEORIGIN;
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy strict-origin-when-cross-origin;

location / {
try_files $uri $uri/ /index.php?$args;
}
location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
include fastcgi_params;
location ~ \.php$ {
include fastcgi_params;

fastcgi_pass wordpress:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_read_timeout 60s;
}
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_read_timeout 60s;
}

location ~ /\.(?!well-known) {
deny all;
}
location ~ /\.(?!well-known) {
deny all;
}
}
2 changes: 1 addition & 1 deletion scripts/db-backup/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ "${SKIP_DB_BACKUP}" = "true" ]; then
fi

if [ ! -x /scripts/db-backup/run-db-backup-periodic.sh ]; then
echo "Error: run-db-backup-periodic.sh not found or not executable"
echo "Error: run-db-backup-periodic.sh not found or not executable" >&2
exit 1
fi

Expand Down
14 changes: 7 additions & 7 deletions scripts/db-backup/lib/backup.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/sh

do_backup() {
_db_name=$1
_backup_dir=$2
_db_name=$1
_backup_dir=$2

_timestamp=$(date +"%Y%m%d-%H%M%S")
_file="$_backup_dir/backup-$_timestamp.sql"
_timestamp=$(date +"%Y%m%d-%H%M%S")
_file="$_backup_dir/backup-$_timestamp.sql"

echo "Executing backup: $_file"
mysqldump --no-tablespaces "$_db_name" > "$_file"
echo "Executing backup: $_file"
mysqldump --no-tablespaces "$_db_name" > "$_file"

echo "Backup completed: $_file"
echo "Backup completed: $_file"
}
26 changes: 13 additions & 13 deletions scripts/db-backup/lib/rotation.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/bin/sh

rotate_backups() {
_backup_dir="$1"
_max_files="$2"
_backup_dir="$1"
_max_files="$2"

_count=$(find "$_backup_dir" -maxdepth 1 -type f -name '*.sql' | wc -l | tr -d ' ')
_count=$(find "$_backup_dir" -maxdepth 1 -type f -name '*.sql' | wc -l | tr -d ' ')

if [ "$_count" -gt "$_max_files" ]; then
_remove=$((_count - _max_files))
echo "Limit exceeded ($_count > $_max_files). Removing $_remove oldest backup(s)"
if [ "$_count" -gt "$_max_files" ]; then
_remove=$((_count - _max_files))
echo "Limit exceeded ($_count > $_max_files). Removing $_remove oldest backup(s)"

find "$_backup_dir" -maxdepth 1 -type f -name '*.sql' -print0 \
| xargs -0 stat --printf '%Y %n\n' \
| sort -n \
| head -n "$_remove" \
| cut -d' ' -f2- \
| xargs rm -f
fi
find "$_backup_dir" -maxdepth 1 -type f -name '*.sql' -print0 \
| xargs -0 stat --printf '%Y %n\n' \
| sort -n \
| head -n "$_remove" \
| cut -d' ' -f2- \
| xargs rm -f
fi
}
8 changes: 4 additions & 4 deletions scripts/db-backup/run-db-backup-periodic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ echo "Initial delay: $(format_interval "$BACKUP_INITIAL_DELAY_SEC")"
sleep "$BACKUP_INITIAL_DELAY_SEC"

while true; do
do_backup "$DB_NAME" "$BACKUP_DIR"
rotate_backups "$BACKUP_DIR" "$BACKUP_MAX_FILES"
do_backup "$DB_NAME" "$BACKUP_DIR"
rotate_backups "$BACKUP_DIR" "$BACKUP_MAX_FILES"

echo "Waiting $(format_interval "$BACKUP_INTERVAL_SEC") until next backup..."
sleep "$BACKUP_INTERVAL_SEC"
echo "Waiting $(format_interval "$BACKUP_INTERVAL_SEC") until next backup..."
sleep "$BACKUP_INTERVAL_SEC"
done
8 changes: 4 additions & 4 deletions scripts/db-cli/run-db-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ set -e
FILE="$1"

if [ -z "$FILE" ]; then
echo "ERROR: No SQL file provided"
exit 1
echo "Error: no SQL file provided" >&2
exit 1
fi

BASE="/db/init"
SQL_PATH="$BASE/$FILE"

if [ ! -f "$SQL_PATH" ]; then
echo "ERROR: SQL file not found: $SQL_PATH"
exit 1
echo "Error: SQL file not found: $SQL_PATH" >&2
exit 1
fi

echo "Creating DB client config"
Expand Down
18 changes: 7 additions & 11 deletions scripts/db-common/create-db-client-config.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#!/bin/sh

. /scripts/utils/check-required-vars.sh

create_db_client_config() {
_db_host="${1:-database}"
_db_port="${2:-3306}"
_db_user="${3}"
_db_password="${4}"

check_required_vars "_db_user _db_password"
_db_host="${1:-database}"
_db_port="${2:-3306}"
_db_user="${3}"
_db_password="${4}"

cat > /root/.my.cnf <<EOF
cat > /root/.my.cnf <<EOF
[client]
host=${_db_host}
port=${_db_port}
user=${_db_user}
password=${_db_password}
EOF

chmod 600 /root/.my.cnf
echo "Created /root/.my.cnf"
chmod 600 /root/.my.cnf
echo "Created /root/.my.cnf"
}
9 changes: 8 additions & 1 deletion scripts/db-common/wait-for-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ wait_for_db() {
fi

echo "Checking database connection at ${_db_host}:${_db_port}"
until nc -z "$_db_host" "$_db_port"; do
retries=60

while ! nc -z "$_db_host" "$_db_port" >/dev/null 2>&1; do
retries=$((retries - 1))
if [ "$retries" -le 0 ]; then
echo "Error: database not reachable at ${_db_host}:${_db_port}" >&2
return 1
fi
echo "Database not ready, retrying in 3 seconds..."
sleep 3
done
Expand Down
Loading