portainer-stack-recreate
Version:
A Node.js CLI tool to recreate Portainer Docker stacks with latest images
67 lines (56 loc) • 1.49 kB
JavaScript
/**
* Example usage of portainer-stack-recreate package
* This shows how you could use the functionality programmatically
*/
const { spawn } = require('child_process');
// Example configuration
const config = {
url: 'https://your-portainer-instance.com:9443',
apiKey: 'your-portainer-api-key',
stackName: 'your-stack-name',
insecure: false
};
// Function to run the CLI tool programmatically
function recreateStack(config) {
return new Promise((resolve, reject) => {
const args = [
'--url', config.url,
'--api-key', config.apiKey,
'--stack-name', config.stackName
];
if (config.insecure) {
args.push('--insecure');
}
const child = spawn('portainer-stack-recreate', args, {
stdio: 'inherit',
shell: true
});
child.on('close', (code) => {
if (code === 0) {
resolve('Stack recreated successfully');
} else {
reject(new Error(`Process exited with code ${code}`));
}
});
child.on('error', (error) => {
reject(error);
});
});
}
// Example usage
async function main() {
try {
console.log('🚀 Starting stack recreation...');
const result = await recreateStack(config);
console.log('✅', result);
} catch (error) {
console.error('❌ Error:', error.message);
process.exit(1);
}
}
// Only run if this file is executed directly
if (require.main === module) {
main();
}
module.exports = { recreateStack };