mirror of
https://github.com/JuliusFreudenberger/portainer-stack-git-redeploy-action.git
synced 2025-05-10 12:12:37 +02:00
Update action to update git stacks
This commit is contained in:
parent
b779a44ee2
commit
646000f132
5 changed files with 59 additions and 104 deletions
71
dist/index.js
vendored
71
dist/index.js
vendored
|
@ -2823,6 +2823,7 @@ let portainerUrl = core.getInput("portainerUrl")
|
|||
const accessToken = core.getInput("accessToken")
|
||||
const stackId = parseInt(core.getInput("stackId"))
|
||||
const endpointId = parseInt(core.getInput("endpointId"))
|
||||
const environmentVariables = core.getInput("environment")
|
||||
|
||||
if (isNaN(stackId)) {
|
||||
core.setFailed("Stack ID must be integer")
|
||||
|
@ -2848,67 +2849,39 @@ if (portainerUrl.substring(portainerUrl.length - 1) === "/") {
|
|||
core.setSecret(portainerUrl)
|
||||
core.setSecret(accessToken)
|
||||
|
||||
client.get(`${portainerUrl}/api/stacks/${stackId}/file`, {
|
||||
const postDataObject = {
|
||||
pullImage: true,
|
||||
}
|
||||
|
||||
console.dir(environmentVariables)
|
||||
if (environmentVariables !== undefined && environmentVariables !== "") {
|
||||
postDataObject.env = JSON.parse(environmentVariables)
|
||||
}
|
||||
|
||||
const postData = JSON.stringify(postDataObject)
|
||||
|
||||
console.dir(postData)
|
||||
|
||||
const req = client.request(`${portainerUrl}/api/stacks/${stackId}/git/redeploy` + (isNaN(endpointId) ? "" : `?endpointId=${endpointId}`), {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"X-API-Key": accessToken
|
||||
"X-API-Key": accessToken,
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": Buffer.byteLength(postData)
|
||||
}
|
||||
}, (res) => {
|
||||
if (res.statusCode !== 200) {
|
||||
core.setFailed(res.statusMessage)
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
let result = ""
|
||||
res.setEncoding("utf8")
|
||||
res.on("data", (chunk) => result = result + chunk)
|
||||
res.on("end", () => {
|
||||
let stackFileContent
|
||||
|
||||
try {
|
||||
// noinspection JSUnresolvedVariable
|
||||
stackFileContent = JSON.parse(result).StackFileContent
|
||||
|
||||
if (stackFileContent === undefined) {
|
||||
// noinspection ExceptionCaughtLocallyJS
|
||||
throw Error("Wrong stack file content")
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
process.exit(4)
|
||||
}
|
||||
|
||||
const postData = JSON.stringify({
|
||||
pullImage: true,
|
||||
stackFileContent
|
||||
})
|
||||
|
||||
const req = client.request(`${portainerUrl}/api/stacks/${stackId}` + (isNaN(endpointId) ? "" : `?endpointId=${endpointId}`), {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"X-API-Key": accessToken,
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": Buffer.byteLength(postData)
|
||||
}
|
||||
}, (res) => {
|
||||
if (res.statusCode !== 200) {
|
||||
core.setFailed(res.statusMessage)
|
||||
process.exit(2)
|
||||
}
|
||||
})
|
||||
.on("error", (error) => {
|
||||
core.setFailed(error.message)
|
||||
process.exit(3)
|
||||
})
|
||||
|
||||
req.write(postData)
|
||||
req.end()
|
||||
})
|
||||
})
|
||||
.on("error", (error) => {
|
||||
core.setFailed(error.message)
|
||||
process.exit(3)
|
||||
})
|
||||
.end()
|
||||
|
||||
req.write(postData)
|
||||
req.end()
|
||||
|
||||
})();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue