Compare commits

1 Commits

Author SHA1 Message Date
ea97a26d5c fixed cron
All checks were successful
Build Website / Build Dockerfile (push) Successful in 38s
2026-03-04 12:20:34 -05:00
4 changed files with 37 additions and 33 deletions

View File

@@ -1,32 +1,36 @@
name: Build and publish name: Build Website
run-name: Build and publish run-name: Build Website
on: on:
push: push:
jobs: jobs:
container: docker:
name: Build Container name: Build Dockerfile
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: docker container: docker:dind
steps: steps:
- name: Build Container - name: Clone Repository
uses: ztimson/actions/clone@develop
- name: Install Node
run: apk add nodejs npm
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Publish Latest Tag
run: | run: |
git clone -b "${{github.ref_name}}" "$(echo ${{github.server_url}}/${{github.repository}}.git | sed s%://%://${{github.token}}@% )" .
DOCKER_HUB=$([ -n "${{secrets.DOCKER_HUB_USER}}" ] && [ -n "${{secrets.DOCKER_HUB_TOKEN}}" ] && [ -n "${{secrets.DOCKER_HUB_IMAGE}}" ] && echo "true" || echo "false")
REGISTRY="$(echo "${{github.server_url}}" | sed -E 's|https?://||')"
docker login -u "${{github.repository_owner}}" -p "${{secrets.DEPLOY_TOKEN}}" "$REGISTRY"
if [ "$DOCKER_HUB" = "true" ]; then docker login -u "${{secrets.DOCKER_HUB_USER}}" -p "${{secrets.DOCKER_HUB_TOKEN}}" docker.io; fi
docker build -t "$REGISTRY/${{github.repository}}:${{github.ref_name}}" .
docker push "$REGISTRY/${{github.repository}}:${{github.ref_name}}"
if [ "${{github.ref_name}}" = "master" ]; then if [ "${{github.ref_name}}" = "master" ]; then
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "$REGISTRY/${{github.repository}}:latest" REGISTRY=$(echo ${{github.server_url}} | sed s%http://%% | sed s%https://%%)
docker push "$REGISTRY/${{github.repository}}:latest" docker login -u "${{github.repository_owner}}" -p "${{secrets.DEPLOY_TOKEN}}" "$REGISTRY"
if [ "$DOCKER_HUB" = "true" ]; then docker login -u "${{secrets.DOCKER_HUB_USER}}" -p "${{secrets.DOCKER_HUB_TOKEN}}" docker.io
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:latest"
docker push "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:latest" docker buildx build --platform linux/amd64,linux/arm64 \
fi -t "$REGISTRY/${{github.repository}}:latest" \
-t "docker.io/ztimson/kiwixm:latest" \
--push .
fi fi

View File

@@ -52,10 +52,10 @@ To restore a backup, uncompress it and use the official `mongorestore`
### Environment Variables ### Environment Variables
| Variable | Description | Default | Example | | Variable | Description | Default | Example |
|--------------------|--------------------------------|--------------------------|---------------| |-------------------------|----------------------------|---------------|---------------|
| `MONGO_INITDB_DATABASE` | Database name to backup | - | `myapp` |
| `BACKUP_CRON` | Cron schedule expression | - | `0 */6 * * *` | | `BACKUP_CRON` | Cron schedule expression | - | `0 */6 * * *` |
| `BACKUP_DIR` | Directory to store backups | /data/backups | `/backups` | | `BACKUP_DIR` | Directory to store backups | /data/backups | `/backups` |
| `BACKUP_DB` | Database that will be backedup | `$MONGO_INITDB_DATABASE` | `admin` | |
| `BACKUP_RETENTION` | Number of backups to keep | - | `7` | | `BACKUP_RETENTION` | Number of backups to keep | - | `7` |
### Built With ### Built With

View File

@@ -6,13 +6,12 @@ TEMP_DUMP="/tmp/mongo_dump_${TIMESTAMP}"
# Create & zip backup # Create & zip backup
mkdir -p "$BACKUP_DIR" mkdir -p "$BACKUP_DIR"
if [[ -z "$BACKUP_DB" ]]; then BACKUP_DB="$MONGO_INITDB_DATABASE"; fi mongodump --host localhost --db "$MONGO_INITDB_DATABASE" -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_PASSWORD" --out "$TEMP_DUMP"
mongodump --host localhost --db "$BACKUP_DB" -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_USERNAME" --out "$TEMP_DUMP"
tar -czf "${BACKUP_DIR}/${BACKUP_FILE}" -C "$TEMP_DUMP" . tar -czf "${BACKUP_DIR}/${BACKUP_FILE}" -C "$TEMP_DUMP" .
rm -rf "$TEMP_DUMP" rm -rf "$TEMP_DUMP"
# Remove old backups # Remove old backups
if [[ -n "$BACKUP_RETENTION" ]]; then if [[ -n "$BACKUP_RETENTION" ]]; then
cd "$BACKUP_DIR" cd "$BACKUP_DIR"
ls -1t dump_${MONGO_INITDB_DATABASE}_*.tar.gz | tail -n +$((BACKUP_RETENTION + 1)) | xargs -r rm -f ls -1t ${MONGO_INITDB_DATABASE}_*.dump.tar.gz 2>/dev/null | tail -n +$((BACKUP_RETENTION + 1)) | xargs -r rm -f
fi fi

View File

@@ -2,10 +2,11 @@
# Setup cron job if BACKUP_CRON is set # Setup cron job if BACKUP_CRON is set
if [ -n "$BACKUP_CRON" ]; then if [ -n "$BACKUP_CRON" ]; then
echo "$BACKUP_CRON /usr/local/bin/backup.sh >> /var/log/mongo-backup.log 2>&1" > /etc/cron.d/mongo-backup echo "$BACKUP_CRON /usr/local/bin/backup >> /var/log/mongo-backup.log 2>&1" > /etc/cron.d/mongo-backup
echo "" >> /etc/cron.d/mongo-backup
chmod 0644 /etc/cron.d/mongo-backup chmod 0644 /etc/cron.d/mongo-backup
crontab /etc/cron.d/mongo-backup crontab /etc/cron.d/mongo-backup
cron cron &
fi fi
# Execute original mongo entrypoint # Execute original mongo entrypoint