Example #1
0
def main_lopp():
    with app.app_context():
        while True:
            apps = get_all_apps()
            find_problem_apps(apps)
            try_deploy_problem_apps()
            sleep(60)
Example #2
0
def remove_docker(container_id):
    with app.app_context():
        client = docker.from_env()
        try:
            container = client.containers.get(container_id)
            container.stop()
            container.remove()
        except docker.errors.APIError:
            pass
Example #3
0
def start_new_docker(app_name):
    with app.app_context():
        client = docker.from_env()
        str_env = "APP_NAME=" + app_name
        server_key_env = "SERVER_KEY=" + get_server_key()
        port = get_port()
        container = client.containers.run(
            'vktestapp',
            ports={'8080/tcp': port},
            detach=True,
            environment=[str_env, server_key_env])
        return port, container.id
Example #4
0
def restart_docker(app_name, container_id, port):
    with app.app_context():
        client = docker.from_env()
        try:
            container = client.containers.get(container_id)
            container.stop()
            container.remove()
        #if container remove, but exist in database
        except docker.errors.APIError:
            port = get_port()
        str_env = "APP_NAME=" + app_name
        server_key_env = "SERVER_KEY=" + get_server_key()
        container = client.containers.run(
            'vktestapp',
            ports={'8080/tcp': port},
            detach=True,
            environment=[str_env, server_key_env])
        return port, container.id
Example #5
0
def delete_app(app_name):
    with app.app_context():
        cursor = get_db().cursor()
        sql = "DELETE FROM Apps WHERE appName=?"
        cursor.execute(sql, [app_name])
        get_db().commit()
Example #6
0
def get_info_app(app_name):
    with app.app_context():
        cursor = get_db().cursor()
        sql = "SELECT * FROM Apps WHERE appName=?"
        cursor.execute(sql, [app_name])
        return cursor.fetchone()
Example #7
0
def get_all_apps():
    with app.app_context():
        cursor = get_db().cursor()
        sql = "SELECT * FROM Apps "
        cursor.execute(sql)
        return cursor.fetchall() 
Example #8
0
def update_info_app(app_name, url, port, container):
    with app.app_context():
        cursor = get_db().cursor()
        sql = "UPDATE Apps SET url = ? , container = ? , port = ? WHERE appName=?"
        cursor.execute(sql, [url, container, port, app_name])
        get_db().commit()
Example #9
0
def set_info_app(app_name, url, port, container):
    with app.app_context():
        cursor = get_db().cursor()
        sql = "INSERT INTO Apps VALUES (?, ?, ?, ?)"
        cursor.execute(sql, [app_name, url, port, container])
        get_db().commit()
Example #10
0
def init_db():
    with app.app_context():
        db = get_db()
        with app.open_resource('Database/schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()