def update_deploy_by_id(id): action = request.form.get("action") deploy = deploys.get(id) if action == "redeploy": new_deploy = deploys.create(user_id=deploy.user_id, project_id=deploy.project_id, host_id=deploy.host_id, mode=deploy.mode, status=2, branch=deploy.branch, version=deploy.version, softln_filename=deploy.softln_filename) deploys.deploy(new_deploy) return jsonify(dict(rc=0, data=dict(id=new_deploy.id))) elif action == "rollback": new_deploy = deploys.create(user_id=deploy.user_id, project_id=deploy.project_id, host_id=deploy.host_id, mode=2, status=2, branch=deploy.branch, version=deploy.version, softln_filename=deploy.softln_filename) deploys.rollback(new_deploy) return jsonify(dict(rc=0, data=dict(id=new_deploy.id))) else: raise Error(10000, msg=None)
def update_deploy_by_id(id): action = request.form.get("action") deploy = deploys.get(id) if action == "redeploy": new_deploy = deploys.create( user_id=deploy.user_id, project_id=deploy.project_id, host_id=deploy.host_id, mode=deploy.mode, status=2, branch=deploy.branch, version=deploy.version, softln_filename=deploy.softln_filename) deploys.deploy(new_deploy) return jsonify(dict(rc=0, data=dict(id=new_deploy.id))) elif action == "rollback": new_deploy = deploys.create( user_id=deploy.user_id, project_id=deploy.project_id, host_id=deploy.host_id, mode=2, status=2, branch=deploy.branch, version=deploy.version, softln_filename=deploy.softln_filename) deploys.rollback(new_deploy) return jsonify(dict(rc=0, data=dict(id=new_deploy.id))) else: raise Error(10000, msg=None)
def api_post_deploy(): project_id = request.args.get("project_id") host_id = request.args.get("host_id") branch = request.form.get("branch") commit = request.form.get("commit") deploy = deploys.create( user_id=g.user.id, project_id=project_id, host_id=host_id, mode=0, status=2, branch=branch, version=commit, softln_filename=time.strftime("%Y%m%d-%H%M%S") + "-" + commit, ) deploys.deploy(deploy) return jsonify(dict(rc=0, data=dict(id=deploy.id)))
def api_post_deploy(): project_id = request.args.get("project_id") host_id = request.args.get("host_id") mode = request.form.get("mode", type=int) branch = request.form.get("branch") if mode == 0 else "" tag = request.form.get("tag") commit = request.form.get("commit") if mode == 0 else tag deploy = deploys.create( user_id=g.user.id, project_id=project_id, host_id=host_id, mode=mode, status=2, branch=branch, version=commit, softln_filename=time.strftime("%Y%m%d-%H%M%S") + "-" + commit, ) deploys.deploy(deploy) return jsonify(dict(rc=0, data=dict(id=deploy.id)))
def update_deploy_by_id(id): action = request.form.get("action") deploy = deploys.get(id) if action == "redeploy": new_deploy = deploys.create( user_id=deploy.user_id, project_id=deploy.project_id, host_id=deploy.host_id, mode=deploy.mode, status=2, branch=deploy.branch, version=deploy.version, softln_filename=deploy.softln_filename) deploys.deploy(new_deploy) return jsonify(dict(rc=0, data=dict(id=new_deploy.id))) elif action == "rollback": # new_deploy = deploys.create( # user_id=deploy.user_id, # project_id=deploy.project_id, # host_id=deploy.host_id, # mode=2, # status=2, # branch=deploy.branch, # version=deploy.version, # softln_filename=deploy.softln_filename) # deploys.rollback(new_deploy) # return jsonify(dict(rc=0, data=dict(id=new_deploy.id))) msg = deploys_new.rollback(deploy) deploys.update(deploy, **dict(deploy_status=2)) return jsonify(dict(rc=0, msg=msg)) elif action == "publish": msg = deploys_new.publish(deploy) deploys.update(deploy, **dict(deploy_status=1)) return jsonify(dict(rc=0, msg=msg)) elif action == "cancel": deploys.update(deploy, **dict(deploy_status=99)) return jsonify(dict(rc=0, data=None)) else: return jsonify(dict(rc=-1, msg="action is not supported"))
def webhooks_push_events(): project_id = request.args.get("project_id") host_id = request.args.get("host_id") data = request.json branch = data["ref"].split("/", 2)[-1] version = data["after"][:7] # 只针对dev分支进行deploy if data["ref"] == "refs/heads/dev" and data["total_commits_count"] > 0: deploy = deploys.create( user_id=g.user.id, project_id=project_id, host_id=host_id, mode=0, status=2, branch=branch, version=version, softln_filename=time.strftime("%Y%m%d-%H%M%S") + "-" + version, ) deploys.deploy(deploy) return jsonify({"rc": 0}), 200 else: return jsonify({"rc": 0}), 204
def webhooks_tag_push_events(): project_id = request.args.get("project_id") host_id = request.args.get("host_id") data = request.json tag = data["ref"].split("/", 2)[-1] logger.debug(repr(data)) # 只针对tag push if data["object_kind"] == "tag_push" and data["total_commits_count"] > 0: deploy = deploys.create( user_id=g.user.id, project_id=project_id, host_id=host_id, mode=1, status=3, branch="", version=tag, softln_filename=time.strftime("%Y%m%d-%H%M%S") + "-" + tag, ) deploys.deploy(deploy) return jsonify({"rc": 0}), 200 else: return jsonify({"rc": 0}), 204
def webhooks_tag_push_events(): project_id = request.args.get("project_id") host_id = request.args.get("host_id") data = request.json tag = data["ref"].split("/", 2)[-1] logger.debug(repr(data)) # 只针对tag push if data["object_kind"] == "tag_push" and data["total_commits_count"] > 0: deploy = deploys.create( user_id=g.user.id, project_id=project_id, host_id=host_id, mode=1, status=2, branch="", version=tag, softln_filename=time.strftime("%Y%m%d-%H%M%S") + "-" + tag, ) deploys.deploy(deploy) return jsonify({"rc": 0}), 200 else: return jsonify({"rc": 0}), 204
def webhooks_push_events(): project_id = request.args.get("project_id") host_id = request.args.get("host_id") data = request.json branch = data["ref"].split("/", 2)[-1] version = data["after"][:7] logger.debug(repr(data)) # 只针对dev分支进行deploy if data["ref"] == "refs/heads/dev" and data["total_commits_count"] > 0: deploy = deploys.create( user_id=g.user.id, project_id=project_id, host_id=host_id, mode=0, status=3, branch=branch, version=version, softln_filename=time.strftime("%Y%m%d-%H%M%S") + "-" + version, ) deploys.deploy(deploy) return jsonify({"rc": 0}), 200 else: return jsonify({"rc": 0}), 204