Skip to content

update for self hosted runner and parsing env files per project to allow for multi-stack deployments.

Notifications You must be signed in to change notification settings

patrickaclark/portainer-deploy-action

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Deploy to Portainer - GitHub Action

Description

This GitHub Action deploys multiple Docker Compose files to a Portainer instance. It detects changes in Docker Compose files and either updates the existing stack or creates a new one in the specified Portainer environment.

Repo structure

In order to deploy the docker compose files to the right environment, a specific repo structure is desired so that the action can act accordingly. The first level should be the name of the environment to which the stack will be deployed. Second level is the name of the deployed stack. Below an example:

.
├── .github
│   └── workflows
│       └── deploy.yml
├── production
│   ├── service1
│   │   └── docker-compose.yml
│   ├── service2
│   │   └── docker-compose.yml
│   └── serviceN
│       └── docker-compose.yml
├── staging
│   ├── service1
│   │   └── docker-compose.yml
│   ├── service2
│   │   └── docker-compose.yml
│   └── serviceN
│       └── docker-compose.yml
└── README.md

Inputs

portainer_url: The URL of the Portainer instance.
portainer_api_key: The API key for Portainer authentication.
changed_files_path: Path to the file containing changed Docker Compose files.
environment_file: (OPTIONAL) File containing environment variables 

Example workflow

To use this action in your GitHub workflow, create a .github/workflows/deploy.yml file in your repository with the following content:

name: Deploy to Portainer

on:
  push:
    paths:
      - '**/docker-compose.yml'

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Deploy to Portainer
        uses: ./  # Assuming the action is in the root of your repository
        with:
          portainer_url: ${{ secrets.PORTAINER_URL }}
          portainer_api_key: ${{ secrets.PORTAINER_API_KEY }}
          changed_files_path: 'changed_files.txt' # This file should be generated by a previous step  
          environment_file: '.env' # OPTIONAL: path to environment file

Generating changed_files.txt

You need to generate the changed_files.txt file that contains the paths of changed Docker Compose files. You can do this with a simple shell command:

- name: Get changed Docker Compose files
  run: |
    git diff --name-only HEAD^ HEAD | grep 'docker-compose.yml' > changed_files.txt

Author

Bram Kelchtermans

About

update for self hosted runner and parsing env files per project to allow for multi-stack deployments.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 95.6%
  • Dockerfile 4.4%