Compare commits

2 Commits

Author SHA1 Message Date
e0933bede2 Updated env vars
All checks were successful
Build and publish / Build Container (push) Successful in 13s
2026-03-04 13:02:42 -05:00
1e6179ac5f Fixed build
All checks were successful
Build and publish / Build Container (push) Successful in 11s
2026-03-04 12:36:44 -05:00
4 changed files with 33 additions and 37 deletions

View File

@@ -1,36 +1,32 @@
name: Build Website name: Build and publish
run-name: Build Website run-name: Build and publish
on: on:
push: push:
jobs: jobs:
docker: container:
name: Build Dockerfile name: Build Container
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: docker:dind container: docker
steps: steps:
- name: Clone Repository - name: Build Container
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: |
if [ "${{github.ref_name}}" = "master" ]; then git clone -b "${{github.ref_name}}" "$(echo ${{github.server_url}}/${{github.repository}}.git | sed s%://%://${{github.token}}@% )" .
REGISTRY=$(echo ${{github.server_url}} | sed s%http://%% | sed s%https://%%) DOCKER_HUB=$([ -n "${{secrets.DOCKER_HUB_USER}}" ] && [ -n "${{secrets.DOCKER_HUB_TOKEN}}" ] && [ -n "${{secrets.DOCKER_HUB_IMAGE}}" ] && echo "true" || echo "false")
docker login -u "${{github.repository_owner}}" -p "${{secrets.DEPLOY_TOKEN}}" "$REGISTRY" REGISTRY="$(echo "${{github.server_url}}" | sed -E 's|https?://||')"
docker login -u "${{secrets.DOCKER_HUB_USER}}" -p "${{secrets.DOCKER_HUB_TOKEN}}" docker.io
docker buildx build --platform linux/amd64,linux/arm64 \ docker login -u "${{github.repository_owner}}" -p "${{secrets.DEPLOY_TOKEN}}" "$REGISTRY"
-t "$REGISTRY/${{github.repository}}:latest" \ if [ "$DOCKER_HUB" = "true" ]; then docker login -u "${{secrets.DOCKER_HUB_USER}}" -p "${{secrets.DOCKER_HUB_TOKEN}}" docker.io; fi
-t "docker.io/ztimson/kiwixm:latest" \
--push . docker build -t "$REGISTRY/${{github.repository}}:${{github.ref_name}}" .
docker push "$REGISTRY/${{github.repository}}:${{github.ref_name}}"
if [ "${{github.ref_name}}" = "master" ]; then
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "$REGISTRY/${{github.repository}}:latest"
docker push "$REGISTRY/${{github.repository}}:latest"
if [ "$DOCKER_HUB" = "true" ]; then
docker tag "$REGISTRY/${{github.repository}}:${{github.ref_name}}" "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:latest"
docker push "docker.io/${{secrets.DOCKER_HUB_IMAGE}}:latest"
fi
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,12 +6,13 @@ TEMP_DUMP="/tmp/mongo_dump_${TIMESTAMP}"
# Create & zip backup # Create & zip backup
mkdir -p "$BACKUP_DIR" mkdir -p "$BACKUP_DIR"
mongodump --host localhost --db "$MONGO_INITDB_DATABASE" -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_PASSWORD" --out "$TEMP_DUMP" if [[ -z "$BACKUP_DB" ]]; then BACKUP_DB="$MONGO_INITDB_DATABASE"; fi
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 ${MONGO_INITDB_DATABASE}_*.dump.tar.gz 2>/dev/null | tail -n +$((BACKUP_RETENTION + 1)) | xargs -r rm -f ls -1t dump_${MONGO_INITDB_DATABASE}_*.tar.gz | tail -n +$((BACKUP_RETENTION + 1)) | xargs -r rm -f
fi fi

View File

@@ -2,11 +2,10 @@
# 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 >> /var/log/mongo-backup.log 2>&1" > /etc/cron.d/mongo-backup echo "$BACKUP_CRON /usr/local/bin/backup.sh >> /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