From 904cd6359c09fa2c2d364192b44648e04bbfdd88 Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Wed, 6 May 2020 20:25:51 +0000 Subject: [PATCH 01/13] feat: add docker-compose setup --- stackstorm-compose/README.md | 305 ++++++++++++++++++++++++++ stackstorm-compose/docker-compose.yml | 194 ++++++++++++++++ stackstorm-compose/htpasswd | 2 + stackstorm-compose/st2-cli.conf | 3 + stackstorm-compose/st2.docker.conf | 23 ++ stackstorm-compose/st2.user.conf | 6 + 6 files changed, 533 insertions(+) create mode 100644 stackstorm-compose/README.md create mode 100644 stackstorm-compose/docker-compose.yml create mode 100644 stackstorm-compose/htpasswd create mode 100644 stackstorm-compose/st2-cli.conf create mode 100644 stackstorm-compose/st2.docker.conf create mode 100644 stackstorm-compose/st2.user.conf diff --git a/stackstorm-compose/README.md b/stackstorm-compose/README.md new file mode 100644 index 00000000..8f758d3f --- /dev/null +++ b/stackstorm-compose/README.md @@ -0,0 +1,305 @@ +# StackStorm in Docker Compose + +This docker-compose is provided as a way to allow someone to "get up and running" quickly with StackStorm using Docker. It is not designed to be used in production, but rather a way to test out StackStorm and facilitate pack development. + +## TL;DR + +```shell +git clone git@github.com:stackstorm/st2-dockerfiles +cd st2-docker/stackstorm-compose +docker-compose up -d +docker-compose run st2api st2ctl reload --register-all # you should only have to do this the first time +docker-compose run st2client bash # this gives you access to the st2 command line +``` + +Open `http://localhost:8000` in your browser. StackStorm Username/Password by default is: st2admin/Ch@ngeMe. + +## Usage + +### Prerequisites + +- Docker Engine 18.09+ +- Docker Compose 1.12+ + +### Compose Configuration + +The image version, exposed ports, and "packs.dev" directory is configurable with environment variables. + +- **ST2_VERSION** this is the tag at the end of the docker image (ie: stackstorm/st2api:v3.3dev) +- **ST2_IMAGE_REPO** The image or path to the images. Default is "stackstorm/". You may change this is using the Enterprise version or a private docker repository. +- **ST2_EXPOSE_HTTP** Port to expose st2web port 80 on. Default is `8000`, and you amy want to do `0.0.0.0:8000` to expose on all interfaces. +- **ST2_PACKS_DEV** Directory to development packs, absolute or relative to docker-compose.yml. This allows you to develop packs locally. Default is `./packs.dev`. When making a number of packs, it is recommended to make a directory outside of st2-dockerfiles, with each subdirectory underneath that being an independent git repo. Example: `ST2_PACKS_DEV=${HOME}/mypacks`, with `${HOME}/mypacks/st2-helloworld` being a git repo for the "helloworld" pack. + +### Credentials + +The `htpasswd` file is created with a default username of `st2admin` and a default password of `Ch@ngeMe`. This can be changed using the [htpasswd utility](https://httpd.apache.org/docs/2.4/programs/htpasswd.html). + +Another file (`st2-cli.conf`) contains default credentials and is mounted into the "st2client" container. If you change credentials in htpasswd, you will probably want to change them in st2-cli.conf. + +### Further configuration + +The base st2 docker images have a built-in `/etc/st2/st2.conf` configuration file. Each st2 Docker image will load: + +- /etc/st2/st2.conf +- /etc/st2/st2.docker.conf (values here will override st2.conf) +- /etc/st2/st2.user.conf (values here will override st2.docker.conf) + +Review `../base/files/st2.tmp.conf` and `st2.docker.conf` for currently set values, and it is recommended to place overrides in `st2.user.conf`. + +### Step by step first time instructions + +First, optionally set and export all the environment variables you want to change. You could make a .env file with customizations. + +Example: + +```shell +export ST2_PACKS_DEV=$HOME/projects/stackstorm-packs +export ST2_EXPOSE_HTTP=0.0.0.0:8000 +``` + +Secondly make any customizations to st2.user.conf, htpasswd, and st2-cli.conf. + +Example: + +To enable [sharing code between actions and sensors](https://docs.stackstorm.com/reference/sharing_code_sensors_actions.html), add these two lines to st2.user.conf: + +```ini +[packs] +enable_common_libs = True +``` + +Third, start the docker environment: + +```shell +docker-compose up -d +``` + +This will pull the required images from docker hub, and then start them. + +To stop the docker environment, run: + +```shell +docker-compose down +``` + +Fourth, if this is your first time running StackStorm in Docker Compose, you will need to force st2api to register everything. + +```shell +docker-compose run st2api st2ctl reload --register-all +``` + +## Regular Usage + +To run st2 commands, you can use the st2client service: + +```shell +docker-compose run st2client st2 +``` + +Example: + +```shell +$ docker-compose run st2client st2 run core.echo message=hello +. +id: 5eb30d77afe5aa8493f31187 +action.ref: core.echo +context.user: st2admin +parameters: + message: hello +status: succeeded +start_timestamp: Wed, 06 May 2020 19:18:15 UTC +end_timestamp: Wed, 06 May 2020 19:18:15 UTC +result: + failed: false + return_code: 0 + stderr: '' + stdout: hello + succeeded: true +``` + +Alternatively, you could run `docker-compose run st2client bash` to be dropped into a container with st2. At that point, you can just run `st2` commands. + +Example: + +```shell +$ docker-compose run st2client bash +Welcome to StackStorm HA v3.3dev (Ubuntu 16.04 LTS GNU/Linux x86_64) + * Documentation: https://docs.stackstorm.com/ + * Community: https://stackstorm.com/community-signup + * Forum: https://forum.stackstorm.com/ + * Enterprise: https://stackstorm.com/#product + + Warning! Do not edit configs, packs or any content inplace as they will be overridden. Modify Helm values.yaml instead! + It's recommended to use st2client container to work with StackStorm cluster. + +root@aaabd11745f0:/opt/stackstorm# st2 run core.echo message="from the inside" +. +id: 5eb310f571af8f57a4582430 +action.ref: core.echo +context.user: st2admin +parameters: + message: from the inside +status: succeeded +start_timestamp: Wed, 06 May 2020 19:33:09 UTC +end_timestamp: Wed, 06 May 2020 19:33:09 UTC +result: + failed: false + return_code: 0 + stderr: '' + stdout: from the inside + succeeded: true +``` + +## Pack Configuration + +Pack configs will be in /opt/stackstorm/configs/$PACKNAME, which is a docker volume shared between st2api, st2actionrunner, and st2sensorcontainer. You can use the `st2 pack config ` in the st2client container in order to configure a pack. + +### Use st2 pack config + +```shell +$ docker-compose run st2client st2 pack config git +repositories[0].url: https://github.com/StackStorm/st2-dockerfiles.git +repositories[0].branch [master]: +~~~ Would you like to add another item to "repositories" array / list? [y]: n +--- +Do you want to preview the config in an editor before saving? [y]: n +--- +Do you want me to save it? [y]: y ++----------+--------------------------------------------------------------+ +| Property | Value | ++----------+--------------------------------------------------------------+ +| id | 5eb3164f566aa824ea88f536 | +| pack | git | +| values | { | +| | "repositories": [ | +| | { | +| | "url": | +| | "https://github.com/StackStorm/st2-dockerfiles.git", | +| | "branch": "master" | +| | } | +| | ] | +| | } | ++----------+--------------------------------------------------------------+ +``` + +### Copy a config file into a container + +First, find the actual container name of st2api by running `docker-compose ps st2api`. + +```shell +$ docker-compose ps st2api + Name Command State Ports +-------------------------------------------------------------------- +compose_st2api_1 /opt/stackstorm/st2/bin/st ... Up 9101/tcp +``` + +Next, use `docker cp` to copy your file into place. + +```shell +docker cp git.yaml compose_st2api_1:/opt/stackstorm/configs/git.yaml +``` + +## Register the configs + +If you copied the file in or, you will need to register it. st2client does not need access to the configs directory, as it will talk to st2api. + +```shell +$ docker-compose run st2client st2 run packs.load packs=git register=configs +. +id: 5eb3171c566aa824ea88f538 +action.ref: packs.load +context.user: st2admin +parameters: + packs: + - git + register: configs +status: succeeded +start_timestamp: Wed, 06 May 2020 19:59:24 UTC +end_timestamp: Wed, 06 May 2020 19:59:25 UTC +result: + exit_code: 0 + result: + configs: 1 + stdout: '' +``` + +## Local Pack Development + +See [Create and Contribute a Pack](https://docs.stackstorm.com/reference/packs.html) for how to actually develop a pack. + +If you are working on a development pack, you will need to register it and install the virutalenv (if it's python). + +### packs.dev directory + +As mentioned above, your default `packs.dev` directory is relative to your `docker-compose.yml` file. However, if you start developing here, git will not like being inside another git directory. You will want to set `ST2_PACKS_DEV` to a directory outside of `st2-dockerfiles` and restart the docker-compose services. + +Example: We have a pack called helloworld in `packs.dev/helloworld`. The directory name has to match the pack name. So even if you have a git repo named "st2-helloworld", it should be cloned locally as "helloworld". + +For these examples, we will be operating inside the st2client container. + +### Register the pack + +Register the pack by running `st2 run packs.load packs=, register=all`. Alternatively you can specify different register option (like register=actions) to focus on the parts you need to (re)register. You will be running this command a lot as you develop actions, sensors, rules and workflows. + +```shell +root@aaabd11745f0:/opt/stackstorm# st2 run packs.load packs=helloworld register=all +. +id: 5eb3100f71af8f57a458241f +action.ref: packs.load +context.user: st2admin +parameters: + packs: + - helloworld + register: all +status: succeeded +start_timestamp: Wed, 06 May 2020 19:29:19 UTC +end_timestamp: Wed, 06 May 2020 19:29:21 UTC +result: + exit_code: 0 + result: + actions: 13 + aliases: 0 + configs: 0 + policies: 0 + policy_types: 3 + rule_types: 2 + rules: 0 + runners: 15 + sensors: 0 + triggers: 0 +``` + +### Create the Python Virtual Environment + +If you are using python-runners in your locally developed pack, you will need to create the virtual environment by hand. You should typically only have to run this if you have changed your requirements.txt. + +To setup the virtual environment: `st2 run packs.setup_virtualenv packs=,` + +```shell +root@aaabd11745f0:/opt/stackstorm# st2 run packs.setup_virtualenv packs=helloworld +.... +id: 5eb311f871af8f57a4582433 +action.ref: packs.setup_virtualenv +context.user: st2admin +parameters: + packs: + - helloworld +status: succeeded +start_timestamp: Wed, 06 May 2020 19:37:28 UTC +end_timestamp: Wed, 06 May 2020 19:37:36 UTC +result: + exit_code: 0 + result: 'Successfully set up virtualenv for the following packs: helloworld' + stderr: 'st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Setting up virtualenv for pack "helloworld" (/opt/stackstorm/packs.dev/helloworld) + st2.actions.python.SetupVirtualEnvironmentAction: INFO Virtualenv path "/opt/stackstorm/virtualenvs/helloworld" doesn''t exist + st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Creating virtualenv for pack "helloworld" in "/opt/stackstorm/virtualenvs/helloworld" + st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Creating virtualenv in "/opt/stackstorm/virtualenvs/helloworld" using Python binary "/opt/stackstorm/st2/bin/python" + st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Running command "/opt/stackstorm/st2/bin/virtualenv -p /opt/stackstorm/st2/bin/python --always-copy --no-download /opt/stackstorm/virtualenvs/helloworld" to create virtualenv. + st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Installing base requirements + st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Installing requirement six>=1.9.0,<2.0 with command /opt/stackstorm/virtualenvs/helloworld/bin/pip install six>=1.9.0,<2.0. + st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Installing pack specific requirements from "/opt/stackstorm/packs.dev/helloworld/requirements.txt" + st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Installing requirements from file /opt/stackstorm/packs.dev/helloworld/requirements.txt with command /opt/stackstorm/virtualenvs/helloworld/bin/pip install -U -r /opt/stackstorm/packs.dev/helloworld/requirements.txt. + st2.actions.python.SetupVirtualEnvironmentAction: DEBUG Virtualenv for pack "helloworld" successfully created in "/opt/stackstorm/virtualenvs/helloworld" + ' + stdout: '' +``` diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml new file mode 100644 index 00000000..688ec9e5 --- /dev/null +++ b/stackstorm-compose/docker-compose.yml @@ -0,0 +1,194 @@ +version: '3' + +services: + st2web: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2web:${ST2_VERSION:-3.3dev} + environment: + ST2_AUTH_URL: ${ST2_AUTH_URL:-http://st2auth:9100/} + ST2_API_URL: ${ST2_API_URL:-http://st2api:9101/} + ST2_STREAM_URL: ${ST2_STREAM_URL:-http://st2stream:9102/} + ST2WEB_HTTPS: ${ST2WEB_HTTPS:-0} + depends_on: + - st2auth + - st2api + - st2stream + ports: + - "${ST2_EXPOSE_HTTP:-8000}:80" + # - "${ST2_EXPOSE_HTTPS:-8443}:443" + # more work would be needed with certificate generate to make https work. + networks: + - private + - public + dns_search: . + st2api: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2api:${ST2_VERSION:-3.3dev} + depends_on: ["mongo", "rabbitmq"] + networks: + - private + environment: + ST2_AUTH_URL: ${ST2_AUTH_URL:-http://st2auth:9100/} + ST2_API_URL: ${ST2_API_URL:-http://st2api:9101/} + ST2_STREAM_URL: ${ST2_STREAM_URL:-http://st2stream:9102/} + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + - stackstorm-packs-configs:/opt/stackstorm/configs:rw + - stackstorm-packs:/opt/stackstorm/packs:rw + - ${ST2_PACKS_DEV:-./packs.dev}:/opt/stackstorm/packs.dev:rw + dns_search: . + st2stream: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2stream:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + dns_search: . + st2scheduler: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2scheduler:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + dns_search: . + st2workflowengine: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2workflowengine:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + dns_search: . + st2auth: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2auth:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + - ./htpasswd:/etc/st2/htpasswd:ro + dns_search: . + st2actionrunner: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2actionrunner:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + - stackstorm-packs-configs:/opt/stackstorm/configs:rw + - stackstorm-packs:/opt/stackstorm/packs:rw + - ${ST2_PACKS_DEV:-./packs.dev}:/opt/stackstorm/packs.dev:rw + - stackstorm-virtualenvs:/opt/stackstorm/virtualenvs:rw + - stackstorm-ssh:/home/stanley.ssh + dns_search: . + st2garbagecollector: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2garbagecollector:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + dns_search: . + st2notifier: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2garbagecollector:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + dns_search: . + st2resultstracker: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2resultstracker:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + dns_search: . + st2rulesengine: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2rulesengine:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + dns_search: . + st2sensorcontainer: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2sensorcontainer:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + dns_search: . + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + - ./st2.user.conf:/etc/st2/st2.user.conf:ro + - stackstorm-virtualenvs:/opt/stackstorm/virtualenvs:ro + - stackstorm-packs:/opt/stackstorm/packs:ro + - stackstorm-packs-configs:/opt/stackstorm/configs:ro + - ${ST2_PACKS_DEV:-./packs.dev}:/opt/stackstorm/packs.dev:ro + st2timersengine: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2timersengine:${ST2_VERSION:-3.3dev} + depends_on: ["st2api"] + networks: + - private + dns_search: . + volumes: + - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro + st2client: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2:${ST2_VERSION:-3.3dev} + networks: + - private + environment: + ST2_AUTH_URL: ${ST2_AUTH_URL:-http://st2auth:9100/} + ST2_API_URL: ${ST2_API_URL:-http://st2api:9101/} + ST2_STREAM_URL: ${ST2_STREAM_URL:-http://st2stream:9102/} + volumes: + - ./st2-cli.conf:/root/.st2/config + # external services + mongo: + image: mongo:3.4 + networks: + - private + volumes: + - stackstorm-mongodb:/data/db + dns_search: . + rabbitmq: + image: rabbitmq:3.8 + networks: + - private + dns_search: . + volumes: + - stackstorm-rabbitmq:/var/lib/rabbitmq + redis: + image: redis:6.0 + networks: + - private + dns_search: . + volumes: + - stackstorm-redis:/data + +volumes: + stackstorm-mongodb: + stackstorm-rabbitmq: + stackstorm-redis: + stackstorm-postgres: + stackstorm-packs: + stackstorm-packs-configs: + stackstorm-virtualenvs: + stackstorm-ssh: + +networks: + public: + driver: bridge + private: + driver: bridge diff --git a/stackstorm-compose/htpasswd b/stackstorm-compose/htpasswd new file mode 100644 index 00000000..a9771452 --- /dev/null +++ b/stackstorm-compose/htpasswd @@ -0,0 +1,2 @@ +# st2admin:Ch@ngeMe +st2admin:$apr1$GjA7KmRf$nmbcSB1XoYRPfQrL9ZBD5. diff --git a/stackstorm-compose/st2-cli.conf b/stackstorm-compose/st2-cli.conf new file mode 100644 index 00000000..94a9bba3 --- /dev/null +++ b/stackstorm-compose/st2-cli.conf @@ -0,0 +1,3 @@ +[credentials] +username = st2admin +password = Ch@ngeMe diff --git a/stackstorm-compose/st2.docker.conf b/stackstorm-compose/st2.docker.conf new file mode 100644 index 00000000..25378f32 --- /dev/null +++ b/stackstorm-compose/st2.docker.conf @@ -0,0 +1,23 @@ +# /etc/st2/st2.docker.conf +# +# This is override st2 config file which will be passed to any st2 command, like this: +# `--config-file /etc/st2/st2.conf --config-file /etc/st2/st2.docker.conf --config-file /etc/st2/st2.user.conf` +# making possible to keep custom st2 config directives in it, instead of modifying the original st2.conf every time. +# The order of merging: st2.conf < st2.docker.conf < st2.user.conf +[auth] +api_url = http://st2api:9101/ +[messaging] +url = amqp://guest:guest@rabbitmq:5672 +[database] +host = mongo +# st2.conf for kubernetes disables retry (relying on kubernetes), but +# for straight docker, we want to re-enable these. +# Connection retry total time (minutes). +connection_retry_max_delay_m = 1 +# Backoff multiplier (seconds). +connection_retry_backoff_mul = 1 +# Connection and server selection timeout (in ms). +connection_timeout = 3000 + +[content] +packs_base_paths=/opt/stackstorm/packs.dev diff --git a/stackstorm-compose/st2.user.conf b/stackstorm-compose/st2.user.conf new file mode 100644 index 00000000..268e0c95 --- /dev/null +++ b/stackstorm-compose/st2.user.conf @@ -0,0 +1,6 @@ +# /etc/st2/st2.user.conf +# +# This is override st2 config file which will be passed to any st2 command, like this: +# `--config-file /etc/st2/st2.conf --config-file /etc/st2/st2.docker.conf --config-file /etc/st2/st2.user.conf` +# making possible to keep custom st2 config directives in it, instead of modifying the original st2.conf every time. +# The order of merging: st2.conf < st2.docker.conf < st2.user.conf From e439c055a110ea38bda3337d83cfbb168236d2bd Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Sun, 10 May 2020 00:58:00 +0000 Subject: [PATCH 02/13] localhost:8000 and document updates --- stackstorm-compose/README.md | 4 ++-- stackstorm-compose/docker-compose.yml | 4 ++-- stackstorm-compose/st2.docker.conf | 7 ++++--- stackstorm-compose/st2.user.conf | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/stackstorm-compose/README.md b/stackstorm-compose/README.md index 8f758d3f..590d1d86 100644 --- a/stackstorm-compose/README.md +++ b/stackstorm-compose/README.md @@ -27,7 +27,7 @@ The image version, exposed ports, and "packs.dev" directory is configurable with - **ST2_VERSION** this is the tag at the end of the docker image (ie: stackstorm/st2api:v3.3dev) - **ST2_IMAGE_REPO** The image or path to the images. Default is "stackstorm/". You may change this is using the Enterprise version or a private docker repository. -- **ST2_EXPOSE_HTTP** Port to expose st2web port 80 on. Default is `8000`, and you amy want to do `0.0.0.0:8000` to expose on all interfaces. +- **ST2_EXPOSE_HTTP** Port to expose st2web port 80 on. Default is `127.0.0.1:8000`, and you may want to do `0.0.0.0:8000` to expose on all interfaces. - **ST2_PACKS_DEV** Directory to development packs, absolute or relative to docker-compose.yml. This allows you to develop packs locally. Default is `./packs.dev`. When making a number of packs, it is recommended to make a directory outside of st2-dockerfiles, with each subdirectory underneath that being an independent git repo. Example: `ST2_PACKS_DEV=${HOME}/mypacks`, with `${HOME}/mypacks/st2-helloworld` being a git repo for the "helloworld" pack. ### Credentials @@ -199,7 +199,7 @@ Next, use `docker cp` to copy your file into place. docker cp git.yaml compose_st2api_1:/opt/stackstorm/configs/git.yaml ``` -## Register the configs +## Register the pack config If you copied the file in or, you will need to register it. st2client does not need access to the configs directory, as it will talk to st2api. diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml index 688ec9e5..cdb3ef05 100644 --- a/stackstorm-compose/docker-compose.yml +++ b/stackstorm-compose/docker-compose.yml @@ -13,8 +13,8 @@ services: - st2api - st2stream ports: - - "${ST2_EXPOSE_HTTP:-8000}:80" - # - "${ST2_EXPOSE_HTTPS:-8443}:443" + - "${ST2_EXPOSE_HTTP:-127.0.0.1:8000}:80" + # - "${ST2_EXPOSE_HTTPS:-127.0.0.1:8443}:443" # more work would be needed with certificate generate to make https work. networks: - private diff --git a/stackstorm-compose/st2.docker.conf b/stackstorm-compose/st2.docker.conf index 25378f32..7bd21893 100644 --- a/stackstorm-compose/st2.docker.conf +++ b/stackstorm-compose/st2.docker.conf @@ -1,8 +1,9 @@ # /etc/st2/st2.docker.conf # -# This is override st2 config file which will be passed to any st2 command, like this: -# `--config-file /etc/st2/st2.conf --config-file /etc/st2/st2.docker.conf --config-file /etc/st2/st2.user.conf` -# making possible to keep custom st2 config directives in it, instead of modifying the original st2.conf every time. +# This st2.docker.conf overrides st2.conf in the base image, and has been written to facilitate operation of +# stackstorm-compose/docker-compose.yml. It is recommended to not alter this file as an end-user, as this file +# is updated as necessary by the StackStorm st2-dockerfile maintainers. Instead, make local changes in the +# file "st2.user.conf". # The order of merging: st2.conf < st2.docker.conf < st2.user.conf [auth] api_url = http://st2api:9101/ diff --git a/stackstorm-compose/st2.user.conf b/stackstorm-compose/st2.user.conf index 268e0c95..9db6d427 100644 --- a/stackstorm-compose/st2.user.conf +++ b/stackstorm-compose/st2.user.conf @@ -1,6 +1,6 @@ # /etc/st2/st2.user.conf # -# This is override st2 config file which will be passed to any st2 command, like this: -# `--config-file /etc/st2/st2.conf --config-file /etc/st2/st2.docker.conf --config-file /etc/st2/st2.user.conf` -# making possible to keep custom st2 config directives in it, instead of modifying the original st2.conf every time. +# This file is provided with no custom overrides and should be utilized by end-users to make any +# desired configuration changes. No changes to this file should be checked into the st2-dockerfiles +# repository. # The order of merging: st2.conf < st2.docker.conf < st2.user.conf From f8a2c0ec19b95417bfee14855f470f1866f1dce3 Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Mon, 11 May 2020 18:53:29 +0000 Subject: [PATCH 03/13] add health check to st2web --- stackstorm-compose/docker-compose.yml | 8 ++++++++ stackstorm-compose/st2web-healthcheck.sh | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100755 stackstorm-compose/st2web-healthcheck.sh diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml index cdb3ef05..870ad736 100644 --- a/stackstorm-compose/docker-compose.yml +++ b/stackstorm-compose/docker-compose.yml @@ -3,6 +3,7 @@ version: '3' services: st2web: image: ${ST2_IMAGE_REPO:-stackstorm/}st2web:${ST2_VERSION:-3.3dev} + restart: always environment: ST2_AUTH_URL: ${ST2_AUTH_URL:-http://st2auth:9100/} ST2_API_URL: ${ST2_API_URL:-http://st2api:9101/} @@ -12,6 +13,13 @@ services: - st2auth - st2api - st2stream + healthcheck: + test: ["CMD", "/st2web-healthcheck.sh"] + interval: 30s + timeout: 1s + retries: 1 + volumes: + - ./st2web-healthcheck.sh:/st2web-healthcheck.sh ports: - "${ST2_EXPOSE_HTTP:-127.0.0.1:8000}:80" # - "${ST2_EXPOSE_HTTPS:-127.0.0.1:8443}:443" diff --git a/stackstorm-compose/st2web-healthcheck.sh b/stackstorm-compose/st2web-healthcheck.sh new file mode 100755 index 00000000..c8335c55 --- /dev/null +++ b/stackstorm-compose/st2web-healthcheck.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# Check each service through the nginx reverse proxy for a specific return code. If the curl request +# fails to work through nginx, a stop signal will be sent to nginx, causing the container to restart. +API_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null http://localhost/api/v1/) +if [ "${API_STATUS}" != "401" ]; then echo "st2api failure"; nginx -s stop; fi + +STREAM_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null http://localhost/stream/v1/stream) +if [ "${STREAM_STATUS}" != "401" ]; then echo "st2stream failure"; nginx -s stop; fi + +AUTH_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null http://localhost/auth/v1/) +if [ "${AUTH_STATUS}" != "404" ]; then echo "st2auth failure"; nginx -s stop; fi + +exit 0 \ No newline at end of file From 48ebcbed8252ea02e9f3b12ebd6e7f1b19856612 Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Thu, 14 May 2020 12:08:18 +0000 Subject: [PATCH 04/13] fix(stackstorm-compose): st2notifier image --- stackstorm-compose/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml index 870ad736..35d6f2bc 100644 --- a/stackstorm-compose/docker-compose.yml +++ b/stackstorm-compose/docker-compose.yml @@ -105,7 +105,7 @@ services: - ./st2.user.conf:/etc/st2/st2.user.conf:ro dns_search: . st2notifier: - image: ${ST2_IMAGE_REPO:-stackstorm/}st2garbagecollector:${ST2_VERSION:-3.3dev} + image: ${ST2_IMAGE_REPO:-stackstorm/}st2notifier:${ST2_VERSION:-3.3dev} depends_on: ["st2api"] networks: - private From 50840ac155945501ddf74aa96a44ca262aa4bf67 Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Sun, 17 May 2020 12:04:49 +0000 Subject: [PATCH 05/13] set docker-compose to restart: on-failure --- stackstorm-compose/docker-compose.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml index 35d6f2bc..4516be79 100644 --- a/stackstorm-compose/docker-compose.yml +++ b/stackstorm-compose/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: st2web: image: ${ST2_IMAGE_REPO:-stackstorm/}st2web:${ST2_VERSION:-3.3dev} - restart: always + restart: on-failure environment: ST2_AUTH_URL: ${ST2_AUTH_URL:-http://st2auth:9100/} ST2_API_URL: ${ST2_API_URL:-http://st2api:9101/} @@ -30,6 +30,7 @@ services: dns_search: . st2api: image: ${ST2_IMAGE_REPO:-stackstorm/}st2api:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["mongo", "rabbitmq"] networks: - private @@ -46,6 +47,7 @@ services: dns_search: . st2stream: image: ${ST2_IMAGE_REPO:-stackstorm/}st2stream:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -55,6 +57,7 @@ services: dns_search: . st2scheduler: image: ${ST2_IMAGE_REPO:-stackstorm/}st2scheduler:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -64,6 +67,7 @@ services: dns_search: . st2workflowengine: image: ${ST2_IMAGE_REPO:-stackstorm/}st2workflowengine:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -73,6 +77,7 @@ services: dns_search: . st2auth: image: ${ST2_IMAGE_REPO:-stackstorm/}st2auth:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -83,6 +88,7 @@ services: dns_search: . st2actionrunner: image: ${ST2_IMAGE_REPO:-stackstorm/}st2actionrunner:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -97,6 +103,7 @@ services: dns_search: . st2garbagecollector: image: ${ST2_IMAGE_REPO:-stackstorm/}st2garbagecollector:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -106,6 +113,7 @@ services: dns_search: . st2notifier: image: ${ST2_IMAGE_REPO:-stackstorm/}st2notifier:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -115,6 +123,7 @@ services: dns_search: . st2resultstracker: image: ${ST2_IMAGE_REPO:-stackstorm/}st2resultstracker:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -124,6 +133,7 @@ services: dns_search: . st2rulesengine: image: ${ST2_IMAGE_REPO:-stackstorm/}st2rulesengine:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -133,6 +143,7 @@ services: dns_search: . st2sensorcontainer: image: ${ST2_IMAGE_REPO:-stackstorm/}st2sensorcontainer:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -146,6 +157,7 @@ services: - ${ST2_PACKS_DEV:-./packs.dev}:/opt/stackstorm/packs.dev:ro st2timersengine: image: ${ST2_IMAGE_REPO:-stackstorm/}st2timersengine:${ST2_VERSION:-3.3dev} + restart: on-failure depends_on: ["st2api"] networks: - private @@ -154,6 +166,7 @@ services: - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro st2client: image: ${ST2_IMAGE_REPO:-stackstorm/}st2:${ST2_VERSION:-3.3dev} + restart: on-failure networks: - private environment: @@ -165,6 +178,7 @@ services: # external services mongo: image: mongo:3.4 + restart: on-failure networks: - private volumes: @@ -172,6 +186,7 @@ services: dns_search: . rabbitmq: image: rabbitmq:3.8 + restart: on-failure networks: - private dns_search: . @@ -179,6 +194,7 @@ services: - stackstorm-rabbitmq:/var/lib/rabbitmq redis: image: redis:6.0 + restart: on-failure networks: - private dns_search: . From 50e91b50c0abb5ead72fe9dd485b06f8b7529fa4 Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Sun, 17 May 2020 12:07:28 +0000 Subject: [PATCH 06/13] change run to exec for running st2ctl --- stackstorm-compose/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stackstorm-compose/README.md b/stackstorm-compose/README.md index 9697200b..89d72384 100644 --- a/stackstorm-compose/README.md +++ b/stackstorm-compose/README.md @@ -8,7 +8,7 @@ This docker-compose is provided as a way to allow someone to "get up and running git clone git@github.com:stackstorm/st2-dockerfiles cd st2-docker/stackstorm-compose docker-compose up -d -docker-compose run st2api st2ctl reload --register-all # you should only have to do this the first time +docker-compose exec st2api st2ctl reload --register-all # you should only have to do this the first time docker-compose run st2client bash # this gives you access to the st2 command line ``` @@ -85,7 +85,7 @@ docker-compose down Fourth, if this is your first time running StackStorm in Docker Compose, you will need to force st2api to register everything. ```shell -docker-compose run st2api st2ctl reload --register-all +docker-compose exec st2api st2ctl reload --register-all ``` ## Regular Usage From f86fec16c5d1a8daaf9431ed3e578f22276b58dc Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Sun, 17 May 2020 12:12:57 +0000 Subject: [PATCH 07/13] set compose st2client to use st2actionrunner image --- stackstorm-compose/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml index 4516be79..716c784e 100644 --- a/stackstorm-compose/docker-compose.yml +++ b/stackstorm-compose/docker-compose.yml @@ -165,7 +165,7 @@ services: volumes: - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro st2client: - image: ${ST2_IMAGE_REPO:-stackstorm/}st2:${ST2_VERSION:-3.3dev} + image: ${ST2_IMAGE_REPO:-stackstorm/}st2actionrunner:${ST2_VERSION:-3.3dev} restart: on-failure networks: - private From c5ba2f460d456af227a6c9f637fc5bfc098989f1 Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Sun, 17 May 2020 12:37:42 +0000 Subject: [PATCH 08/13] make st2client run always, matching stackstorm-ha --- stackstorm-compose/README.md | 14 +++++++------- stackstorm-compose/docker-compose.yml | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/stackstorm-compose/README.md b/stackstorm-compose/README.md index 89d72384..09d57fa6 100644 --- a/stackstorm-compose/README.md +++ b/stackstorm-compose/README.md @@ -9,7 +9,7 @@ git clone git@github.com:stackstorm/st2-dockerfiles cd st2-docker/stackstorm-compose docker-compose up -d docker-compose exec st2api st2ctl reload --register-all # you should only have to do this the first time -docker-compose run st2client bash # this gives you access to the st2 command line +docker-compose exec st2client bash # this gives you access to the st2 command line ``` Open `http://localhost:8000` in your browser. StackStorm Username/Password by default is: st2admin/Ch@ngeMe. @@ -93,13 +93,13 @@ docker-compose exec st2api st2ctl reload --register-all To run st2 commands, you can use the st2client service: ```shell -docker-compose run st2client st2 +docker-compose exec st2client st2 ``` Example: ```shell -$ docker-compose run st2client st2 run core.echo message=hello +$ docker-compose exec st2client st2 run core.echo message=hello . id: 5eb30d77afe5aa8493f31187 action.ref: core.echo @@ -117,12 +117,12 @@ result: succeeded: true ``` -Alternatively, you could run `docker-compose run st2client bash` to be dropped into a container with st2. At that point, you can just run `st2` commands. +Alternatively, you could run `docker-compose exec st2client bash` to be dropped into a container with st2. At that point, you can just run `st2` commands. Example: ```shell -$ docker-compose run st2client bash +$ docker-compose exec st2client bash Welcome to StackStorm HA v3.3dev (Ubuntu 16.04 LTS GNU/Linux x86_64) * Documentation: https://docs.stackstorm.com/ * Community: https://stackstorm.com/community-signup @@ -157,7 +157,7 @@ Pack configs will be in /opt/stackstorm/configs/$PACKNAME, which is a docker vol ### Use st2 pack config ```shell -$ docker-compose run st2client st2 pack config git +$ docker-compose exec st2client st2 pack config git repositories[0].url: https://github.com/StackStorm/st2-dockerfiles.git repositories[0].branch [master]: ~~~ Would you like to add another item to "repositories" array / list? [y]: n @@ -204,7 +204,7 @@ docker cp git.yaml compose_st2api_1:/opt/stackstorm/configs/git.yaml If you used `docker cp` to copy the config in, you will need to manually load that configuration. The st2client service does not need access to the configs directory, as it will talk to st2api. ```shell -$ docker-compose run st2client st2 run packs.load packs=git register=configs +$ docker-compose exec st2client st2 run packs.load packs=git register=configs . id: 5eb3171c566aa824ea88f538 action.ref: packs.load diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml index 716c784e..605c22b4 100644 --- a/stackstorm-compose/docker-compose.yml +++ b/stackstorm-compose/docker-compose.yml @@ -167,6 +167,7 @@ services: st2client: image: ${ST2_IMAGE_REPO:-stackstorm/}st2actionrunner:${ST2_VERSION:-3.3dev} restart: on-failure + command: sleep infinity networks: - private environment: From d377ba8ac952afdc692f86d6c34705d8dfe1a59b Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Mon, 25 May 2020 12:49:57 +0000 Subject: [PATCH 09/13] Add secret keys on start for encrypted secrets --- stackstorm-compose/docker-compose.yml | 14 +++++++++++++- stackstorm-compose/makesecrets.sh | 11 +++++++++++ stackstorm-compose/st2.docker.conf | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 stackstorm-compose/makesecrets.sh diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml index 605c22b4..7a98fd10 100644 --- a/stackstorm-compose/docker-compose.yml +++ b/stackstorm-compose/docker-compose.yml @@ -28,10 +28,20 @@ services: - private - public dns_search: . + st2makesecrets: + image: ${ST2_IMAGE_REPO:-stackstorm/}st2actionrunner:${ST2_VERSION:-3.3dev} + restart: on-failure + networks: + - private + volumes: + - ./makesecrets.sh:/makesecrets.sh + - stackstorm-keys:/etc/st2/keys:rw + dns_search: . + command: /makesecrets.sh st2api: image: ${ST2_IMAGE_REPO:-stackstorm/}st2api:${ST2_VERSION:-3.3dev} restart: on-failure - depends_on: ["mongo", "rabbitmq"] + depends_on: ["mongo", "rabbitmq", "st2makesecrets"] networks: - private environment: @@ -41,6 +51,7 @@ services: volumes: - ./st2.docker.conf:/etc/st2/st2.docker.conf:ro - ./st2.user.conf:/etc/st2/st2.user.conf:ro + - stackstorm-keys:/etc/st2/keys:rw - stackstorm-packs-configs:/opt/stackstorm/configs:rw - stackstorm-packs:/opt/stackstorm/packs:rw - ${ST2_PACKS_DEV:-./packs.dev}:/opt/stackstorm/packs.dev:rw @@ -209,6 +220,7 @@ volumes: stackstorm-postgres: stackstorm-packs: stackstorm-packs-configs: + stackstorm-keys: stackstorm-virtualenvs: stackstorm-ssh: diff --git a/stackstorm-compose/makesecrets.sh b/stackstorm-compose/makesecrets.sh new file mode 100755 index 00000000..edc9c6ec --- /dev/null +++ b/stackstorm-compose/makesecrets.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# this needs to run as root, so can't be ran in the st2api container +KEYPATH=/etc/st2/keys/datastore_key.json +if [ ! -f "/etc/st2/keys/datastore_key.json" ] +then + echo "Generating ${KEYPATH}" + st2-generate-symmetric-crypto-key --key-path /etc/st2/keys/datastore_key.json + chown -R st2:st2 /etc/st2/keys + chmod -R 750 /etc/st2/keys +fi + diff --git a/stackstorm-compose/st2.docker.conf b/stackstorm-compose/st2.docker.conf index 7bd21893..f5ea3f6d 100644 --- a/stackstorm-compose/st2.docker.conf +++ b/stackstorm-compose/st2.docker.conf @@ -9,6 +9,10 @@ api_url = http://st2api:9101/ [messaging] url = amqp://guest:guest@rabbitmq:5672 + +[keyvalue] +encryption_key_path = /etc/st2/keys/datastore_key.json + [database] host = mongo # st2.conf for kubernetes disables retry (relying on kubernetes), but From 848430f36abfcf99d48455393a0151a14df110ca Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Mon, 25 May 2020 13:10:49 +0000 Subject: [PATCH 10/13] better st2web healthchecks --- stackstorm-compose/st2web-healthcheck.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/stackstorm-compose/st2web-healthcheck.sh b/stackstorm-compose/st2web-healthcheck.sh index c8335c55..227f5629 100755 --- a/stackstorm-compose/st2web-healthcheck.sh +++ b/stackstorm-compose/st2web-healthcheck.sh @@ -1,13 +1,23 @@ #!/usr/bin/env bash +# check downstream services and mark container unhealthy if downstream is not unreachable +DOWNSTREAM_API_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null $ST2_API_URL/v1) +if [ "${DOWNSTREAM_API_STATUS}" != "404" ]; then echo "st2api downstream failure"; exit 1; fi + +DOWNSTREAM_STREAM_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null $ST2_STREAM_URL/v1/stream) +if [ "${DOWNSTREAM_STREAM_STATUS}" != "404" ]; then echo "st2stream downstream failure"; exit 1; fi + +DOWNSTREAM_AUTH_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null $ST2_AUTH_URL/v1) +if [ "${DOWNSTREAM_AUTH_STATUS}" != "404" ]; then echo "st2auth downstream failure"; exit 1; fi + # Check each service through the nginx reverse proxy for a specific return code. If the curl request # fails to work through nginx, a stop signal will be sent to nginx, causing the container to restart. API_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null http://localhost/api/v1/) -if [ "${API_STATUS}" != "401" ]; then echo "st2api failure"; nginx -s stop; fi +if [ "${API_STATUS}" != "401" ]; then echo "st2api nginx failure"; nginx -s stop; fi STREAM_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null http://localhost/stream/v1/stream) -if [ "${STREAM_STATUS}" != "401" ]; then echo "st2stream failure"; nginx -s stop; fi +if [ "${STREAM_STATUS}" != "401" ]; then echo "st2stream nginx failure"; nginx -s stop; fi AUTH_STATUS=$(curl --write-out "%{http_code}\n" --silent --output /dev/null http://localhost/auth/v1/) -if [ "${AUTH_STATUS}" != "404" ]; then echo "st2auth failure"; nginx -s stop; fi +if [ "${AUTH_STATUS}" != "404" ]; then echo "st2auth nginx failure"; nginx -s stop; fi exit 0 \ No newline at end of file From 23d1825587d3781c861c46272bfd7220a8bf50aa Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Mon, 25 May 2020 13:51:05 +0000 Subject: [PATCH 11/13] st2client startup will register actions --- stackstorm-compose/README.md | 15 ++++++++------- stackstorm-compose/docker-compose.yml | 8 +++++++- stackstorm-compose/st2client-startup.sh | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100755 stackstorm-compose/st2client-startup.sh diff --git a/stackstorm-compose/README.md b/stackstorm-compose/README.md index 09d57fa6..2b65caa7 100644 --- a/stackstorm-compose/README.md +++ b/stackstorm-compose/README.md @@ -8,7 +8,6 @@ This docker-compose is provided as a way to allow someone to "get up and running git clone git@github.com:stackstorm/st2-dockerfiles cd st2-docker/stackstorm-compose docker-compose up -d -docker-compose exec st2api st2ctl reload --register-all # you should only have to do this the first time docker-compose exec st2client bash # this gives you access to the st2 command line ``` @@ -82,12 +81,6 @@ To stop the docker environment, run: docker-compose down ``` -Fourth, if this is your first time running StackStorm in Docker Compose, you will need to force st2api to register everything. - -```shell -docker-compose exec st2api st2ctl reload --register-all -``` - ## Regular Usage To run st2 commands, you can use the st2client service: @@ -303,3 +296,11 @@ result: ' stdout: '' ``` + +# Remove everything + +If you want to uninstall, or start from a "clean" installation, docker-compose can remove all the containers and volumes in one comamnd. + +```shell +docker-compose down --remove-orphans -v +``` \ No newline at end of file diff --git a/stackstorm-compose/docker-compose.yml b/stackstorm-compose/docker-compose.yml index 7a98fd10..2b7e07be 100644 --- a/stackstorm-compose/docker-compose.yml +++ b/stackstorm-compose/docker-compose.yml @@ -178,14 +178,20 @@ services: st2client: image: ${ST2_IMAGE_REPO:-stackstorm/}st2actionrunner:${ST2_VERSION:-3.3dev} restart: on-failure - command: sleep infinity + depends_on: + - st2auth + - st2api + - st2stream + command: /st2client-startup.sh networks: - private environment: + ST2CLIENT: 1 ST2_AUTH_URL: ${ST2_AUTH_URL:-http://st2auth:9100/} ST2_API_URL: ${ST2_API_URL:-http://st2api:9101/} ST2_STREAM_URL: ${ST2_STREAM_URL:-http://st2stream:9102/} volumes: + - ./st2client-startup.sh:/st2client-startup.sh - ./st2-cli.conf:/root/.st2/config # external services mongo: diff --git a/stackstorm-compose/st2client-startup.sh b/stackstorm-compose/st2client-startup.sh new file mode 100755 index 00000000..8676922b --- /dev/null +++ b/stackstorm-compose/st2client-startup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +#st2client startup and registration +while true +do +ACTIONS=$(st2 action list) +if [ "$?" -ne 0 ] +then + echo "unable to reach downstream, will try again" + sleep 5 +elif [ "$ACTIONS" == "No matching items found" ] +then + echo "No packs registered, will register" + st2 pack register +else + echo "actions found st2client ready" + sleep infinity +fi +done \ No newline at end of file From a5754bbfebeb90f59b852e4dad157821ea0ccf76 Mon Sep 17 00:00:00 2001 From: John Hogenmiller Date: Tue, 26 May 2020 16:12:58 +0000 Subject: [PATCH 12/13] readme path fix --- stackstorm-compose/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stackstorm-compose/README.md b/stackstorm-compose/README.md index 2b65caa7..43e9cdfe 100644 --- a/stackstorm-compose/README.md +++ b/stackstorm-compose/README.md @@ -6,7 +6,7 @@ This docker-compose is provided as a way to allow someone to "get up and running ```shell git clone git@github.com:stackstorm/st2-dockerfiles -cd st2-docker/stackstorm-compose +cd st2-dockerfiles/stackstorm-compose docker-compose up -d docker-compose exec st2client bash # this gives you access to the st2 command line ``` From aeb72c5cfbbaeac15c2b2ec49672e096d25d469c Mon Sep 17 00:00:00 2001 From: armab Date: Wed, 3 Jun 2020 14:11:33 +0100 Subject: [PATCH 13/13] Adjust .welcome.sh messages to work properly in both K8s and docker-compose environments --- base/files/.welcome.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/base/files/.welcome.sh b/base/files/.welcome.sh index a2390b08..f37312f6 100644 --- a/base/files/.welcome.sh +++ b/base/files/.welcome.sh @@ -8,6 +8,7 @@ printf " * Documentation: https://docs.stackstorm.com/\n" printf " * Community: https://stackstorm.com/community-signup\n" printf " * Forum: https://forum.stackstorm.com/\n" printf " * \033[1;38;5;93mEnterprise: https://stackstorm.com/#product\033[0m\n\n" +# User logged into st2client container if [ -n "$ST2CLIENT" ]; then printf " Here you can use StackStorm CLI. Examples:\n" printf " st2 action list --pack=core\n" @@ -15,9 +16,11 @@ if [ -n "$ST2CLIENT" ]; then printf " st2 run core.local_sudo cmd='apt-get update' --tail\n" printf " st2 execution list\n" printf "\n" +else + printf " \033[1mNotice!\033[0m It's recommended to use \033[1mst2client\033[0m container to work with StackStorm cluster.\n" fi -printf " \033[1mWarning!\033[0m Do not edit configs, packs or any content inplace as they will be overridden. Modify Helm values.yaml instead!\n" -if [ ! -n "$ST2CLIENT" ]; then - printf " It's recommended to use \033[1mst2client\033[0m container to work with StackStorm cluster.\n" +# Is K8s environment +if [ -n "$KUBERNETES_PORT" ]; then + printf " \033[1mWarning!\033[0m Do not edit configs, packs or any content inplace as they will be overridden. Modify Helm values.yaml instead!\n" fi printf "\n"