This repository was archived by the owner on Jun 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
52 lines (46 loc) · 1.85 KB
/
app.py
File metadata and controls
52 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from os import name
from flask import Flask, render_template, request, redirect, jsonify
from flask.json import jsonify
import subprocess
import docker
import dockerhub_login
from discord_webhook import DiscordWebhook, DiscordEmbed
import datetime
import discord_key
app = Flask(__name__, static_url_path='/static')
@app.route("/update/", methods =["POST", "GET"])
def update_data():
"""
Does some configuring for dockerhub
"""
client = docker.from_env()
client.login(username=dockerhub_login.username, password=dockerhub_login.password)
"""
If there's a docker instance, pull the latest image from the repo
"""
down = DiscordWebhook(url=discord_key.api_key, content="Xatu is going down for a bit!")
down_response = down.execute()
try:
client.images.pull(dockerhub_login.repo)
# Removes the last instance and pulls the new one
except:
client.images.remove(dockerhub_login.repo + ":latest")
client.images.pull(dockerhub_login.repo)
# Attempts to deploys a docker container
try:
docker_container = client.containers.run(dockerhub_login.repo + ":latest", name= "xatu")
# If a docker container exist with the name, remove it and make a new instance
except:
xatu = client.containers.get("xatu")
xatu.stop()
client.containers.prune()
subprocess.Popen("sudo", "killall", "./main.go")
now = datetime.now()
month = datetime.date.today()
time_stamp = str(now.strftime("%b %d %Y %H:%M:%S"))
up = DiscordWebhook(url=discord_key.api_key, content='Xatu is up again! Done at:\n' + time_stamp)
up_response = up.execute()
docker_container = client.containers.run(dockerhub_login.repo + ":latest", name= "xatu")
return "Now running Xatu!"
if __name__ == '__main__':
app.run(host="0.0.0.0", port=80)