Portainer-stack-deploy is a GitHub Action for deploying a newly updated stack to a Portainer v2 instance.
Find a file
loadi 0a152f643c
All checks were successful
build-test / build-and-test (push) Successful in 2m10s
Fix output
2025-12-03 20:18:13 +01:00
.forgejo Add auto detection for endpointId 2025-06-21 09:10:07 +02:00
.idea Cleanup in api 2025-03-13 00:45:05 +01:00
__tests__ Remove swarm enforcement 2025-06-21 10:40:13 +02:00
dist Fix output 2025-12-03 20:18:13 +01:00
nbproject Add auto detection for endpointId 2025-06-21 09:10:07 +02:00
src Fix output 2025-12-03 20:18:13 +01:00
.eslintrc.json Update all dependencies 2021-12-04 21:20:32 +01:00
.gitattributes Initial commit 2021-04-11 13:26:28 +02:00
.gitignore Add auto detection for endpointId 2025-06-21 09:10:07 +02:00
.prettierignore Initial commit 2021-04-11 13:26:28 +02:00
.prettierrc.json Logout from Portainer even when it something fails 2021-12-05 02:15:49 +01:00
action.yml Update action.yml 2025-03-13 22:47:54 +01:00
eslint.config.mjs modernize app 2025-03-13 00:59:26 +01:00
example-stack-definition-with-template-variables.yml Add test for template variables 2022-02-04 21:51:37 +01:00
example-stack-definition.yml Update documentation 2021-12-28 21:43:36 +01:00
jest.config.js Initial commit 2021-04-11 13:26:28 +02:00
LICENSE Initial commit 2021-04-11 13:26:28 +02:00
package-lock.json Merge pull request #29 from dann41/dependabot/npm_and_yarn/eslint-9.28.0 2025-06-10 22:43:31 +02:00
package.json Merge pull request #29 from dann41/dependabot/npm_and_yarn/eslint-9.28.0 2025-06-10 22:43:31 +02:00
README.md Add auto detection for endpointId 2025-06-21 09:10:07 +02:00
renovate.json Add auto detection for endpointId 2025-06-21 09:10:07 +02:00
tsconfig.json Cleanup in api 2025-03-13 00:45:05 +01:00
tsconfig.publish.json Update all dependencies 2021-12-04 21:20:32 +01:00

Portainer Stack Deploy

Portainer-stack-deploy is a GitHub Action for deploying a newly updated stack to a Portainer v2 instance. This action is useful when you have a continuous deployment pipeline. The action itself is inspired by how you deploy a task definition to Amazon ECS.

Currently works on Portainer API v2.

Action Inputs

Input Description Default
portainer-host Portainer host, eg. https://myportainer.instance.com Required
access-token User access token for Portainer API. NOTE: Do not use access tokens for admin account! Create a new CI specific login instead Required
swarm-id ID of the swarm. Only required if you deploy to a swarm
endpoint-id ID of the Portainer node to deploy to 1
stack-name Name for the Portainer stack Required
stack-definition The path to the docker-compose stack stack definition file from repo root, eg. stack-definition.yml Required
template-variables If given, these variables will be replaced in docker-compose file by handlebars
image The URI of the container image to insert into the stack definition, eg. ghcr.io/username/repo:sha-676cae2. Will use existing image inside stack definition if not provided

Example

The example below shows how the portainer-stack-deploy action can be used to deploy a fresh version of your app to Portainer using ghcr.io.

name: Deploy

on:
  push:
    branches:
      - master

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    timeout-minutes: 20

    env:
      GITHUB_REF: ${{ github.ref }}
      DOCKER_REGISTRY: ghcr.io
      DOCKER_IMAGE: github-username/my-awesome-web-app

    steps:
      - uses: actions/checkout@v2

      - name: Creating envs
        run: |
          echo "IMAGE_TAG=sha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
          echo "DOCKER_IMAGE_URI=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}" >> $GITHUB_ENV

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ${{ env.DOCKER_REGISTRY }}
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build docker image and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: ${{ env.DOCKER_IMAGE_URI }}:${{ env.IMAGE_TAG }},${{ env.DOCKER_IMAGE_URI }}:latest

      - name: Sleep for 10 seconds
        run: sleep 10s
        shell: bash

      - name: Deploy stack to Portainer
        uses: dann41/portainer-stack-deploy@v1
        with:
          portainer-host: ${{ secrets.PORTAINER_HOST }}
          access-token: ${{ secrets.PORTAINER_ACCESS_TOKEN }}
          stack-name: 'my-awesome-web-app'
          stack-definition: 'stack-definition.yml'
          template-variables: '{"username": "MrCool"}'
          image: ${{ env.DOCKER_IMAGE_URI }}:${{ env.IMAGE_TAG }}

The stack-definition.yml file would be placed in the root of the repository and might look something like this:

version: '3.7'

services:
  server:
    image: ghcr.io/{{username}}/my-awesome-web-app:latest
    deploy:
      update_config:
        order: start-first

Development

Feel free contributing.

Running unit tests

npm test

Build, check linting, run tests

npm run all