This commit is contained in:
commit
acfd5cbdfb
2
.drone.yml
Normal file
2
.drone.yml
Normal file
@ -0,0 +1,2 @@
|
||||
kind: template
|
||||
load: docker.yaml
|
6
.flake8
Normal file
6
.flake8
Normal file
@ -0,0 +1,6 @@
|
||||
[flake8]
|
||||
inline-quotes = "
|
||||
multiline-quotes = """
|
||||
indent-size = 4
|
||||
max-line-length = 160
|
||||
ignore = Q003 E128 E704 E731
|
6
.pre-commit-config.yaml
Normal file
6
.pre-commit-config.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
repos:
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 3.9.2
|
||||
hooks:
|
||||
- id: flake8
|
||||
additional_dependencies: [flake8-typing-imports==1.10.0,flake8-quotes==3.2.0]
|
6
Dockerfile
Normal file
6
Dockerfile
Normal file
@ -0,0 +1,6 @@
|
||||
FROM harbor.k-space.ee/k-space/microservice-base
|
||||
ADD backup.py /backup.py
|
||||
RUN apk add mongodb-tools
|
||||
RUN pip install kubernetes flask
|
||||
ENTRYPOINT /backup.py
|
||||
EXPOSE 3001
|
28
backup.py
Executable file
28
backup.py
Executable file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
import base64
|
||||
import os
|
||||
from kubernetes import client, config
|
||||
from kubernetes.client.api_client import ApiClient
|
||||
from subprocess import Popen, PIPE
|
||||
from flask import Flask, request, send_file
|
||||
|
||||
TOKEN = os.environ["TOKEN"]
|
||||
app = Flask(__name__)
|
||||
config.load_incluster_config()
|
||||
|
||||
@app.route("/stream/<namespace>/mongo/<user>/<database>")
|
||||
def stream(namespace, user, database):
|
||||
if request.headers.get("Authorization") != TOKEN:
|
||||
raise
|
||||
with ApiClient() as api:
|
||||
v1 = client.CoreV1Api(api)
|
||||
secret_name = "mongodb-%s-%s" % (user, database)
|
||||
secret = v1.read_namespaced_secret(secret_name, namespace)
|
||||
uri = base64.b64decode(secret.data["connectionString.standard"]).decode("ascii")
|
||||
cmd = "/usr/bin/mongodump", "--uri", uri, "--gzip", "--archive"
|
||||
print("Executing:", cmd)
|
||||
process = Popen(cmd, stdout=PIPE, stdin=PIPE, close_fds=True, bufsize=4096 * 1024)
|
||||
return send_file(process.stdout, "stream", "application/tar+gzip", download_name="%s.tar.gz" % secret_name)
|
||||
|
||||
|
||||
app.run(host="0.0.0.0", debug=False, threaded=True)
|
Loading…
Reference in New Issue
Block a user