From a57c11b7620fc157417b5520153cab6b27b875ef Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 5 Feb 2024 14:27:36 +0000 Subject: [PATCH 1/2] ci: test monolithic scripts (#179) * ci: test monolithic scripts * fix spawn * sleep between backup and restore to allow container to come up --- .github/workflows/docker-compose-verify.yml | 2 +- .../workflows/docker-monolithic-verify.yml | 25 +++++- templates/docker-monolithic/setup.sh | 19 ++++- .../docker-monolithic/verify-install.exp | 79 +++++++++++++++++++ 4 files changed, 119 insertions(+), 6 deletions(-) create mode 100755 templates/docker-monolithic/verify-install.exp diff --git a/.github/workflows/docker-compose-verify.yml b/.github/workflows/docker-compose-verify.yml index f70bab5..a3008b9 100644 --- a/.github/workflows/docker-compose-verify.yml +++ b/.github/workflows/docker-compose-verify.yml @@ -27,7 +27,7 @@ jobs: -w "/v" \ koalaman/shellcheck \ -e SC1091 -e SC1117 \ - setup.sh + *.sh - name: docker compose config test run: | diff --git a/.github/workflows/docker-monolithic-verify.yml b/.github/workflows/docker-monolithic-verify.yml index c5963d9..ce70e23 100644 --- a/.github/workflows/docker-monolithic-verify.yml +++ b/.github/workflows/docker-monolithic-verify.yml @@ -26,9 +26,32 @@ jobs: -w "/v" \ koalaman/shellcheck \ -e SC1091 -e SC1117 \ - setup.sh + *.sh - name: docker compose config test run: | echo "" > .env docker compose config + + - name: install supportpal + run: | + bash setup.sh --local -n --host "http://localhost" --email "kieran@supportpal.com" + docker compose up -d + + sudo apt install -y expect + expect verify-install.exp + + sleep 5 + curl -fSL -o /tmp/test.txt http://localhost/ + if ! grep -q "SupportPal" /tmp/test.txt; then + echo "ERROR: SupportPal is not loading via HTTP" + exit 3 + fi + env: + SUPPORTPAL_LICENSE_KEY: "${{ secrets.SUPPORTPAL_MONO_LICENSE_KEY }}" + + - name: test backup/restore + run: | + bash backup.sh + sleep 60 + bash restore.sh diff --git a/templates/docker-monolithic/setup.sh b/templates/docker-monolithic/setup.sh index bc11d52..b500216 100755 --- a/templates/docker-monolithic/setup.sh +++ b/templates/docker-monolithic/setup.sh @@ -6,6 +6,8 @@ usage="Options: -n Run the command non interactively. + --local The script is being ran from the repository, so don't use CURL to download them. + -r,--ref= Git ref (commit sha, ref name, tag) to run the script on. -H,--host= Domain name to use with SupportPal. @@ -14,6 +16,7 @@ usage="Options: " # Options +local=0 interactive=1 host= email= @@ -23,6 +26,7 @@ while [[ "$#" -gt 0 ]]; do case $1 in -h|--help) echo "$usage" ; exit 0 ;; -n) interactive=0 ;; + --local) local=1 ;; -H|--host) host="$2" ; shift ;; -e|--email) email="$2" ; shift ;; -r|--ref) ref="$2" ; shift ;; @@ -186,13 +190,16 @@ create_volume() { configure() { # download docker-compose.yml example printf "generating docker-compose.yml ... " - if [[ -f "docker-compose.yml" ]]; then + if [[ -f "docker-compose.yml" ]] && [[ "$local" -eq 0 ]]; then echo echo "error: $(pwd)/docker-compose.yml already exists. Delete the file and try again." exit 1 fi - curl -fLsS https://raw.githubusercontent.com/supportpal/helpdesk-install/"${ref}"/templates/docker-monolithic/docker-compose.yml -o docker-compose.yml - curl -fLsS https://raw.githubusercontent.com/supportpal/helpdesk-install/"${ref}"/templates/docker-monolithic/docker-compose.override.yml -o docker-compose.override.yml + + if [[ "$local" -eq 0 ]]; then + curl -fLsS https://raw.githubusercontent.com/supportpal/helpdesk-install/"${ref}"/templates/docker-monolithic/docker-compose.yml -o docker-compose.yml + curl -fLsS https://raw.githubusercontent.com/supportpal/helpdesk-install/"${ref}"/templates/docker-monolithic/docker-compose.override.yml -o docker-compose.override.yml + fi echo "" > .env @@ -221,7 +228,11 @@ configure() { fi # create volumes - bash <(curl -LsS https://raw.githubusercontent.com/supportpal/helpdesk-install/"${ref}"/templates/docker-monolithic/create_volumes.sh) + if [[ "$local" -eq 0 ]]; then + bash <(curl -LsS https://raw.githubusercontent.com/supportpal/helpdesk-install/"${ref}"/templates/docker-monolithic/create_volumes.sh) + else + bash create_volumes.sh + fi } check_memory() { diff --git a/templates/docker-monolithic/verify-install.exp b/templates/docker-monolithic/verify-install.exp new file mode 100755 index 0000000..9c51708 --- /dev/null +++ b/templates/docker-monolithic/verify-install.exp @@ -0,0 +1,79 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Mon Feb 5 13:07:01 2024 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 + +match_max 100000 + +spawn docker compose exec supportpal bash -c {bash /init/init-helpdesk.sh} + +expect "I Accept and Continue (yes/no)*:\r" +send -- "yes\r" + +expect "SupportPal requires a valid license to function, please enter one below.*:*" +sleep 1 +send "$env(SUPPORTPAL_LICENSE_KEY)\r" + +expect "Email*:*" +send -- "operator@my.company\r" + +expect "Password*:*" +send -- "test\r" + +expect "First Name*:*" +send -- "Joe\r" + +expect "Last Name*:*" +send -- "Blogs\r" + +expect "Brand Name*:*" +send -- "My Company\r" + +expect "Enter the full web address of your installation*:*" +send -- "http://localhost\r" + +expect "Enter your main company email address*:*" +send -- "support@my.company\r" + +expect eof From 88c82fa9adf99e9ab893262f5d23896caed9eeea Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 5 Feb 2024 14:33:22 +0000 Subject: [PATCH 2/2] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ec0216..6bd3550 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,11 @@ This repository contains templates to get started using SupportPal. ## Docker Compose -This [template](https://docs.supportpal.com/current/Deploy+on+Docker) relies on docker-compose to manage the helpdesk software deployment. A typical use case for this template would be a standalone server. +This [template](https://docs.supportpal.com/current/Deploy+on+Docker+HA) is intended for use in a microservice style architecture, whereby each service is deployed to a separate container. It provides a functional example for how you may deploy SupportPal in a HA environment. + +## Docker Monolithic + +This [template](https://docs.supportpal.com/current/Deploy+on+Docker) uses a monolithic image which runs all the necessary services in a single container. This is our recommended installation method. ## Linux