From 63d9c75bc2897c0c2f07fd70774a273363829b78 Mon Sep 17 00:00:00 2001 From: Julius Freudenberger Date: Tue, 22 Aug 2023 17:50:06 +0200 Subject: [PATCH 1/3] Improve logging --- dist/index.js | 6 ++++-- index.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index a01500e..f0f4914 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2819,6 +2819,8 @@ var __webpack_exports__ = {}; (() => { const core = __nccwpck_require__(186) +console.log('Preparing stack deployment') + let portainerUrl = core.getInput("portainerUrl") const accessToken = core.getInput("accessToken") const stackId = parseInt(core.getInput("stackId")) @@ -2853,14 +2855,13 @@ const postDataObject = { pullImage: true, } -console.dir(environmentVariables) if (environmentVariables !== undefined && environmentVariables !== "") { postDataObject.env = JSON.parse(environmentVariables) } const postData = JSON.stringify(postDataObject) -console.dir(postData) +console.log(`Deploying stack ${stackId} on portainer host ${portainerUrl} ${postDataObject.env ? 'With environment variables ' + JSON.stringify(postDataObject.env) : 'clearing all environment variables.'}`) const req = client.request(`${portainerUrl}/api/stacks/${stackId}/git/redeploy` + (isNaN(endpointId) ? "" : `?endpointId=${endpointId}`), { method: "PUT", @@ -2874,6 +2875,7 @@ const req = client.request(`${portainerUrl}/api/stacks/${stackId}/git/redeploy` core.setFailed(res.statusMessage) process.exit(2) } + console.log('Stack deployed successfully') }) .on("error", (error) => { core.setFailed(error.message) diff --git a/index.js b/index.js index 84a70a7..d97e028 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,7 @@ const core = require("@actions/core") +console.log('Preparing stack deployment') + let portainerUrl = core.getInput("portainerUrl") const accessToken = core.getInput("accessToken") const stackId = parseInt(core.getInput("stackId")) @@ -34,14 +36,13 @@ const postDataObject = { pullImage: true, } -console.dir(environmentVariables) if (environmentVariables !== undefined && environmentVariables !== "") { postDataObject.env = JSON.parse(environmentVariables) } const postData = JSON.stringify(postDataObject) -console.dir(postData) +console.log(`Deploying stack ${stackId} on portainer host ${portainerUrl} ${postDataObject.env ? 'With environment variables ' + JSON.stringify(postDataObject.env) : 'clearing all environment variables.'}`) const req = client.request(`${portainerUrl}/api/stacks/${stackId}/git/redeploy` + (isNaN(endpointId) ? "" : `?endpointId=${endpointId}`), { method: "PUT", @@ -55,6 +56,7 @@ const req = client.request(`${portainerUrl}/api/stacks/${stackId}/git/redeploy` core.setFailed(res.statusMessage) process.exit(2) } + console.log('Stack deployed successfully') }) .on("error", (error) => { core.setFailed(error.message) From 80a45233337671fd53e49cd6d0d9995c3cf9e7cf Mon Sep 17 00:00:00 2001 From: Julius Freudenberger Date: Mon, 18 Mar 2024 16:33:31 +0100 Subject: [PATCH 2/3] Add toggle to support stack redeploy with git authentication --- README.md | 4 ++++ action.yml | 4 ++++ dist/index.js | 5 +++++ index.js | 5 +++++ 4 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 9402047..0d6fd20 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,10 @@ This is a fork of [wirgen/portainer-stack-redeploy-action](https://github.com/wi ID of endpoint (environment). Required if your stack is not in local environment +### `repositoryAuthentication` + +Use stored credentials to pull docker-compose.yaml from git repository. When credentials are stored, but this is not set to `true`, the action will fail + ### `environment` Environment variables to set on the stack. When omitted, all existing variables will be cleared from the stack. Must be input as a JSON String; one array of objects each with the keys `name` and `value` diff --git a/action.yml b/action.yml index f21e78f..4233bc9 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,10 @@ inputs: description: 'Endpoint ID' required: false default: '' + repositoryAuthentication: + description: 'Use stored credentials to pull docker-compose.yaml from git repository' + required: false + default: false environment: description: 'Environment variables' required: false diff --git a/dist/index.js b/dist/index.js index f0f4914..147bf1f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2825,6 +2825,7 @@ let portainerUrl = core.getInput("portainerUrl") const accessToken = core.getInput("accessToken") const stackId = parseInt(core.getInput("stackId")) const endpointId = parseInt(core.getInput("endpointId")) +const repositoryAuthentication = core.getInput("repositoryAuthentication") const environmentVariables = core.getInput("environment") if (isNaN(stackId)) { @@ -2855,6 +2856,10 @@ const postDataObject = { pullImage: true, } +if (repositoryAuthentication === true || repositoryAuthentication === 'true') { + postDataObject.repositoryAuthentication = true +} + if (environmentVariables !== undefined && environmentVariables !== "") { postDataObject.env = JSON.parse(environmentVariables) } diff --git a/index.js b/index.js index d97e028..19d693a 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ let portainerUrl = core.getInput("portainerUrl") const accessToken = core.getInput("accessToken") const stackId = parseInt(core.getInput("stackId")) const endpointId = parseInt(core.getInput("endpointId")) +const repositoryAuthentication = core.getInput("repositoryAuthentication") const environmentVariables = core.getInput("environment") if (isNaN(stackId)) { @@ -36,6 +37,10 @@ const postDataObject = { pullImage: true, } +if (repositoryAuthentication === true || repositoryAuthentication === 'true') { + postDataObject.repositoryAuthentication = true +} + if (environmentVariables !== undefined && environmentVariables !== "") { postDataObject.env = JSON.parse(environmentVariables) } From 0544d68626ff877c6586b570ffcaf06822a5bf65 Mon Sep 17 00:00:00 2001 From: Julius Freudenberger Date: Mon, 18 Mar 2024 16:56:57 +0100 Subject: [PATCH 3/3] Update action to node 20 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 4233bc9..da3fd6d 100644 --- a/action.yml +++ b/action.yml @@ -25,7 +25,7 @@ inputs: required: false runs: - using: 'node16' + using: 'node20' main: 'dist/index.js' branding: