mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 14:43:05 -04:00
rework updates and deployments
This commit is contained in:
parent
3676dfaf70
commit
4639d11a7e
2 changed files with 51 additions and 19 deletions
33
commands/message/dev/deploy.js
Normal file
33
commands/message/dev/deploy.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "update",
|
||||||
|
label: "flags",
|
||||||
|
metadata: {
|
||||||
|
description: `Queries pb manager to trigger a deploy and restart flow`,
|
||||||
|
description_short: '[MANAGER] Query deploy',
|
||||||
|
examples: ['update'],
|
||||||
|
category: 'dev',
|
||||||
|
usage: 'update'
|
||||||
|
},
|
||||||
|
onBefore: context => context.user.isClientOwner,
|
||||||
|
onCancel: () => { },
|
||||||
|
run: async (context) => {
|
||||||
|
if (process.env.environment == "prodnew") return await editOrReply(context, createEmbed("error", "Cannot deploy on this instance."))
|
||||||
|
await editOrReply(context, createEmbed("loading", context, "Querying deploy..."))
|
||||||
|
|
||||||
|
try {
|
||||||
|
const t = Date.now()
|
||||||
|
|
||||||
|
// Call server to query update
|
||||||
|
await superagent.post(`${process.env.PB_MANAGER_HOST}_pbs/DeployPbService`)
|
||||||
|
.set("Authorization", process.env.PB_MANAGER_KEY)
|
||||||
|
|
||||||
|
return await editOrReply(context, createEmbed("success", "Deployment queried at manager. Shutting down."))
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
return await editOrReply(context, createEmbed("error", "Manager reported error during deploy query."))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,34 +1,33 @@
|
||||||
const { createEmbed } = require('../../../labscore/utils/embed')
|
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||||
const { editOrReply } = require('../../../labscore/utils/message')
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
|
||||||
const { execSync } = require("child_process");
|
|
||||||
const { icon, highlight, smallPill } = require('../../../labscore/utils/markdown');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "update",
|
name: "update",
|
||||||
label: "flags",
|
label: "flags",
|
||||||
metadata: {
|
metadata: {
|
||||||
description: `Fetches latest bot version.\nUse ${smallPill('-f')} to force an update.`,
|
description: `Queries pb manager to trigger an update flow`,
|
||||||
description_short: 'Bot update',
|
description_short: '[MANAGER] Query update',
|
||||||
examples: ['update -f'],
|
examples: ['update'],
|
||||||
category: 'dev',
|
category: 'dev',
|
||||||
usage: 'update [-f]'
|
usage: 'update'
|
||||||
},
|
},
|
||||||
onBefore: context => context.user.isClientOwner,
|
onBefore: context => context.user.isClientOwner,
|
||||||
onCancel: ()=>{},
|
onCancel: () => { },
|
||||||
run: async (context, args) => {
|
run: async (context) => {
|
||||||
let response = await editOrReply(context, createEmbed("loading", context, "Updating bot..."))
|
if (process.env.environment == "prodnew") return await editOrReply(context, createEmbed("error", "Cannot update on this instance."))
|
||||||
try{
|
await editOrReply(context, createEmbed("loading", context, "Querying manager..."))
|
||||||
const t = Date.now()
|
|
||||||
if(args.flags.includes('-force') || args.flags.includes('-f')) execSync("git checkout .")
|
|
||||||
const r = execSync("git pull")
|
|
||||||
if(r.toString().includes("Already up to date.")) return await editOrReply(context, {embeds: [createEmbed("warning", context, "Already up to date.")]})
|
|
||||||
|
|
||||||
let com = r.toString().match(/([a-z0-9]{7})\.\.([a-z0-9]{7})/)
|
try {
|
||||||
return await editOrReply(context, { content: `${icon("success_simple")} Updated ${highlight(com[1] + ' -> ' + com[2])} in ${((Date.now() - t) / 1000).toFixed(2)}s`, embeds: []})
|
const t = Date.now()
|
||||||
}catch(e){
|
|
||||||
|
// Call server to query update
|
||||||
|
await superagent.post(`${process.env.PB_MANAGER_HOST}_pbs/UpdatePbService`)
|
||||||
|
.set("Authorization", process.env.PB_MANAGER_KEY)
|
||||||
|
|
||||||
|
return await editOrReply(context, createEmbed("success", "Update queried at manager"))
|
||||||
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return await editOrReply(context, createEmbed("error", context, "Update failed. Use -f to force update."))
|
return await editOrReply(context, createEmbed("error", "Manager reported error during update query."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Add table
Add a link
Reference in a new issue