Commit 979c06d7 by chalermpong

debug file

parent 22709861
......@@ -47,6 +47,8 @@ app.post('/apply-state', async (req, res) => {
await controllers.dockerFileStatus(results, salt);
} else if (state === 'dockerps') {
return controllers.getDockerPsStatus(results, res);
} else if (state === 'checkversion') {
return controllers.getImageVersion(results, res);
}
res.status(200).send({ message: 'Salt state applied successfully', results });
......
// controller/getDockerImageVersion.js
async function getImageVersion (results, res) {
try {
const output = results['salt-minion']['cmd_|-docker_ps_status_|-docker images_|-run']['changes']['stdout'];
const lines = output.split('\n');
const images = lines.slice(1).filter(line => line.trim() !== '').map(line => {
const parts = line.trim().split(/\s{2,}/);
return {
repository: parts[0],
tag: parts[1],
size: parts[parts.length - 1] // แก้ไขส่วนนี้เพื่อให้แสดง size ถูกต้อง
};
});
return res.status(200).json({ message: 'Salt state applied successfully', images });
} catch (error) {
console.error('Error processing docker images output:', error);
res.status(500).send({ error: 'Error processing docker images output', details: error.message });
}
};
module.exports = getImageVersion
\ No newline at end of file
......@@ -6,6 +6,7 @@ const checkDirectory = require('./checkDirectory');
const updateImage = require('./updateImage');
const install_packages = require('./installpackages');
const getDockerPsStatus = require('./getDockerPsStatus');
const getImageVersion = require('./getImageVersion');
module.exports = {
checkDockerStatus,
runDockerComposeUp,
......@@ -14,5 +15,6 @@ module.exports = {
checkDirectory,
updateImage,
install_packages,
getDockerPsStatus
getDockerPsStatus,
getImageVersion
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment