-
-
Notifications
You must be signed in to change notification settings - Fork 62
st2bootstrap generic template #753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
755a210
Initial commit with generic templating.
nzlosh 47778d0
Use virtualenv for template build and populate templates from scripts.
nzlosh a7c2a9e
Regenerate st2bootstrap scripts from templates
nzlosh bd0a29d
Update chatop templates/vars and re-make
skiedude 9926cbd
Use git to detect uncommitted scripts and remove comment strip.
nzlosh b988614
Add copyright to installation script.
nzlosh 1ccdaeb
Remove unused function pkg_get_versions
nzlosh 0921099
Split nginx and st2web install functions and manage firewall on RHEL …
nzlosh 22aac4c
Use appropriate repostiory metadata refresh command.
nzlosh 7dd7087
Split ChatOps and nodejs installation.
nzlosh 8c8ce84
Move selinux to redhat section of template
nzlosh 051f027
Add key name as comment to repo definition.
nzlosh 1ae8394
Use systemctl to start chatops.
nzlosh 508dde8
convert shell to jinja comments, typo fixes and logic fixes.
nzlosh 32ff7f8
Regenerate scripts from latest template changes
nzlosh 4c9f68a
Improved structure in rabbitmq template and moved nginx selinux to ng…
nzlosh 52145c6
Template regeneration
nzlosh 276f7bb
Allow override repo metadata settings and disable nodejs repo_gpgcheck.
nzlosh f8e1d0f
Regenerate scripts.
nzlosh f7aad4f
Add thank you message to asciiart.eu
nzlosh b8522bd
Regenerate scripts.
nzlosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,45 @@ | ||
| ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
| SHELL := /bin/bash | ||
| VIRTUALENV_DIR ?= virtualenv/st2packages | ||
| .DEFAULT_GOAL := scriptsgen | ||
|
|
||
| .PHONY: .create_venv | ||
| .create_venv: | ||
| test -d "$(VIRTUALENV_DIR)" || python3 -m venv "$(VIRTUALENV_DIR)" | ||
|
|
||
| .PHONY: .install_dependencies | ||
| .install_dependencies: | ||
| "$(VIRTUALENV_DIR)/bin/pip3" install -r requirements.txt | ||
|
|
||
| .PHONY: clean | ||
| clean: | ||
| test -d "$(VIRTUALENV_DIR)" && rm -rf "$(VIRTUALENV_DIR)" | ||
|
|
||
| .PHONY: scriptsgen | ||
| scriptsgen: | ||
| scriptsgen: .create_venv .install_dependencies | ||
| @echo | ||
| @echo "================== scripts gen ====================" | ||
| @echo | ||
| /usr/bin/env python3 tools/generate_final_installer_scripts.py | ||
| "$(VIRTUALENV_DIR)/bin/python3" tools/generate_install_script.py | ||
|
|
||
| .PHONY: .generated-files-check | ||
| .generated-files-check: | ||
| # Verify that all the files which are automatically generated have indeed been re-generated and | ||
| # committed | ||
| # Verify that all the files which are automatically generated have indeed | ||
| # been re-generated and committed. | ||
| @echo "==================== generated-files-check ====================" | ||
|
|
||
| # 1. Sample config - conf/st2.conf.sample | ||
| cp scripts/st2bootstrap-deb.sh /tmp/st2bootstrap-deb.sh.upstream | ||
| cp scripts/st2bootstrap-el8.sh /tmp/st2bootstrap-el8.sh.upstream | ||
| cp scripts/st2bootstrap-el9.sh /tmp/st2bootstrap-el9.sh.upstream | ||
|
|
||
| make scriptsgen | ||
|
|
||
| diff scripts/st2bootstrap-deb.sh /tmp/st2bootstrap-deb.sh.upstream || (echo "scripts/st2bootstrap-deb.sh hasn't been re-generated and committed. Please run \"make scriptsgen\" and include and commit the generated file." && exit 1) | ||
| diff scripts/st2bootstrap-el8.sh /tmp/st2bootstrap-el8.sh.upstream || (echo "scripts/st2bootstrap-el8.sh hasn't been re-generated and committed. Please run \"make scriptsgen\" and include and commit the generated file." && exit 1) | ||
| diff scripts/st2bootstrap-el9.sh /tmp/st2bootstrap-el9.sh.upstream || (echo "scripts/st2bootstrap-el9.sh hasn't been re-generated and committed. Please run \"make scriptsgen\" and include and commit the generated file." && exit 1) | ||
|
|
||
| export NEED_COMMIT=0; \ | ||
| for i in scripts/st2bootstrap-*.sh; \ | ||
| do \ | ||
| export FILE=$$(git status -s "$$i"); \ | ||
| if grep -E " M $$i" <<<$$FILE ; then \ | ||
| echo "$$i hasn't been re-generated and committed. Please run \"make scriptsgen\" and include and commit the generated file."; \ | ||
| export NEED_COMMIT=1; \ | ||
| git diff "$$i" | cat; \ | ||
| elif grep -E "\?\? $$i" <<<$$FILE ; then \ | ||
| echo "$$i does not appear to be under git control!? Please add it to git or remove it from the directory."; \ | ||
| fi; \ | ||
| done; \ | ||
| test $$NEED_COMMIT -eq 1 && exit 2 || true | ||
| @echo "All automatically generated files are up to date." | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Installation script template | ||
|
|
||
| ## Overview | ||
|
|
||
| The installation script is used to install StackStorm on to officially supported Linux distributions running on bare-metal or virtual machine systems. The installation consists of applying system configuration and software installation required to run StackStorm and its dependencies on a single host. A high-availability deployment is outside the scope of this script. Consult the official documentation for instructions on how to deploy StackStorm in a high-availability configuration. | ||
|
|
||
| ## Components | ||
|
|
||
| To maintain consistent logic and behaviour across multiple distributions and releases, there are two main phases to creating modular logical blocks of the script: | ||
|
|
||
| 1. Build time - Jinja template logic selectively includes, excludes or adapts code included in the output script. | ||
| 2. Run time - BASH script is written to use functions to apply system changes in logical blocks. | ||
|
|
||
| ## Jinja Template Logic | ||
|
|
||
| Shell scripts are generated by running the make file. | ||
|
|
||
| `make` | ||
|
|
||
| The make file will setup a Python virtual environment, install jinja2 and read the set of Linux distributions to be generated from a JSON data file. | ||
|
|
||
| The Jinja template engine will be given high level information to generate the script. Below is the information to create the installation script for Ubuntu 20.04: | ||
| ``` | ||
| { | ||
| "id": "ubuntu", | ||
| "version_id": "20.04", | ||
| "script_filename": "st2bootstrap-focal.sh", | ||
| "pkg_mgr": "apt" | ||
| } | ||
| ``` | ||
| The generation script and data file can be found in the `tools` directory. The Jinja templates themselves are found in the `templates` directory. | ||
|
|
||
| The main template is `st2bootstrap.jinja` which includes all other jinja templates. Templates are written to group functional parts of the script into a single file to help maintainability and readability. | ||
|
|
||
| - `funcs_display.jinja`: Functions related to formatting script output. | ||
| - `funcs_mongodb.jinja`: Functions to configure and install mongodb on the system. | ||
| - `funcs_package_manager.jinja`: Functions to install or query packages. | ||
| - `funcs_rabbitmq.jinja`: Functions to configure and install rabbitmq on the system. | ||
| - `funcs_redis.jinja`: Function to configure and install redis on the system. | ||
| - `funcs_repo_manager.jinja`: Functions to install and query package repositories. | ||
| - `funcs_setup.jinja`: Functions to process script parameter input. | ||
| - `funcs_st2chatops.jinja`: Functions to install ChatOps on the system. | ||
| - `funcs_st2.jinja`: Functions to install StackStorm on the system. | ||
| - `funcs_st2web.jinja`: Functions to install Web App on the system. | ||
| - `funcs_system.jinja`: Functions for configuration and checks of installation pre-requisites. | ||
| - `funcs_usage.jinja`: Functions for help output. | ||
|
|
||
| In general, templating is used to conditionally include shell code based on distribution id, package manger or release id. | ||
| Some special cases are | ||
| - RedHat type systems have a major.minor release (e.g. 9.1, 9.2 ...) but package repositories only make the distinction by major version. To avoid the need to repeat entries in the data file for each minor version iteration only the major version is used. | ||
| - Debian type systems have versions (e.g. Ubuntu 20.04 or Debian 11) however the version code name is often used to select the repository. This isn't required in the data file because the codename is sourced from `/etc/os-release`. | ||
|
|
||
| Scripts are generated and written in the `scripts` directory. After they're generated, shell comments are stripped to reduce the file size by approximately 15%. | ||
|
|
||
| ## Shell Logic | ||
|
|
||
| As described above, shell logic is grouped by high level functions. These functions should avoid accessing global state or producing side effects, such as defining global variables from within the function calls. | ||
| The only code that is executed immediately is the code located in the `st2bootstrap.jinja` template. Shell variables are scoped to avoid name collisions or side effects between function calls. | ||
|
|
||
| While only RedHat and Ubuntu type distributions are supported as of writing, the install script is designed to be as generic and flexible as possible to add other distributions or handle system evolutions in a clean, modular fashion. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Jinja2 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.