generated from ztimson/template
This commit is contained in:
36
.github/workflows/build.yaml
vendored
Normal file
36
.github/workflows/build.yaml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Build Website
|
||||
run-name: Build Website
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
name: Build Dockerfile
|
||||
runs-on: ubuntu-latest
|
||||
container: docker:dind
|
||||
steps:
|
||||
- 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: |
|
||||
if [ "${{github.ref_name}}" = "master" ]; then
|
||||
REGISTRY=$(echo ${{github.server_url}} | sed s%http://%% | sed s%https://%%)
|
||||
docker login -u "${{github.repository_owner}}" -p "${{secrets.DEPLOY_TOKEN}}" "$REGISTRY"
|
||||
docker login -u "${{secrets.DOCKER_HUB_USER}}" -p "${{secrets.DOCKER_HUB_TOKEN}}" docker.io
|
||||
|
||||
docker buildx build --platform linux/amd64,linux/arm64 \
|
||||
-t "$REGISTRY/${{github.repository}}:latest" \
|
||||
-t "docker.io/ztimson/kiwixm:latest" \
|
||||
--push .
|
||||
fi
|
||||
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM mongo:latest
|
||||
|
||||
ENV BACKUP_DIR=/data/backups
|
||||
|
||||
# Install cron
|
||||
RUN apt-get update && apt-get install -y cron && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy backup script
|
||||
COPY backup.sh /usr/local/bin/backup
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/backup && \
|
||||
chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
CMD ["mongod"]
|
||||
11
LICENSE
11
LICENSE
@@ -1,11 +0,0 @@
|
||||
Copyright (c) 2023 Zakary Timson
|
||||
|
||||
All Rights Reserved.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
134
README.md
134
README.md
@@ -1,96 +1,67 @@
|
||||
<!-- Header -->
|
||||
<div id="top" align="center">
|
||||
<br />
|
||||
|
||||
|
||||
<!-- Logo -->
|
||||
<img src="https://git.zakscode.com/repo-avatars/2b4ee6ba1f2e2618bf7694e4a52fb56d1d0ea6abafa2dcbe496ab786b86d5a76" alt="Logo" width="200" height="200">
|
||||
<img src="https://git.zakscode.com/repo-avatars/07b972bff6cb72ac002083726471fff9b2396e2f50a6be3b0529271a629f9228" alt="Logo" width="200" height="200">
|
||||
|
||||
<!-- Title -->
|
||||
### Template
|
||||
|
||||
|
||||
### MongoDB
|
||||
|
||||
<!-- Description -->
|
||||
Simple repository template
|
||||
MongoDB + Backups & Retention
|
||||
|
||||
<!-- Repo badges -->
|
||||
[](https://git.zakscode.com/ztimson/template/tags)
|
||||
[](https://git.zakscode.com/ztimson/template/pulls)
|
||||
[](https://git.zakscode.com/ztimson/template/issues)
|
||||
[](https://git.zakscode.com/ztimson/mongodb/tags)
|
||||
[](https://git.zakscode.com/ztimson/mongodb/pulls)
|
||||
[](https://git.zakscode.com/ztimson/mongodb/issues)
|
||||
|
||||
<!-- Links -->
|
||||
|
||||
---
|
||||
<div>
|
||||
<a href="https://git.zakscode.com/ztimson/template/wiki" target="_blank">Documentation</a>
|
||||
• <a href="https://git.zakscode.com/ztimson/template/releases" target="_blank">Release Notes</a>
|
||||
• <a href="https://git.zakscode.com/ztimson/template/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
|
||||
• <a href="https://git.zakscode.com/ztimson/template/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
|
||||
<a href="https://git.zakscode.com/ztimson/mongodb/wiki" target="_blank">Documentation</a>
|
||||
• <a href="https://git.zakscode.com/ztimson/mongodb/releases" target="_blank">Release Notes</a>
|
||||
• <a href="https://git.zakscode.com/ztimson/mongodb/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
|
||||
• <a href="https://git.zakscode.com/ztimson/mongodb/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
|
||||
</div>
|
||||
|
||||
---
|
||||
</div>
|
||||
|
||||
## Table of Contents
|
||||
- [Template](#top)
|
||||
- [About](#about)
|
||||
- [Demo](#demo)
|
||||
- [Built With](#built-with)
|
||||
- [Setup](#setup)
|
||||
- [Production](#production)
|
||||
- [Development](#development)
|
||||
- [License](#license)
|
||||
|
||||
- [MongoDB](#top)
|
||||
- [About](#about)
|
||||
- [Environment Variables](#environment-variables)
|
||||
- [Built With](#built-with)
|
||||
- [Setup](#setup)
|
||||
- [Production](#production)
|
||||
|
||||
## About
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
Custom MongoDB Docker image extending `mongo:latest` with automated backup functionality.
|
||||
|
||||
### Demo
|
||||
Installs cron to run scheduled mongodump operations with compression and retention management, while preserving all native MongoDB server functionality.
|
||||
|
||||
Website: https://git.zakscode.com
|
||||
Backups can be manually triggered with: `docker --exec -t mongodb backup`
|
||||
|
||||
To restore a backup, uncompress it and use the official `mongorestore`
|
||||
|
||||
### Environment Variables
|
||||
|
||||
| Variable | Description | Default | Example |
|
||||
|-------------------------|----------------------------|---------------|---------------|
|
||||
| `MONGO_INITDB_DATABASE` | Database name to backup | - | `myapp` |
|
||||
| `BACKUP_CRON` | Cron schedule expression | - | `0 */6 * * *` |
|
||||
| `BACKUP_DIR` | Directory to store backups | /data/backups | `/backups` |
|
||||
| `BACKUP_RETENTION` | Number of backups to keep | - | `7` |
|
||||
|
||||
### Built With
|
||||
[](https://angular.io/)
|
||||
[](https://www.android.com/)
|
||||
[](https://www.arduino.cc/)
|
||||
[](https://getbootstrap.com)
|
||||
[](https://en.cppreference.com/w/c/language)
|
||||
[](https://cplusplus.com/)
|
||||
[](https://dotnet.microsoft.com/)
|
||||
[](https://www.w3.org/Style/CSS/Overview.en.html)
|
||||
[](https://www.djangoproject.com/)
|
||||
|
||||
[](https://docker.com/)
|
||||
[](https://www.electronjs.org/)
|
||||
[](https://firebase.google.com/)
|
||||
[](https://go.dev/)
|
||||
[](https://graphql.org/)
|
||||
[](https://developer.mozilla.org/en-US/docs/Glossary/HTML)
|
||||
[](https://java.com/)
|
||||
[](https://javascript.com/)
|
||||
[](https://jquery.com )
|
||||
[](https://laravel.com)
|
||||
[](https://www.linux.org/)
|
||||
[](https://git.zakscode.com/ztimson/momentum)
|
||||
[](https://www.mongodb.com/)
|
||||
[](https://www.mysql.com/)
|
||||
[](https://nestjs.com/)
|
||||
[](https://dotnet.microsoft.com/)
|
||||
[](https://nextjs.org/)
|
||||
[](https://www.nginx.com/)
|
||||
[](https://nodejs.org/)
|
||||
[](https://p5js.org/)
|
||||
[](https://www.php.net/)
|
||||
[](https://www.postgresql.org/)
|
||||
[](https://www.python.org/)
|
||||
[](https://reactjs.org/)
|
||||
[](https://redis.com/)
|
||||
[](https://sass-lang.com/)
|
||||
[](https://en.wikipedia.org/wiki/Shell_script)
|
||||
[](https://www.microsoft.com/en-ca/sql-server)
|
||||
[](https://www.sqlite.org/index.html)
|
||||
[](https://svelte.dev/)
|
||||
[](https://typescriptlang.org/)
|
||||
[](https://microsoft.com/windows)
|
||||
[](https://vitejs.dev/)
|
||||
[](https://vuejs.org/)
|
||||
|
||||
## Setup
|
||||
|
||||
@@ -102,31 +73,24 @@ Website: https://git.zakscode.com
|
||||
</summary>
|
||||
|
||||
#### Prerequisites
|
||||
|
||||
- [Docker](https://docs.docker.com/install/)
|
||||
|
||||
#### Instructions
|
||||
1. Run the docker image: `docker run -p 80:80 git.zakscode.com/ztimson/template:latest`
|
||||
2. Open [http://localhost](http://localhost)
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
<h3 id="development" style="display: inline">
|
||||
Development
|
||||
</h3>
|
||||
</summary>
|
||||
1. Run the docker image:
|
||||
|
||||
#### Prerequisites
|
||||
- [Node.js](https://nodejs.org/en/download)
|
||||
|
||||
#### Instructions
|
||||
1. Install the dependencies: `npm install`
|
||||
2. Start the Angular server: `npm run start`
|
||||
3. Open [http://localhost:4200](http://localhost:4200)
|
||||
```shell
|
||||
docker run -d \
|
||||
--name mongodb \
|
||||
--restart unless-stopped \
|
||||
-p 27017:27017 \
|
||||
-e MONGO_INITDB_DATABASE=myapp \
|
||||
-e BACKUP_CRON="0 3 * * *" \
|
||||
-e BACKUP_RETENTION=7 \
|
||||
-v ./mongodb/data:/data/db \
|
||||
-v ./mongodb/backups:/data/backups \
|
||||
ztimson/mongodb:latest
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## License
|
||||
Copyright © 2023 Zakary Timson | All Rights Reserved | Available under MIT Licensing
|
||||
|
||||
See the [license](./LICENSE) for more information.
|
||||
|
||||
17
backup.sh
Normal file
17
backup.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
TIMESTAMP=$(date +%Y-%m-%d_%H-%M-%S)
|
||||
BACKUP_FILE="${MONGO_INITDB_DATABASE}_${TIMESTAMP}.dump.tar.gz"
|
||||
TEMP_DUMP="/tmp/mongo_dump_${TIMESTAMP}"
|
||||
|
||||
# Create & zip backup
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
mongodump --host localhost --db "$MONGO_INITDB_DATABASE" -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_USERNAME" --out "$TEMP_DUMP"
|
||||
tar -czf "${BACKUP_DIR}/${BACKUP_FILE}" -C "$TEMP_DUMP" .
|
||||
rm -rf "$TEMP_DUMP"
|
||||
|
||||
# Remove old backups
|
||||
if [[ -n "$BACKUP_RETENTION" ]]; then
|
||||
cd "$BACKUP_DIR"
|
||||
ls -1t dump_${MONGO_INITDB_DATABASE}_*.tar.gz | tail -n +$((BACKUP_RETENTION + 1)) | xargs -r rm -f
|
||||
fi
|
||||
12
entrypoint.sh
Normal file
12
entrypoint.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Setup cron job if BACKUP_CRON is set
|
||||
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
|
||||
chmod 0644 /etc/cron.d/mongo-backup
|
||||
crontab /etc/cron.d/mongo-backup
|
||||
cron
|
||||
fi
|
||||
|
||||
# Execute original mongo entrypoint
|
||||
exec /usr/local/bin/docker-entrypoint.sh "$@"
|
||||
Reference in New Issue
Block a user