Skip to content

Commit

Permalink
Add Git Redeploy Option
Browse files Browse the repository at this point in the history
  • Loading branch information
smashedr committed Jul 26, 2024
1 parent 4b8dbfc commit a75d75d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This action is written from the ground up in VanillaJS and is not a fork/clone o
| endpoint | No | `endpoints[0].Id` | Portainer Endpoint * |
| ref | No | `current reference` | Repository Ref * |
| repo | No | `current repository` | Repository URL * |
| redeploy | No | `false` | Perform Redeploy * |
| tlsskip | No | `false` | Skip Repo TLS Verify |
| prune | No | `true` | Prune Services |
| pull | No | `true` | Pull Images |
Expand All @@ -58,6 +59,8 @@ Useful if you are deploying from another repository. Example: `refs/heads/master
**repo** - This defaults to the repository running the action. If you want to deploy a different repository
put the full http URL to that repository here.

**redeploy** - If using `type` repo and stack already exists, this will perform a git redeploy after the update.

**type** - Type of Deployment. Currently, supports either `repo` or `file`.

**env_json/env_file** - Optional environment variables used when creating the stack. File should be in dotenv format and
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
repo:
description: "Repository URL"
required: false
redeploy:
description: "Redeploy Stack"
required: false
default: "false"
tlsskip:
description: "Skip TLS Repo Verification"
required: false
Expand Down
21 changes: 21 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33112,6 +33112,15 @@ class Portainer {
return response.data
}

async redeployStackRepo(stackID, endpointId, body) {
const response = await this.client.post(
`/stacks/${stackID}/git/redeploy`,
body,
{ params: { endpointId } }
)
return response.data
}

async updateStackString(stackID, endpointId, body) {
const response = await this.client.put(`/stacks/${stackID}`, body, {
params: { endpointId },
Expand Down Expand Up @@ -39808,6 +39817,8 @@ const Portainer = __nccwpck_require__(2275)
const repositoryURL =
core.getInput('repo') || `https://github.com/${owner}/${repo}`
console.log('repositoryURL:', repositoryURL)
const redeploy = core.getBooleanInput('redeploy')
console.log('redeploy:', redeploy)
const tlsskipVerify = core.getBooleanInput('tlsskip')
console.log('tlsskipVerify:', tlsskipVerify)
const prune = core.getBooleanInput('prune')
Expand Down Expand Up @@ -39879,6 +39890,16 @@ const Portainer = __nccwpck_require__(2275)
)
// console.log('stack:', stack)
core.info(`Updated Stack ${stack.Id}: ${stack.Name}`)
if (redeploy) {
core.info(`Redeploying Stack ${stack.Id}: ${stack.Name}`)
stack = await portainer.redeployStackRepo(
stackID,
endpointID,
body
)
// console.log('stack:', stack)
core.info(`Redeployed Stack ${stack.Id}: ${stack.Name}`)
}
} else {
core.info('Stack NOT Found - Deploying NEW Stack')
const body = {
Expand Down
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const Portainer = require('./portainer')
const repositoryURL =
core.getInput('repo') || `https://github.com/${owner}/${repo}`
console.log('repositoryURL:', repositoryURL)
const redeploy = core.getBooleanInput('redeploy')
console.log('redeploy:', redeploy)
const tlsskipVerify = core.getBooleanInput('tlsskip')
console.log('tlsskipVerify:', tlsskipVerify)
const prune = core.getBooleanInput('prune')
Expand Down Expand Up @@ -97,6 +99,16 @@ const Portainer = require('./portainer')
)
// console.log('stack:', stack)
core.info(`Updated Stack ${stack.Id}: ${stack.Name}`)
if (redeploy) {
core.info(`Redeploying Stack ${stack.Id}: ${stack.Name}`)
stack = await portainer.redeployStackRepo(
stackID,
endpointID,
body
)
// console.log('stack:', stack)
core.info(`Redeployed Stack ${stack.Id}: ${stack.Name}`)
}
} else {
core.info('Stack NOT Found - Deploying NEW Stack')
const body = {
Expand Down
9 changes: 9 additions & 0 deletions src/portainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ class Portainer {
return response.data
}

async redeployStackRepo(stackID, endpointId, body) {
const response = await this.client.post(
`/stacks/${stackID}/git/redeploy`,
body,
{ params: { endpointId } }
)
return response.data
}

async updateStackString(stackID, endpointId, body) {
const response = await this.client.put(`/stacks/${stackID}`, body, {
params: { endpointId },
Expand Down

0 comments on commit a75d75d

Please sign in to comment.