2019-12-04 14:23:08 +00:00
< h1 > Portainer Stack Utils< / h1 >
< div class = "docsify-hidden" >
2018-11-21 19:23:18 +00:00
2019-12-04 14:23:08 +00:00
[![Docker Pulls ](https://img.shields.io/docker/pulls/psuapp/psu.svg )](https://hub.docker.com/r/psuapp/psu/)
2021-09-14 12:04:15 +00:00
[![pipeline status ](https://gitlab.com/psuapp/psu/badges/1-3-next/pipeline.svg )](https://gitlab.com/psuapp/psu/commits/1-3-next)
2018-11-21 20:01:20 +00:00
2019-12-04 14:23:08 +00:00
Bash script to deploy/update/remove stacks in a [Portainer ](https://portainer.io/ ) instance from a [docker-compose ](https://docs.docker.com/compose ) [yaml file ](https://docs.docker.com/compose/compose-file ).
2018-11-21 19:23:18 +00:00
2019-12-04 14:23:08 +00:00
_Based on previous work by [@vladbabii ](https://github.com/vladbabii ) on [docker-how-to/portainer-bash-scripts ](https://github.com/docker-how-to/portainer-bash-scripts )._
< h2 > Table of contents< / h2 >
<!-- Generated by https://github.com/mcpride/atom - mdtoc -->
<!-- MDTOC maxdepth:2 firsth1:2 numbering:0 flatten:0 bullets:1 updateOnSave:1 -->
2018-11-21 20:37:05 +00:00
2019-12-04 14:23:08 +00:00
- [How to install ](#how-to-install )
- [Standalone ](#standalone )
2021-12-01 16:47:21 +00:00
- [Docker image, variants and multi-architecture ](#docker-image-variants-and-multi-architecture )
2019-12-04 14:23:08 +00:00
- [How to use ](#how-to-use )
- [With options ](#with-options )
- [With flags ](#with-flags )
- [With envvars ](#with-envvars )
- [Documentation ](#documentation )
- [Supported Portainer API ](#supported-portainer-api )
- [License ](#license )
<!-- /MDTOC -->
< / div >
2018-11-21 20:37:05 +00:00
2018-11-26 19:40:50 +00:00
## How to install
2019-06-10 05:31:34 +00:00
### Standalone
2021-09-23 15:22:15 +00:00
> **Note**: The easiest way to install `psu` is to use [Docker method](#docker-image-and-variants), instead of this one
Check the [Requirements ](#requirements ) section then [git] clone the repo and use the [bash] script below:
2021-09-14 12:04:15 +00:00
2018-11-26 19:40:50 +00:00
```bash
2019-12-04 14:23:08 +00:00
git clone https://gitlab.com/psuapp/psu.git
cd psu/
2021-09-14 08:54:22 +00:00
# Allow the 'psu' command to run everywhere:
export PATH="$(pwd):$PATH"
# Or if you want it permanent, with a super user account, run:
# ln -s $(pwd)/psu /usr/local/bin
#
# Then you can use psu, e.g.
psu deploy ...
2018-11-26 19:40:50 +00:00
```
2019-08-11 07:40:46 +00:00
For detailed instructions, see [How to use ](#how-to-use ) section.
2019-06-10 05:31:34 +00:00
#### Requirements
2018-11-26 19:40:50 +00:00
2019-08-11 07:40:32 +00:00
You will need these dependencies installed:
2018-11-21 19:23:18 +00:00
2021-11-25 16:55:53 +00:00
##### [Linux] based systems <small>([Alpine], [Debian], [Ubuntu]...)</small>
2021-09-23 15:22:15 +00:00
- [bash]< sup title = "required" > \*</ sup > < small > (>= 4.4.23)</ small >
- [curl]< sup title = "required" > \*</ sup > < small > (>= 7.64.0, but >= 7.76.0 is recommended)</ small >
- [jq]< sup title = "required" > \*</ sup > < small > (>= 1.5.1)</ small >
- [uuidgen] recommended only for some < abbr title = "Operating System" > OS</ abbr > < small > (Alpine and Debian work fine without it)</ small >
2018-11-21 19:23:18 +00:00
2021-09-23 15:22:15 +00:00
For [Debian] and similar apt-powered [Linux] systems, run: `apt install bash curl jq`
2021-11-25 16:55:53 +00:00
##### [macOS]
2021-09-23 15:22:15 +00:00
- [bash]< sup title = "required" > \*</ sup > < small > (>= 4.4.23)</ small >
- [curl]< sup title = "required" > \*</ sup > < small > (>= 7.64.0, but >= 7.76.0 is recommended)</ small >
- [jq]< sup title = "required" > \*</ sup > < small > (>= 1.5.1)</ small >
- [timeout]< sup title = "required" > \*</ sup > < small > (included in the [coreutils] package)</ small >
- greadlink < small > (included in the [coreutils] package)</ small >
You should install [Homebrew], then run: `brew install bash coreutils jq`
2021-11-25 16:55:53 +00:00
##### [Windows]
2021-09-23 15:22:15 +00:00
- [bash]< sup title = "required" > \*</ sup > < small > (>= 4.4.23)</ small >
- [curl]< sup title = "required" > \*</ sup > < small > (>= 7.64.0, but >= 7.76.0 is recommended)</ small >
- [jq]< sup title = "required" > \*</ sup > < small > (>= 1.5.1)</ small >
2021-09-14 11:41:15 +00:00
2021-09-23 15:22:15 +00:00
> **Note**: `psu`should work with [Windows], but it could be unstable ⚠️
You should download and install [Git ](https://git-scm.com/download/win ) and [jq ](https://stedolan.github.io/jq/download ) for [Windows]
##### For all systems
- [docker-compose] is recommended but not required < small > (useful for linting docker compose/stack files)</ small >
< sup > \*</ sup > = required
2018-11-26 19:40:50 +00:00
2021-12-01 16:47:21 +00:00
### Docker image, variants and multi-architecture
2019-06-10 05:31:34 +00:00
2019-12-04 14:23:08 +00:00
If you don't want or can't install `psu` and its dependencies, you can run it with the default [published Docker image ](https://hub.docker.com/r/psuapp/psu ), like this:
2019-06-10 05:31:34 +00:00
```bash
2021-02-18 14:31:42 +00:00
docker run psuapp/psu:1.2 deploy ...
2019-06-10 05:31:34 +00:00
```
2019-07-24 14:23:39 +00:00
> **Note**: Docker images are also available on [GitLab](https://gitlab.com/psuapp/psu/container_registry).
2019-06-10 05:31:34 +00:00
2019-08-11 07:44:00 +00:00
For detailed instructions, see [How to use ](#how-to-use ) section.
2019-12-04 14:23:08 +00:00
#### Supported tags
Published Docker images are [tagged ](https://hub.docker.com/r/psuapp/psu/tags ) matching [GitLab tags ](https://gitlab.com/psuapp/psu/-/tags ):
2021-09-14 09:24:46 +00:00
<!-- - `dev` -> [`dev` ](https://gitlab.com/psuapp/psu/-/tags/dev ) -->
2021-11-30 17:09:04 +00:00
- `1.3.0-beta.1` -> [`v1.3.0-beta.1` ](https://gitlab.com/psuapp/psu/-/tags/v1.3.0-beta.1 )
2021-09-14 12:10:41 +00:00
- `1.3.0-alpha` -> [`v1.3.0-alpha` ](https://gitlab.com/psuapp/psu/-/tags/v1.3.0-alpha )
2021-09-14 09:24:46 +00:00
- `1` , `1.2` , `1.2.0` -> [`v1.2.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.2.0 )
- `1.2.0-beta.1` -> [`v1.2.0-beta.1` ](https://gitlab.com/psuapp/psu/-/tags/v1.2.0-beta.1 )
- `1.2.0-alpha` -> [`v1.2.0-alpha` ](https://gitlab.com/psuapp/psu/-/tags/v1.2.0-alpha )
- `1.1` , `1.1.0` -> [`v1.1.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.1.0 )
- `1.1.0-alpha` -> [`v1.1.0-alpha` ](https://gitlab.com/psuapp/psu/-/tags/v1.1.0-alpha )
- `1.0` , `1.0.7` -> [`v1.0.7` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.7 )
- `1.0.6` -> [`v1.0.6` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.6 )
- `1.0.5` -> [`v1.0.5` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.5 )
- `1.0.4` -> [`v1.0.4` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.4 )
- `1.0.3` -> [`v1.0.3` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.3 )
- `1.0.2` -> [`v1.0.2` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.2 )
- `1.0.1` -> [`v1.0.1` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.1 )
- `1.0.0` -> [`v1.0.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.0 )
- `0.1.2` -> [`v0.1.2` ](https://gitlab.com/psuapp/psu/-/tags/v0.1.2 )
- `0.1.1` -> [`v0.1.1` ](https://gitlab.com/psuapp/psu/-/tags/v0.1.1 )
- `0.1.0` -> [`v0.1.0` ](https://gitlab.com/psuapp/psu/-/tags/v0.1.0 )
2019-12-04 14:23:08 +00:00
##### Variants
The `core` variant doesn't include `docker-compose` , so it's a bit smaller.
But you can't lint Docker compose/stack file before deploying a stack.
2021-09-14 09:24:46 +00:00
<!-- - `dev-core` -> [`dev` ](https://gitlab.com/psuapp/psu/-/tags/dev ) -->
- `1-core` , `1.2-core` , `1.2.0-core` -> [`v1.2.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.2.0 )
- `1.1-core` , `1.1.0-core` -> [`v1.1.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.1.0 )
- `1.0-core` , `1.0.7-core` -> [`v1.0.7` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.7 )
2019-06-10 05:31:34 +00:00
2019-12-04 14:23:08 +00:00
The `debian` and `debian-core` variants use [Debian ](https://www.debian.org ) instead of [Alpine ](https://alpinelinux.org/ ) as base image for `psu` .
2021-09-14 09:24:46 +00:00
<!-- - `dev-debian` -> [`dev` ](https://gitlab.com/psuapp/psu/-/tags/dev )
- `dev-debian-core` -> [`dev` ](https://gitlab.com/psuapp/psu/-/tags/dev ) -->
2021-02-18 13:04:38 +00:00
2021-09-14 09:24:46 +00:00
- `1-debian` , `1.2-debian` , `1.2.0-debian` -> [`v1.2.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.2.0 )
- `1-debian-core` , `1.2-debian-core` , `1.2.0-debian-core` -> [`v1.2.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.2.0 )
- `1.1-debian` , `1.1.0-debian` -> [`v1.1.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.1.0 )
- `1.1-debian-core` , `1.1.0-debian-core` -> [`v1.1.0` ](https://gitlab.com/psuapp/psu/-/tags/v1.1.0 )
- `1.0-debian` , `1.0.7-debian` -> [`v1.0.7` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.7 )
- `1.0-debian-core` , `1.0.7-debian-core` -> [`v1.0.7` ](https://gitlab.com/psuapp/psu/-/tags/v1.0.7 )
2019-06-10 05:31:34 +00:00
2021-12-01 16:47:21 +00:00
##### Multi-Architecture
The Docker images support multi-architecture: `linux/amd64` , `linux/arm64` and `linux/arm/v7` .
On ARM machines, if you get this error when running a `psu` Docker image:
```
standard_init_linux.go:228: exec user process caused: exec format error
```
You need to install `linux/amd64` QEMU binary, like this:
```bash
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
```
Then run your `psu` Docker image again and it should work 🤞
And if you want to uninstall this QEMU binary, run this command:
```bash
docker run --privileged --rm tonistiigi/binfmt --uninstall linux/amd64
```
2019-12-04 14:23:08 +00:00
#### Testing/debugging:
For testing/debugging, you can use this Docker image in interactive mode, to run any commands inside the container:
```bash
2021-02-18 14:31:42 +00:00
docker run -v $(pwd)/docker-compose.yml:/docker-compose.yml -it --rm --entrypoint bash psuapp/psu:1.2
2019-12-04 14:23:08 +00:00
# Run any commands here! E.g.
$ psu --version
2021-11-30 17:09:04 +00:00
Portainer Stack Utils, version 1.3.0-beta.1
2019-12-04 14:23:08 +00:00
License GPLv3: GNU GPL version 3
```
2019-06-10 05:31:34 +00:00
2018-11-21 19:23:18 +00:00
## How to use
2019-12-04 14:23:08 +00:00
The provided `psu` script allows to deploy/update/remove... Portainer stacks. Settings can be passed through envvars and/or options and/or flags. Both envvars, options and flags can be mixed but options or 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).
2018-11-21 19:23:18 +00:00
2019-12-04 14:23:08 +00:00
### With options
2018-11-21 19:23:18 +00:00
2019-12-04 14:23:08 +00:00
This is more suitable for standalone script usage.
2018-11-21 19:23:18 +00:00
2019-12-04 14:23:08 +00:00
- `<action>` ("deploy", "rm", "ls"..., required): Whether to deploy, remove, list... the stack, _not an option but an argument_
- `--user` (string, required): Username
- `--password` (string, required): Password
- `--url` (string, required): URL to Portainer
- `--name` (string, required): Stack name
- `--compose-file` (string, required if action=deploy): Path to docker-compose file
For detailed instructions, see the full [options list ](docs/README.md#available-options ).
2018-11-24 19:12:47 +00:00
#### Examples
2018-11-21 19:23:18 +00:00
```bash
2021-09-14 08:54:22 +00:00
psu deploy --user admin --password password --url https://portainer.local --name mystack --compose-file /path/to/docker-compose.yml --env-file /path/to/env_vars_file
2018-11-24 19:12:47 +00:00
```
```bash
2021-09-14 08:54:22 +00:00
psu rm --user admin --password password --url https://portainer.local --name mystack
2019-12-04 14:23:08 +00:00
```
2018-11-24 19:12:47 +00:00
2019-12-04 14:23:08 +00:00
**With Docker:**
```bash
2021-02-18 14:31:42 +00:00
docker run -v $(pwd)/docker-compose.yml:/docker-compose.yml -v $(pwd)/.env:/.env psuapp/psu:1.2 deploy --user admin --password password --url https://portainer.local --name mystack --compose-file docker-compose.yml --env-file .env
2018-11-21 19:23:18 +00:00
```
2018-11-24 19:12:47 +00:00
### With flags
2018-11-21 19:23:18 +00:00
2018-11-24 19:12:47 +00:00
This is more suitable for standalone script usage.
2019-12-04 14:23:08 +00:00
- `<action>` ("deploy", "rm", "ls"..., required): Whether to deploy, remove, list... the stack, _not a flag but an argument_
2018-11-24 19:12:47 +00:00
- `-u` (string, required): Username
- `-p` (string, required): Password
- `-l` (string, required): URL to Portainer
- `-n` (string, required): Stack name
2019-12-04 14:23:08 +00:00
- `-c` (string, required if action=deploy): Path to docker-compose file
For detailed instructions, see the full [flags list ](docs/README.md#available-options ).
2018-11-24 19:12:47 +00:00
#### Examples
```bash
2021-09-14 08:54:22 +00:00
psu deploy -u admin -p password -l https://portainer.local -n mystack -c /path/to/docker-compose.yml -g /path/to/env_vars_file
2018-11-24 19:12:47 +00:00
```
2018-11-21 19:23:18 +00:00
```bash
2021-09-14 08:54:22 +00:00
psu rm -u admin -p password -l https://portainer.local -n mystack
2018-11-21 19:23:18 +00:00
```
2018-11-21 20:33:32 +00:00
2019-12-04 14:23:08 +00:00
**With Docker:**
2019-05-11 03:32:32 +00:00
```bash
2021-02-18 14:31:42 +00:00
docker run -v $(pwd)/docker-compose.yml:/docker-compose.yml -v $(pwd)/.env:/.env psuapp/psu:1.2 deploy -u admin -p password -l https://portainer.local -n mystack -c docker-compose.yml -g .env
2019-05-11 03:32:32 +00:00
```
2019-12-04 14:23:08 +00:00
### With envvars
2019-05-11 03:32:32 +00:00
2019-12-04 14:23:08 +00:00
This is particularly useful for [CI ](https://en.wikipedia.org/wiki/Continuous_integration )/[CD](https://en.wikipedia.org/wiki/Continuous_deployment) pipelines using Docker containers.
2018-11-25 17:48:57 +00:00
2019-12-04 14:23:08 +00:00
- `ACTION` ("deploy", "rm", "ls"..., required): Whether to deploy, remove, list... 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
2019-08-28 09:37:35 +00:00
- `DOCKER_COMPOSE_FILE` (string, required if action=deploy): Path to docker-compose file
2018-11-25 17:48:57 +00:00
2019-12-04 14:23:08 +00:00
For detailed instructions, see the full [envvars list ](docs/README.md#available-environment-variables ).
#### Examples
```bash
export ACTION="deploy"
export PORTAINER_USER="admin"
export PORTAINER_PASSWORD="password"
export PORTAINER_URL="https://portainer.local"
export PORTAINER_STACK_NAME="mystack"
export DOCKER_COMPOSE_FILE="/path/to/docker-compose.yml"
export ENVIRONMENT_VARIABLES_FILE="/path/to/env_vars_file"
2021-09-14 08:54:22 +00:00
psu
2018-11-25 17:48:57 +00:00
```
2019-12-04 14:23:08 +00:00
```bash
export ACTION="rm"
export PORTAINER_USER="admin"
export PORTAINER_PASSWORD="password"
export PORTAINER_URL="https://portainer.local"
export PORTAINER_STACK_NAME="mystack"
2018-11-25 17:48:57 +00:00
2021-09-14 08:54:22 +00:00
psu
2019-12-04 14:23:08 +00:00
```
2018-11-24 20:09:14 +00:00
2019-12-04 14:23:08 +00:00
**With Docker:**
```bash
2021-02-18 14:31:42 +00:00
docker run -v $(pwd)/docker-compose.yml:/docker-compose.yml -v $(pwd)/.env:/.env -e ACTION="deploy" -e PORTAINER_USER="admin" -e PORTAINER_PASSWORD="password" -e PORTAINER_URL="https://portainer.local" -e PORTAINER_STACK_NAME="mystack" -e DOCKER_COMPOSE_FILE="docker-compose.yml" -e ENVIRONMENT_VARIABLES_FILE=".env" psuapp/psu:1.2
2019-12-04 14:23:08 +00:00
```
2018-11-25 17:43:12 +00:00
2019-12-04 14:23:08 +00:00
## Documentation
2018-11-25 02:03:23 +00:00
2019-12-04 14:23:08 +00:00
< div class = "docsify-hidden" >
2021-09-14 09:24:46 +00:00
For advanced usage, see the full < a href = "https://psuapp.gitlab.io/psu/1-2-stable" > < abbr title = "Portainer Stack Utils" > PSU< / abbr > documentation< / a > .
2019-12-04 14:23:08 +00:00
< / div >
2018-11-24 20:09:14 +00:00
2019-12-04 14:23:08 +00:00
For detailed instructions, see the [CLI Commands ](docs/README.md ) documentation.
2018-11-25 17:41:02 +00:00
2019-12-04 14:23:08 +00:00
## Supported Portainer API
2018-11-25 17:41:02 +00:00
2021-12-07 17:16:38 +00:00
< abbr title = "Portainer Stack Utils" > PSU</ abbr > was created for the latest versions of Portainer API, which at the time of writing are [1.24.2 ](https://app.swaggerhub.com/apis/deviantony/Portainer/1.24.1 ), [2.5.1 ](https://app.swaggerhub.com/apis/portainer/portainer-ce/2.5.1 ), [2.6.3 ](https://app.swaggerhub.com/apis/portainer/portainer-ce/2.6.3 ) and [2.9.3 ](https://app.swaggerhub.com/apis/portainer/portainer-ce/2.9.3 ).
2018-11-25 17:41:02 +00:00
2018-11-21 20:33:32 +00:00
## License
2019-08-11 07:45:12 +00:00
Source code contained by this project is licensed under the [GNU General Public License version 3 ](https://www.gnu.org/licenses/gpl-3.0.en.html ).
See [LICENSE ](LICENSE ) file for reference.
2021-09-23 15:22:15 +00:00
[Linux]: https://kernel.org
[Alpine]: https://alpinelinux.org
[Debian]: https://debian.org
[Ubuntu]: https://ubuntu.com/
[macOS]: https://apple.com/macos
[Homebrew]: https://brew.sh
[coreutils]: https://formulae.brew.sh/formula/coreutils
[Windows]: https://microsoft.com/windows
[bash]: https://www.gnu.org/software/bash
[curl]: https://curl.se
[jq]: https://stedolan.github.io/jq
[timeout]: https://man7.org/linux/man-pages/man1/timeout.1.html
[uuidgen]: https://man7.org/linux/man-pages/man1/uuidgen.1.html
[docker-compose]: https://docs.docker.com/compose/install
[git]: https://git-scm.com/