feat(docker): add webhook to auto-redeploy on master commit, remove old docker-related files
Build and deploy / deploy (push) Successful in 35s
Build and deploy / deploy (push) Successful in 35s
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
FROM python:3-alpine
|
||||
COPY receive.py /receive.py
|
||||
CMD ["python", "/receive.py"]
|
||||
@@ -0,0 +1,34 @@
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
import os, tarfile, io, shutil, time
|
||||
|
||||
SECRET = os.environ["WEBHOOK_SECRET"]
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
if self.headers.get("X-Webhook-Secret") != SECRET:
|
||||
self.send_response(401)
|
||||
self.end_headers()
|
||||
return
|
||||
|
||||
body = self.rfile.read(int(self.headers["Content-Length"]))
|
||||
|
||||
for item in os.listdir("/data"):
|
||||
path = os.path.join("/data", item)
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
else:
|
||||
os.remove(path)
|
||||
|
||||
with tarfile.open(fileobj=io.BytesIO(body), mode="r:gz") as tar:
|
||||
tar.extractall("/data", filter="data")
|
||||
|
||||
with open("/data/.deploy-timestamp", "w") as f:
|
||||
f.write(str(time.time()))
|
||||
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(b"OK")
|
||||
|
||||
|
||||
HTTPServer(("0.0.0.0", 9000), Handler).serve_forever()
|
||||
Reference in New Issue
Block a user