GithubHelp home page GithubHelp logo

yeckey / portainer-stack-utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from greenled/portainer-stack-utils

0.0 2.0 0.0 82 KB

Deploy/update/undeploy script for portainer stacks

Home Page: https://hub.docker.com/r/greenled/portainer-stack-utils/

License: GNU General Public License v3.0

Dockerfile 3.95% Shell 96.05%

portainer-stack-utils's Introduction

Portainer Stack Utils

Docker Automated build Docker Pulls Microbadger

Bash script to deploy/update/undeploy stacks in a Portainer instance from a docker-compose yaml file. Based on previous work by @vladbabii on docker-how-to/portainer-bash-scripts.

Supported Portainer API

Script was created for the latest Portainer API, which at the time of writing is 1.9.2.

How to install

Just clone the repo and use the script

git clone https://github.com/greenled/portainer-stack-utils.git
cd portainer-stack-utils
./psu ...

Requirements

You will need these dependecies installed:

For Debian and similar apt-powered systems: apt install bash httpie jq.

How to use

The provided psu script allows to deploy/update/undeploy Portainer stacks. Settings can be passed through envvars and/or flags. Both envvars and flags can be mixed but flags will always overwrite envvar values. When deploying a stack, if it doesn't exist a new one is created, otherwise it's updated (unless strict mode is active).

With envvars

This is particularly useful for CI/CD pipelines.

  • ACTION ("deploy" or "undeploy", required): Whether to deploy or undeploy the stack
  • PORTAINER_USER (string, required): Username
  • PORTAINER_PASSWORD (string, required): Password
  • PORTAINER_URL (string, required): URL to Portainer
  • PORTAINER_STACK_NAME (string, required): Stack name
  • DOCKER_COMPOSE_FILE (string, required if action=deploy): Path to doker-compose file
  • PORTAINER_PRUNE ("true" or "false", optional): Whether to prune unused containers or not. Defaults to "false".
  • PORTAINER_ENDPOINT (int, optional): Which endpoint to use. Defaults to 1.
  • HTTPIE_VERIFY_SSL ("yes" or "no", optional): Whether to verify SSL certificate or not. Defaults to "yes".
  • VERBOSE_MODE ("true" or "false", optional): Whether to activate verbose output mode or not. Defaults to "false". See verbose mode below.
  • DEBUG_MODE ("true" or "false", optional): Whether to activate debug output mode or not. Defaults to "false". See debug mode below.
  • STRICT_MODE ("true" or "false", optional): Whether to activate strict mode or not. Defaults to "false". See strict mode below.

Examples

export ACTION="deploy"
export PORTAINER_USER="admin"
export PORTAINER_PASSWORD="password"
export PORTAINER_URL="http://portainer.local"
export PORTAINER_STACK_NAME="mystack"
export DOCKER_COMPOSE_FILE="/path/to/docker-compose.yml"

./psu
export ACTION="undeploy"
export PORTAINER_USER="admin"
export PORTAINER_PASSWORD="password"
export PORTAINER_URL="http://portainer.local"
export PORTAINER_STACK_NAME="mystack"

./psu

With flags

This is more suitable for standalone script usage.

  • -a ("deploy" or "undeploy", required): Whether to deploy or undeploy the stack
  • -u (string, required): Username
  • -p (string, required): Password
  • -l (string, required): URL to Portainer
  • -n (string, required): Stack name
  • -c (string, required if action=deploy): Path to doker-compose file
  • -r ("true" or "false", optional): Whether to prune unused containers or not. Defaults to "false".
  • -e (int, optional): Which endpoint to use. Defaults to 1.
  • -s ("yes" or "no", optional): Whether to verify SSL certificate or not. Defaults to "yes".
  • -v ("true" or "false", optional): Whether to activate verbose output mode or not. Defaults to "false". See verbose mode below.
  • -d ("true" or "false", optional): Whether to activate debug output mode or not. Defaults to "false". See debug mode below.
  • -t ("true" or "false", optional): Whether to activate strict mode or not. Defaults to "false". See strict mode below.

Examples

./psu -a deploy -u admin -p password -l http://portainer.local -n mystack -c /path/to/docker-compose.yml
./psu -a undeploy -u admin -p password -l http://portainer.local -n mystack

Verbose mode

In verbose mode the script prints execution steps.

Getting auth token...
Getting stack mystack...
Stack mystack not found.
Getting Docker info...
Getting swarm cluster (if any)...
Swarm cluster found.
Preparing stack JSON...
Creating stack mystack...

Verbose mode can be enabled through VERBOSE_MODE envvar or -v flag.

Debug mode

In debug mode the script prints as much information as possible to help diagnosing a malfunction.

WARNING: Debug mode will print configuration values (with Portainer credentials) and Portainer API responses (with sensitive information like authentication token and stacks environment variables). Avoid using debug mode in CI/CD pipelines, as pipeline logs are usually recorded.

Debug mode can be enabled through DEBUG_MODE envvar or -d flag.

Strict mode

In strict mode the script never updates an existent stack nor removes an unexistent one, and instead exits with an error.

Strict mode can be enabled through STRICT_MODE envvar or -t flag.

License

Source code contained by this project is licensed under the GNU General Public License version 3. See LICENSE file for reference.

portainer-stack-utils's People

Contributors

greenled avatar yeckey avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.