Skip to content

Commit

Permalink
Joomla with Let's Encrypt Using Docker Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
heyvaldemar committed Sep 7, 2024
1 parent 1729b32 commit 60b90dc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 75 deletions.
29 changes: 11 additions & 18 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Traefik Variables
TRAEFIK_IMAGE_TAG=traefik:3.1
TRAEFIK_IMAGE_TAG=traefik:2.9
TRAEFIK_LOG_LEVEL=WARN
TRAEFIK_ACME_EMAIL=[email protected]
TRAEFIK_HOSTNAME=traefik.joomla.heyvaldemar.net
Expand All @@ -9,32 +9,25 @@ TRAEFIK_HOSTNAME=traefik.joomla.heyvaldemar.net
TRAEFIK_BASIC_AUTH=traefikadmin:$$2y$$10$$sMzJfirKC75x/hVpiINeZOiSm.Jkity9cn4KwNkRvO7hSQVFc5FLO

# Joomla Variables
JOOMLA_MARIADB_IMAGE_TAG=mariadb:11.1
JOOMLA_IMAGE_TAG=bitnami/joomla:5.1.2
JOOMLA_POSTGRES_IMAGE_TAG=postgres:16
JOOMLA_IMAGE_TAG=joomla
JOOMLA_DB_NAME=joomladb
JOOMLA_DB_USER=joomladbbuser
JOOMLA_DB_PASSWORD=XD8YowgYuwhYBfNcKbRG
JOOMLA_DB_ADMIN_PASSWORD=DFsmVC5uOGyXTjkoRfRE
JOOMLA_BLOG_NAME=Joomla
JOOMLA_SITE_NAME=Joomla
JOOMLA_ADMIN_USER=Joomla Admin
JOOMLA_ADMIN_USERNAME=joomlaadmin
JOOMLA_ADMIN_PASSWORD=BcFtUTOrYqh43i7859eK
JOOMLA_ADMIN_EMAIL=[email protected]
JOOMLA_HOSTNAME=joomla.heyvaldemar.net
JOOMLA_SMTP_ADDRESS=smtp-relay.gmail.com
JOOMLA_SMTP_PORT=587
JOOMLA_SMTP_USER_NAME=[email protected]
JOOMLA_SMTP_PASSWORD=HerTYhLKjDkWuGobstUF
JOOMLA_SMTP_PROTOCOL=tls
JOOMLA_SMTP_SENDER_EMAIL=[email protected]
JOOMLA_SMTP_SENDER_NAME=Joomla

# Backup Variables
BACKUP_INIT_SLEEP=30m
BACKUP_INTERVAL=24h
MARIADB_BACKUP_PRUNE_DAYS=7
BACKUP_INIT_SLEEP=1m
BACKUP_INTERVAL=1m
POSTGRES_BACKUP_PRUNE_DAYS=7
DATA_BACKUP_PRUNE_DAYS=7
MARIADB_BACKUPS_PATH=/srv/joomla-mariadb/backups
POSTGRES_BACKUPS_PATH=/srv/joomla-postgres/backups
DATA_BACKUPS_PATH=/srv/joomla-application-data/backups
DATA_PATH=/bitnami/joomla
MARIADB_BACKUP_NAME=joomla-mariadb-backup
DATA_PATH=/var/www/html
POSTGRES_BACKUP_NAME=joomla-postgres-backup
DATA_BACKUP_NAME=joomla-application-data-backup
2 changes: 1 addition & 1 deletion .github/workflows/00-deployment-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Wait for the application to be ready via Traefik
run: |
echo "Checking the routing and availability of application via Traefik..."
timeout 5m bash -c 'while ! curl -fsSLk "https://joomla.heyvaldemar.net"; do echo "Waiting for the application to be ready..."; sleep 10; done'
timeout 5m bash -c 'while ! curl -fsSLk "https://joomla.heyvaldemar.net/administrator"; do echo "Waiting for the application to be ready..."; sleep 10; done'
- name: Inspect Network Configuration
run: |
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Deploy Joomla using Docker Compose:

The `backups` container in the configuration is responsible for the following:

1. **Database Backup**: Creates compressed backups of the MariaDB database using pg_dump.
Customizable backup path, filename pattern, and schedule through variables like `MARIADB_BACKUPS_PATH`, `MARIADB_BACKUP_NAME`, and `BACKUP_INTERVAL`.
1. **Database Backup**: Creates compressed backups of the PostgreSQL database using pg_dump.
Customizable backup path, filename pattern, and schedule through variables like `POSTGRES_BACKUPS_PATH`, `POSTGRES_BACKUP_NAME`, and `BACKUP_INTERVAL`.

2. **Application Data Backup**: Compresses and stores backups of the application data on the same schedule. Controlled via variables such as `DATA_BACKUPS_PATH`, `DATA_BACKUP_NAME`, and `BACKUP_INTERVAL`.

3. **Backup Pruning**: Periodically removes backups exceeding a specified age to manage storage. Customizable pruning schedule and age threshold with `MARIADB_BACKUP_PRUNE_DAYS` and `DATA_BACKUP_PRUNE_DAYS`.
3. **Backup Pruning**: Periodically removes backups exceeding a specified age to manage storage. Customizable pruning schedule and age threshold with `POSTGRES_BACKUP_PRUNE_DAYS` and `DATA_BACKUP_PRUNE_DAYS`.

By utilizing this container, consistent and automated backups of the essential components of your instance are ensured. Moreover, efficient management of backup storage and tailored backup routines can be achieved through easy and flexible configuration using environment variables.

Expand Down
4 changes: 2 additions & 2 deletions joomla-restore-application-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
JOOMLA_CONTAINER=$(docker ps -aqf "name=joomla-joomla")
JOOMLA_BACKUPS_CONTAINER=$(docker ps -aqf "name=joomla-backups")
BACKUP_PATH="/srv/joomla-application-data/backups/"
RESTORE_PATH="/bitnami/joomla/"
RESTORE_PATH="/var/www/html/"
BACKUP_PREFIX="joomla-application-data"

echo "--> All available application data backups:"
Expand All @@ -41,4 +41,4 @@ docker exec -it "$JOOMLA_BACKUPS_CONTAINER" sh -c "rm -rf ${RESTORE_PATH}* && ta
echo "--> Application data recovery completed..."

echo "--> Starting service..."
docker start "$JOOMLA_CONTAINER"
docker start "$JOOMLA_CONTAINER"
17 changes: 9 additions & 8 deletions joomla-restore-database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
JOOMLA_CONTAINER=$(docker ps -aqf "name=joomla-joomla")
JOOMLA_BACKUPS_CONTAINER=$(docker ps -aqf "name=joomla-backups")
JOOMLA_DB_NAME="joomladb"
JOOMLA_DB_USER=$(docker exec $JOOMLA_BACKUPS_CONTAINER printenv JOOMLA_DB_USER)
MARIADB_PASSWORD=$(docker exec $JOOMLA_BACKUPS_CONTAINER printenv JOOMLA_DB_PASSWORD)
BACKUP_PATH="/srv/joomla-mariadb/backups/"
JOOMLA_DB_USER="joomladbuser"
POSTGRES_PASSWORD=$(docker exec $JOOMLA_BACKUPS_CONTAINER printenv PGPASSWORD)
BACKUP_PATH="/srv/joomla-postgres/backups/"

echo "--> All available database backups:"

Expand All @@ -26,8 +26,8 @@ do
echo "$entry"
done

echo "--> Copy and paste the backup name from the list above to restore database and press [ENTER]"
echo "--> Example: joomla-mariadb-backup-YYYY-MM-DD_hh-mm.gz"
echo "--> Copy and paste the backup name from the list above to restore database and press [ENTER]
--> Example: joomla-postgres-backup-YYYY-MM-DD_hh-mm.gz"
echo -n "--> "

read SELECTED_DATABASE_BACKUP
Expand All @@ -38,9 +38,10 @@ echo "--> Stopping service..."
docker stop "$JOOMLA_CONTAINER"

echo "--> Restoring database..."
docker exec "$JOOMLA_BACKUPS_CONTAINER" sh -c "mariadb -h mariadb -u $JOOMLA_DB_USER --password=$MARIADB_PASSWORD -e 'DROP DATABASE $JOOMLA_DB_NAME; CREATE DATABASE $JOOMLA_DB_NAME;' \
&& gunzip -c ${BACKUP_PATH}${SELECTED_DATABASE_BACKUP} | mariadb -h mariadb -u $JOOMLA_DB_USER --password=$MARIADB_PASSWORD $JOOMLA_DB_NAME"
docker exec "$JOOMLA_BACKUPS_CONTAINER" sh -c "dropdb -h postgres -p 5432 $JOOMLA_DB_NAME -U $JOOMLA_DB_USER \
&& createdb -h postgres -p 5432 $JOOMLA_DB_NAME -U $JOOMLA_DB_USER \
&& gunzip -c ${BACKUP_PATH}${SELECTED_DATABASE_BACKUP} | psql -h postgres -p 5432 $JOOMLA_DB_NAME -U $JOOMLA_DB_USER"
echo "--> Database recovery completed..."

echo "--> Starting service..."
docker start "$JOOMLA_CONTAINER"
docker start "$JOOMLA_CONTAINER"
79 changes: 36 additions & 43 deletions joomla-traefik-letsencrypt-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

# Backups
# The `backups` container in the configuration is responsible for the following:
# 1. **Database Backup**: Creates compressed backups of the MariaDB database using pg_dump.
# Customizable backup path, filename pattern, and schedule through variables like `MARIADB_BACKUPS_PATH`, `MARIADB_BACKUP_NAME`, and `BACKUP_INTERVAL`.
# 1. **Database Backup**: Creates compressed backups of the PostgreSQL database using pg_dump.
# Customizable backup path, filename pattern, and schedule through variables like `POSTGRES_BACKUPS_PATH`, `POSTGRES_BACKUP_NAME`, and `BACKUP_INTERVAL`.
# 2. **Application Data Backup**: Compresses and stores backups of the application data on the same schedule. Controlled via variables such as `DATA_BACKUPS_PATH`, `DATA_BACKUP_NAME`, and `BACKUP_INTERVAL`.
# 3. **Backup Pruning**: Periodically removes backups exceeding a specified age to manage storage.
# Customizable pruning schedule and age threshold with `MARIADB_BACKUP_PRUNE_DAYS` and `DATA_BACKUP_PRUNE_DAYS`.
# Customizable pruning schedule and age threshold with `POSTGRES_BACKUP_PRUNE_DAYS` and `DATA_BACKUP_PRUNE_DAYS`.
# By utilizing this container, consistent and automated backups of the essential components of your instance are ensured.
# Moreover, efficient management of backup storage and tailored backup routines can be achieved through easy and flexible configuration using environment variables.

Expand Down Expand Up @@ -55,7 +55,7 @@
# Follow me on Twitter: https://twitter.com/heyValdemar
# Follow me on Instagram: https://www.instagram.com/heyvaldemar/
# Follow me on Threads: https://www.threads.net/@heyvaldemar
# Follow me on Mastodon: https://mastodon.social/@heyValdemar
# Follow me on Mastodon: https://mastodon.social/@heyvaldemar
# Follow me on Bluesky: https://bsky.app/profile/heyvaldemar.bsky.social
# Follow me on Facebook: https://www.facebook.com/heyValdemarFB/
# Follow me on TikTok: https://www.tiktok.com/@heyvaldemar
Expand All @@ -80,27 +80,26 @@ networks:
external: true

volumes:
mariadb-data:
joomla-data:
joomla-mariadb-backup:
joomla-postgres:
joomla-postgres-backup:
joomla-data-backups:
joomla-database-backups:
traefik-certificates:

services:
mariadb:
image: ${JOOMLA_MARIADB_IMAGE_TAG}
postgres:
image: ${JOOMLA_POSTGRES_IMAGE_TAG}
volumes:
- mariadb-data:/var/lib/mysql
- joomla-postgres:/var/lib/postgresql/data
environment:
MARIADB_DATABASE: ${JOOMLA_DB_NAME}
MARIADB_USER: ${JOOMLA_DB_USER}
MARIADB_PASSWORD: ${JOOMLA_DB_PASSWORD}
MARIADB_ROOT_PASSWORD: ${JOOMLA_DB_ADMIN_PASSWORD}
POSTGRES_DB: ${JOOMLA_DB_NAME}
POSTGRES_USER: ${JOOMLA_DB_USER}
POSTGRES_PASSWORD: ${JOOMLA_DB_PASSWORD}
networks:
- joomla-network
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
test: [ "CMD", "pg_isready", "-q", "-d", "${JOOMLA_DB_NAME}", "-U", "${JOOMLA_DB_USER}" ]
interval: 10s
timeout: 5s
retries: 3
Expand All @@ -112,27 +111,21 @@ services:
volumes:
- joomla-data:${DATA_PATH}
environment:
JOOMLA_DATABASE_HOST: mariadb
JOOMLA_DATABASE_PORT_NUMBER: 3306
JOOMLA_DATABASE_NAME: ${JOOMLA_DB_NAME}
JOOMLA_DATABASE_USER: ${JOOMLA_DB_USER}
JOOMLA_DATABASE_PASSWORD: ${JOOMLA_DB_PASSWORD}
JOOMLA_SITE_NAME: ${JOOMLA_BLOG_NAME}
JOOMLA_USERNAME: ${JOOMLA_ADMIN_USERNAME}
JOOMLA_PASSWORD: ${JOOMLA_ADMIN_PASSWORD}
JOOMLA_EMAIL: ${JOOMLA_ADMIN_EMAIL}
JOOMLA_SMTP_HOST: ${JOOMLA_SMTP_ADDRESS}
JOOMLA_SMTP_PORT: ${JOOMLA_SMTP_PORT}
JOOMLA_SMTP_USER: ${JOOMLA_SMTP_USER_NAME}
JOOMLA_SMTP_PASSWORD: ${JOOMLA_SMTP_PASSWORD}
JOOMLA_SMTP_PROTOCOL: ${JOOMLA_SMTP_PROTOCOL}
JOOMLA_SMTP_SENDER_EMAIL: ${JOOMLA_SMTP_SENDER_EMAIL}
JOOMLA_SMTP_SENDER_NAME: ${JOOMLA_SMTP_SENDER_NAME}
JOOMLA_DB_TYPE: pgsql
JOOMLA_DB_HOST: postgres
JOOMLA_DB_NAME: ${JOOMLA_DB_NAME}
JOOMLA_DB_USER: ${JOOMLA_DB_USER}
JOOMLA_DB_PASSWORD: ${JOOMLA_DB_PASSWORD}
JOOMLA_SITE_NAME: ${JOOMLA_SITE_NAME}
JOOMLA_ADMIN_USER: ${JOOMLA_ADMIN_USER}
JOOMLA_ADMIN_USERNAME: ${JOOMLA_ADMIN_USERNAME}
JOOMLA_ADMIN_PASSWORD: ${JOOMLA_ADMIN_PASSWORD}
JOOMLA_ADMIN_EMAIL: ${JOOMLA_ADMIN_EMAIL}
networks:
- joomla-network
- traefik-network
healthcheck:
test: timeout 10s bash -c ':> /dev/tcp/127.0.0.1/8080' || exit 1
test: timeout 10s bash -c ':> /dev/tcp/127.0.0.1/80' || exit 1
interval: 10s
timeout: 5s
retries: 3
Expand All @@ -142,7 +135,7 @@ services:
- "traefik.http.routers.joomla.rule=Host(`${JOOMLA_HOSTNAME}`)"
- "traefik.http.routers.joomla.service=joomla"
- "traefik.http.routers.joomla.entrypoints=websecure"
- "traefik.http.services.joomla.loadbalancer.server.port=8080"
- "traefik.http.services.joomla.loadbalancer.server.port=80"
- "traefik.http.routers.joomla.tls=true"
- "traefik.http.routers.joomla.tls.certresolver=letsencrypt"
- "traefik.http.services.joomla.loadbalancer.passhostheader=true"
Expand All @@ -151,7 +144,7 @@ services:
- "traefik.docker.network=traefik-network"
restart: unless-stopped
depends_on:
mariadb:
postgres:
condition: service_healthy
traefik:
condition: service_healthy
Expand Down Expand Up @@ -210,36 +203,36 @@ services:
restart: unless-stopped

backups:
image: ${JOOMLA_MARIADB_IMAGE_TAG}
image: ${JOOMLA_POSTGRES_IMAGE_TAG}
command: >-
sh -c 'sleep $BACKUP_INIT_SLEEP &&
while true; do
mariadb-dump -h mariadb -u $JOOMLA_DB_USER -p"$JOOMLA_DB_PASSWORD" $JOOMLA_DB_NAME | gzip > "$MARIADB_BACKUPS_PATH/$MARIADB_BACKUP_NAME-$(date '+%Y-%m-%d_%H-%M').gz" &&
pg_dump -h postgres -p 5432 -d $JOOMLA_DB_NAME -U $JOOMLA_DB_USER | gzip > $POSTGRES_BACKUPS_PATH/$POSTGRES_BACKUP_NAME-$(date "+%Y-%m-%d_%H-%M").gz &&
tar -zcpf $DATA_BACKUPS_PATH/$DATA_BACKUP_NAME-$(date "+%Y-%m-%d_%H-%M").tar.gz $DATA_PATH &&
find $MARIADB_BACKUPS_PATH -type f -mtime +$MARIADB_BACKUP_PRUNE_DAYS | xargs rm -f &&
find $POSTGRES_BACKUPS_PATH -type f -mtime +$POSTGRES_BACKUP_PRUNE_DAYS | xargs rm -f &&
find $DATA_BACKUPS_PATH -type f -mtime +$DATA_BACKUP_PRUNE_DAYS | xargs rm -f;
sleep $BACKUP_INTERVAL; done'
volumes:
- joomla-mariadb-backup:/var/lib/mysql
- joomla-postgres-backup:/var/lib/postgresql/data
- joomla-data:${DATA_PATH}
- joomla-data-backups:${DATA_BACKUPS_PATH}
- joomla-database-backups:${MARIADB_BACKUPS_PATH}
- joomla-database-backups:${POSTGRES_BACKUPS_PATH}
environment:
JOOMLA_DB_NAME: ${JOOMLA_DB_NAME}
JOOMLA_DB_USER: ${JOOMLA_DB_USER}
JOOMLA_DB_PASSWORD: ${JOOMLA_DB_PASSWORD}
PGPASSWORD: ${JOOMLA_DB_PASSWORD}
BACKUP_INIT_SLEEP: ${BACKUP_INIT_SLEEP}
BACKUP_INTERVAL: ${BACKUP_INTERVAL}
MARIADB_BACKUP_PRUNE_DAYS: ${MARIADB_BACKUP_PRUNE_DAYS}
POSTGRES_BACKUP_PRUNE_DAYS: ${POSTGRES_BACKUP_PRUNE_DAYS}
DATA_BACKUP_PRUNE_DAYS: ${DATA_BACKUP_PRUNE_DAYS}
MARIADB_BACKUPS_PATH: ${MARIADB_BACKUPS_PATH}
POSTGRES_BACKUPS_PATH: ${POSTGRES_BACKUPS_PATH}
DATA_BACKUPS_PATH: ${DATA_BACKUPS_PATH}
DATA_PATH: ${DATA_PATH}
MARIADB_BACKUP_NAME: ${MARIADB_BACKUP_NAME}
POSTGRES_BACKUP_NAME: ${POSTGRES_BACKUP_NAME}
DATA_BACKUP_NAME: ${DATA_BACKUP_NAME}
networks:
- joomla-network
restart: unless-stopped
depends_on:
mariadb:
postgres:
condition: service_healthy

0 comments on commit 60b90dc

Please sign in to comment.