From ce7b4c8ba3364cac2e457e8551c29eb62bf0dfa3 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 29 Jul 2020 19:56:36 +0300 Subject: [PATCH 01/32] Run tests on Travis CI --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3eb6ce63..66cfe7ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,6 @@ before_install: - docker-compose up -d - docker ps - docker images + +script: + - CHTSH_URL=http://localhost:8002 bash tests/run-tests.sh From 40d18da4f722a2b0749863be39ba92d4e439e4c4 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 29 Jul 2020 19:59:53 +0300 Subject: [PATCH 02/32] Test server is up with `curl` before running tests --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 66cfe7ad..0b89cc32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,5 @@ before_install: - docker images script: + - curl http://localhost:8002 - CHTSH_URL=http://localhost:8002 bash tests/run-tests.sh From 06d8fa7fbdaaaacbae5d0c8aef956b84c42355d1 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 29 Jul 2020 20:12:02 +0300 Subject: [PATCH 03/32] `cd` to tests/ dir when runner is executed with relpath --- tests/run-tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index f5db9cff..36461f50 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -10,6 +10,9 @@ # 2) configure CHTSH_URL # 3) run the script +# work from script's dir +cd "$(dirname "$0")" || exit + PYTHON="${PYTHON:-../ve/bin/python}" "$PYTHON" --version 2>&1 | grep -q 'Python 2' && python_version=2 || python_version=3 From 3905047d6275bbc796dc95d09515a8e16a3186a3 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 29 Jul 2020 20:37:45 +0300 Subject: [PATCH 04/32] Wait 3 seconds to let server to start Because `docker-compose` is not capable of checking open ports https://github.com/docker/compose/issues/374 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0b89cc32..c4aa379a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,5 +9,6 @@ before_install: - docker images script: + - sleep 3 - curl http://localhost:8002 - CHTSH_URL=http://localhost:8002 bash tests/run-tests.sh From c515c564543a89401f193f4fb0d151f65c69d0f8 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 29 Jul 2020 22:44:18 +0300 Subject: [PATCH 05/32] Use `python3` command if virtualenv doesn't exist --- tests/run-tests.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 36461f50..97354cea 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -13,7 +13,14 @@ # work from script's dir cd "$(dirname "$0")" || exit +# detect Python - if not set in env, try default virtualenv PYTHON="${PYTHON:-../ve/bin/python}" +# if no virtalenv, try current python3 binary +if ! command -v $PYTHON &> /dev/null; then + PYTHON=$(command -v python3) +fi +echo "Using PYTHON: $PYTHON" + "$PYTHON" --version 2>&1 | grep -q 'Python 2' && python_version=2 || python_version=3 skip_online="${CHEATSH_TEST_SKIP_ONLINE:-NO}" From 1a1624e2e055917972e509e9a47b3c55d3ad780d Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 29 Jul 2020 22:59:09 +0300 Subject: [PATCH 06/32] Detect Python version using Python --- tests/run-tests.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 97354cea..06df392f 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -19,9 +19,8 @@ PYTHON="${PYTHON:-../ve/bin/python}" if ! command -v $PYTHON &> /dev/null; then PYTHON=$(command -v python3) fi -echo "Using PYTHON: $PYTHON" - -"$PYTHON" --version 2>&1 | grep -q 'Python 2' && python_version=2 || python_version=3 +python_version="$($PYTHON -c 'import sys; print(sys.version_info[0])')" +echo "Using PYTHON $python_version: $PYTHON" skip_online="${CHEATSH_TEST_SKIP_ONLINE:-NO}" test_standalone="${CHEATSH_TEST_STANDALONE:-YES}" From 1a5aa6408fbde30d1df2c0e1f0e388b0b177b8ed Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 29 Jul 2020 23:21:47 +0300 Subject: [PATCH 07/32] Turn off standalone mode to run tests against remote server --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c4aa379a..a3dfa2c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ before_install: script: - sleep 3 - curl http://localhost:8002 - - CHTSH_URL=http://localhost:8002 bash tests/run-tests.sh + - CHTSH_URL=http://localhost:8002 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh From 60ae85e031e2ac0b66fde4f97b9fd4547cb4fd8c Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 30 Jul 2020 02:24:54 +0300 Subject: [PATCH 08/32] Show which test is being run --- tests/run-tests.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 06df392f..077874d8 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -16,7 +16,7 @@ cd "$(dirname "$0")" || exit # detect Python - if not set in env, try default virtualenv PYTHON="${PYTHON:-../ve/bin/python}" # if no virtalenv, try current python3 binary -if ! command -v $PYTHON &> /dev/null; then +if ! command -v "$PYTHON" &> /dev/null; then PYTHON=$(command -v python3) fi python_version="$($PYTHON -c 'import sys; print(sys.version_info[0])')" @@ -48,6 +48,7 @@ failed=0 while read -r number test_line; do + echo "Running $number: $test_line" if [ "$skip_online" = YES ]; then if [[ $test_line = *\[online\]* ]]; then echo "$number is [online]; skipping" @@ -56,10 +57,12 @@ while read -r number test_line; do fi if [[ "$python_version" = 2 ]] && [[ $test_line = *\[python3\]* ]]; then + echo "$number is for Python 3; skipping" continue fi if [[ "$python_version" = 3 ]] && [[ $test_line = *\[python2\]* ]]; then + echo "$number is for Python 2; skipping" continue fi From 09dff20c9cab0d5f93a00b5a18cadfb8f7dcd935 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 30 Jul 2020 02:47:18 +0300 Subject: [PATCH 09/32] Add color to printed test names --- tests/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 077874d8..e8dce945 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -48,7 +48,7 @@ failed=0 while read -r number test_line; do - echo "Running $number: $test_line" + echo -e "\e[94mRunning $number: \e[96m$test_line\e[0m" if [ "$skip_online" = YES ]; then if [[ $test_line = *\[online\]* ]]; then echo "$number is [online]; skipping" From c0bbc245df9b0fb006bb7aa65471e764804af635 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 30 Jul 2020 17:51:12 +0300 Subject: [PATCH 10/32] Run `curl https://cht.sh` to pinpoint Travis problems with ANSI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a3dfa2c4..ce489729 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,6 @@ before_install: script: - sleep 3 + - curl https://cht.sh - curl http://localhost:8002 - CHTSH_URL=http://localhost:8002 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh From 4610690ec31794e874468257623b6555628d73ab Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 30 Jul 2020 22:20:58 +0300 Subject: [PATCH 11/32] Travis doesn't support bright colors, use 8 colors palette And remove temporary `curl cht.sh` call --- .travis.yml | 1 - tests/run-tests.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ce489729..a3dfa2c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,5 @@ before_install: script: - sleep 3 - - curl https://cht.sh - curl http://localhost:8002 - CHTSH_URL=http://localhost:8002 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh diff --git a/tests/run-tests.sh b/tests/run-tests.sh index e8dce945..488f67c9 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -48,7 +48,7 @@ failed=0 while read -r number test_line; do - echo -e "\e[94mRunning $number: \e[96m$test_line\e[0m" + echo -e "\e[34mRunning $number: \e[36m$test_line\e[0m" if [ "$skip_online" = YES ]; then if [[ $test_line = *\[online\]* ]]; then echo "$number is [online]; skipping" From 1387f8b6f87840624dd0c7e986be91a73bf7a8ca Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 30 Jul 2020 22:37:34 +0300 Subject: [PATCH 12/32] Show test command executed when `$show_details == YES` --- tests/run-tests.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 488f67c9..0d2552eb 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -71,17 +71,19 @@ while read -r number test_line; do if [ "$test_standalone" = YES ]; then test_line="${test_line//cht.sh /}" - "${PYTHON}" ../lib/standalone.py "$test_line" > "$TMP" 2> /dev/null + [[ $show_details == YES ]] && echo "${PYTHON} ../lib/standalone.py $test_line" + "${PYTHON}" ../lib/standalone.py "$test_line" > "$TMP" elif [[ $test_line = "cht.sh "* ]]; then test_line="${test_line//cht.sh /}" + [[ $show_details == YES ]] && echo "bash $CHTSH_SCRIPT $test_line" eval "bash $CHTSH_SCRIPT $test_line" > "$TMP" else + [[ $show_details == YES ]] && echo "curl -s $CHTSH_URL/$test_line" eval "curl -s $CHTSH_URL/$test_line" > "$TMP" fi if ! diff results/"$number" "$TMP" > "$TMP2"; then if [ "$show_details" = YES ]; then - echo "$ CHEATSH_CACHE_TYPE=none python ../lib/standalone.py $test_line" cat "$TMP2" fi echo "FAILED: [$number] $test_line" From 5737a1606a1ac4b017ac955e82636058355d8e65 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 30 Jul 2020 22:43:32 +0300 Subject: [PATCH 13/32] Use unified diff format --- tests/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 0d2552eb..1a3019a1 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -82,7 +82,7 @@ while read -r number test_line; do eval "curl -s $CHTSH_URL/$test_line" > "$TMP" fi - if ! diff results/"$number" "$TMP" > "$TMP2"; then + if ! diff -u3 results/"$number" "$TMP" > "$TMP2"; then if [ "$show_details" = YES ]; then cat "$TMP2" fi From a0d344c38df8aa22266ab03a17f39a2dea0c04f7 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 30 Jul 2020 23:03:44 +0300 Subject: [PATCH 14/32] Use http://localhost:8002 for default tests CHTSH_URL --- tests/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 1a3019a1..48ecce1d 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -25,13 +25,13 @@ echo "Using PYTHON $python_version: $PYTHON" skip_online="${CHEATSH_TEST_SKIP_ONLINE:-NO}" test_standalone="${CHEATSH_TEST_STANDALONE:-YES}" show_details="${CHEATSH_TEST_SHOW_DETAILS:-YES}" +CHTSH_URL="${CHTSH_URL:-'http://localhost:8002'}" TMP=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX) TMP2=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX) TMP3=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX) trap 'rm -rf $TMP $TMP2 $TMP3' EXIT -export CHTSH_URL=http://cht.sh:50000 CHTSH_SCRIPT=$(dirname "$(dirname "$(readlink -f "$0")")")/share/cht.sh.txt export PYTHONIOENCODING=UTF-8 From e0f84e8b3a296c618844f75b4804f17dab91442b Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 30 Jul 2020 23:17:01 +0300 Subject: [PATCH 15/32] Pipe colored diffs --- tests/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 48ecce1d..6b3e5efa 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -82,7 +82,7 @@ while read -r number test_line; do eval "curl -s $CHTSH_URL/$test_line" > "$TMP" fi - if ! diff -u3 results/"$number" "$TMP" > "$TMP2"; then + if ! diff -u3 --color=always results/"$number" "$TMP" > "$TMP2"; then if [ "$show_details" = YES ]; then cat "$TMP2" fi From 10326234ffac47d5061f879437a0157b43070728 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 04:57:12 +0300 Subject: [PATCH 16/32] Fix `btrfs` test drift as trailing whitespaces were fixed https://github.com/chubin/cheat.sheets/commit/d7473ac185bc4309b5d4aa55761233e974c5f80d#diff-8d0f560b012648accbca6af7a3356d61 --- tests/results/4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/results/4 b/tests/results/4 index 10b9309f..df4bb0f4 100644 --- a/tests/results/4 +++ b/tests/results/4 @@ -1,7 +1,7 @@ # Create a btrfs file system on /dev/sdb, /dev/sdc, and /dev/sdd mkfs.btrfs /dev/sdb /dev/sdc /dev/sdd -# btrfs with just one hard drive, metadata not redundant  +# btrfs with just one hard drive, metadata not redundant # (this is danegerous: if your metadata is lost, your data is lost as well) mkfs.btrfs -m single /dev/sdb From be9d3a70fec21fbc03f809dc9b8cbe30a600c5a5 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 09:25:04 +0300 Subject: [PATCH 17/32] Run cheat.sh service (app) by `docker-compose` in debug mode This would allow later inspection of stdout. Assigned names to image and container to avoid confusion. Build is done separately to clean up the output. --- .travis.yml | 3 ++- docker-compose.yml | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3dfa2c4..f142efb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,8 @@ language: - generic before_install: - - docker-compose up -d + - docker-compose build + - docker-compose run -d app bin/srv.py --debug - docker ps - docker images diff --git a/docker-compose.yml b/docker-compose.yml index 589033c6..da8cfbb5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,9 @@ version: '2' services: app: - build: - context: . + build: . + image: cheat.sh + container_name: chtsh depends_on: - redis ports: From 6be6a25c2ab70e340932b3d59abaf446abe77e96 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 09:34:00 +0300 Subject: [PATCH 18/32] `docker-compose run` requires explicit port permission --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f142efb1..0a36ef7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ language: before_install: - docker-compose build - - docker-compose run -d app bin/srv.py --debug + - docker-compose run -d --service-ports app bin/srv.py --debug - docker ps - docker images From 9a495a76155c78d5cf0bb1d258e90895ce119901 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 09:57:20 +0300 Subject: [PATCH 19/32] Try to show container log in case of error on Travis --- tests/run-tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 6b3e5efa..222ad716 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -86,6 +86,9 @@ while read -r number test_line; do if [ "$show_details" = YES ]; then cat "$TMP2" fi + if grep -q "Internal Server Error" "$TMP2"; then + [[ $TRAVIS == true ]] && docker-compose logs app + fi echo "FAILED: [$number] $test_line" ((failed++)) fi From 5dab632e217591afd06074613bad9626421473ec Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 10:09:19 +0300 Subject: [PATCH 20/32] Try --no-color to avoid log output being stripped by Travis --- .travis.yml | 1 + tests/run-tests.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0a36ef7e..a0026560 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,4 +12,5 @@ before_install: script: - sleep 3 - curl http://localhost:8002 + - docker-compose logs app - CHTSH_URL=http://localhost:8002 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 222ad716..43237218 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -87,7 +87,7 @@ while read -r number test_line; do cat "$TMP2" fi if grep -q "Internal Server Error" "$TMP2"; then - [[ $TRAVIS == true ]] && docker-compose logs app + [[ $TRAVIS == true ]] && docker-compose logs --no-color fi echo "FAILED: [$number] $test_line" ((failed++)) From 10bfaab38cc649d765637bf4af4791266d21a3f7 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 13:31:31 +0300 Subject: [PATCH 21/32] Modern DevOps is a PITA Run Python 3 in unbuffered mode to see lines in `docker logs` as soon as they appear. When Python 3 is not attached to a terminal, it turns on the buffering, like when `docker` runs in a background. --- .travis.yml | 2 +- Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a0026560..1ac2cec5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ language: before_install: - docker-compose build - - docker-compose run -d --service-ports app bin/srv.py --debug + - docker-compose run -d --service-ports app --debug - docker ps - docker images diff --git a/Dockerfile b/Dockerfile index e78be409..e41aa0a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,5 +15,5 @@ RUN mkdir -p /root/.cheat.sh/log/ \ # installing server dependencies RUN apk add --update --no-cache py3-jinja2 py3-flask bash gawk -ENTRYPOINT ["python3"] -CMD ["bin/srv.py"] +ENTRYPOINT ["python3", "-u", "bin/srv.py"] +CMD [""] From 2e1d8041c9a308ec72631a151400760d11e7c908 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 14:46:44 +0300 Subject: [PATCH 22/32] Try `docker-compose` logs with no color --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1ac2cec5..f1c8b172 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,5 +12,5 @@ before_install: script: - sleep 3 - curl http://localhost:8002 - - docker-compose logs app + - docker-compose logs --no-color - CHTSH_URL=http://localhost:8002 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh From f62fb51d3f3d2179648a75a979dd8ebf0b9f76b6 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 14:54:52 +0300 Subject: [PATCH 23/32] View container log without `docker-compose` --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f1c8b172..d4781c27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ language: before_install: - docker-compose build - - docker-compose run -d --service-ports app --debug + - docker-compose run -d --service-ports --name chtsh app --debug + - docker-compose ps - docker ps - docker images @@ -13,4 +14,5 @@ script: - sleep 3 - curl http://localhost:8002 - docker-compose logs --no-color + - docker logs chtsh - CHTSH_URL=http://localhost:8002 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh From ca55415659495c41da08a3985b0537e432258900 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 15:12:56 +0300 Subject: [PATCH 24/32] Check `docker logs` with unbuffered Python again --- .travis.yml | 3 ++- tests/run-tests.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d4781c27..02dfb5ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ language: before_install: - docker-compose build - - docker-compose run -d --service-ports --name chtsh app --debug + #- docker-compose run -d --service-ports --name chtsh app --debug + - docker-compose up -d - docker-compose ps - docker ps - docker images diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 43237218..185c42a6 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -87,7 +87,7 @@ while read -r number test_line; do cat "$TMP2" fi if grep -q "Internal Server Error" "$TMP2"; then - [[ $TRAVIS == true ]] && docker-compose logs --no-color + [[ $TRAVIS == true ]] && docker logs chtsh fi echo "FAILED: [$number] $test_line" ((failed++)) From 198a2c41c9e7149351b7d935e27e38f6c704ce40 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 16:43:14 +0300 Subject: [PATCH 25/32] Add --debug option to chtsh container the `docker-compose` way --- .travis.yml | 6 ++---- docker-compose.debug.yml | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 docker-compose.debug.yml diff --git a/.travis.yml b/.travis.yml index 02dfb5ac..af960014 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,9 @@ language: before_install: - docker-compose build - #- docker-compose run -d --service-ports --name chtsh app --debug - - docker-compose up -d - - docker-compose ps - - docker ps - docker images + - docker-compose -f docker-compose.yml -f docker-compose.debug.yml up -d + - docker-compose ps script: - sleep 3 diff --git a/docker-compose.debug.yml b/docker-compose.debug.yml new file mode 100644 index 00000000..0a784323 --- /dev/null +++ b/docker-compose.debug.yml @@ -0,0 +1,8 @@ +# Compose override to add --debug option to bin/srv.py +# call to print tracebacks on errors to stdout. +# +# See https://docs.docker.com/compose/extends/ + +services: + app: + command: "--debug" From acd07d27c1a075bcda7e40c2e5c6682f4f7b5e94 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 16:56:30 +0300 Subject: [PATCH 26/32] Override files needs a version too --- docker-compose.debug.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.debug.yml b/docker-compose.debug.yml index 0a784323..56c5e9c9 100644 --- a/docker-compose.debug.yml +++ b/docker-compose.debug.yml @@ -2,7 +2,7 @@ # call to print tracebacks on errors to stdout. # # See https://docs.docker.com/compose/extends/ - +version: '2' services: app: command: "--debug" From ee273e2d512fb0fa7fab60f2dfad5b206b5a6870 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Fri, 31 Jul 2020 19:29:43 +0300 Subject: [PATCH 27/32] Now fixing connection to Redis on Travis Docker Default `localhost:6379` doesn't work there. Trying to set REDIS_HOST advertised in `run-tests.sh` --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af960014..4e75a7c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ script: - curl http://localhost:8002 - docker-compose logs --no-color - docker logs chtsh - - CHTSH_URL=http://localhost:8002 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh + - REDIS_HOST=http://redis:6379 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh From 91320d921d38107f8792332f1a53ec84dab4365c Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 1 Aug 2020 00:41:05 +0300 Subject: [PATCH 28/32] Set Redis host using cheat.sh config framework https://github.com/chubin/cheat.sh/blob/f5d5fae71218e771e84b896600b2504c0d8814ec/lib/config.py --- .travis.yml | 2 +- docker-compose.yml | 2 ++ tests/run-tests.sh | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4e75a7c4..f64a78ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ script: - curl http://localhost:8002 - docker-compose logs --no-color - docker logs chtsh - - REDIS_HOST=http://redis:6379 CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh + - CHEATSH_TEST_STANDALONE=NO bash tests/run-tests.sh diff --git a/docker-compose.yml b/docker-compose.yml index da8cfbb5..8221bafa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,8 @@ services: container_name: chtsh depends_on: - redis + environment: + - CHEATSH_REDIS_HOST=redis ports: - "8002:8002" redis: diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 185c42a6..1a42b869 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -2,10 +2,10 @@ # 1) start server: # without caching: -# REDIS_HOST=None CHEATSH_PORT=50000 python bin/srv.py +# CHEATSH_REDIS_HOST=None CHEATSH_PORT=50000 python bin/srv.py # (recommended) # with caching: -# REDIS_PREFIX=TEST1 CHEATSH_PORT=50000 python bin/srv.py +# CHEATSH_REDIS_PREFIX=TEST1 CHEATSH_PORT=50000 python bin/srv.py # (for complex search queries + to test caching) # 2) configure CHTSH_URL # 3) run the script From 36a7cd3fc55d31105090e118a415e047a2bafac3 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 1 Aug 2020 00:53:24 +0300 Subject: [PATCH 29/32] Set proper config names and update `docker` status in README.md The proper config name for Redis host is CHEATSH_CACHE_REDIS_HOST and for disabling cache the var is CHEATSH_CACHE_TYPE. --- README.md | 12 ++++++++++-- docker-compose.yml | 2 +- tests/run-tests.sh | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 98d4c6ef..86284cc2 100644 --- a/README.md +++ b/README.md @@ -447,8 +447,16 @@ scoop install cht ### Docker -Currently, the easiest way to get a self-hosted instance running is by using the docker-compose.yml file provided in the extra/docker folder. -This pulls down the latest image with baked in cheatsheets and starts the app and a Redis instance to back it, making the service available on port 8002 of the local host. This is currently an early implementation and should probably not be used for anything outside of internal/dev/personal use right now. +Currently, the easiest way to get a self-hosted instance running is by using +the `docker-compose.yml` file. + + docker-compose up + +This builds and runs the image with baked in cheatsheets and starts the app +and a Redis instance to back it, making the service available at +http://localhost:8002 This is currently an early implementation and should +probably not be used for anything outside of internal/dev/personal use right +now. ## Editors integration diff --git a/docker-compose.yml b/docker-compose.yml index 8221bafa..9e5f58f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: depends_on: - redis environment: - - CHEATSH_REDIS_HOST=redis + - CHEATSH_CACHE_REDIS_HOST=redis ports: - "8002:8002" redis: diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 1a42b869..400b0332 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -2,7 +2,7 @@ # 1) start server: # without caching: -# CHEATSH_REDIS_HOST=None CHEATSH_PORT=50000 python bin/srv.py +# CHEATSH_CACHE_TYPE=none CHEATSH_PORT=50000 python bin/srv.py # (recommended) # with caching: # CHEATSH_REDIS_PREFIX=TEST1 CHEATSH_PORT=50000 python bin/srv.py From ca88810936ce290c1977ceb8317c405d6da54da2 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 1 Aug 2020 06:06:49 +0300 Subject: [PATCH 30/32] run-tests.sh Quotes are not needed in default param --- tests/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 400b0332..8422bbd5 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -25,7 +25,7 @@ echo "Using PYTHON $python_version: $PYTHON" skip_online="${CHEATSH_TEST_SKIP_ONLINE:-NO}" test_standalone="${CHEATSH_TEST_STANDALONE:-YES}" show_details="${CHEATSH_TEST_SHOW_DETAILS:-YES}" -CHTSH_URL="${CHTSH_URL:-'http://localhost:8002'}" +CHTSH_URL="${CHTSH_URL:-http://localhost:8002}" TMP=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX) TMP2=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX) From b74707a109749eb680f754c7f1d4f31e7a18956e Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 1 Aug 2020 06:10:03 +0300 Subject: [PATCH 31/32] Redis doesn't need to be Strict https://github.com/andymccurdy/redis-py#client-classes-redis-and-strictredis --- bin/clean_cache.py | 2 +- lib/cache.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/clean_cache.py b/bin/clean_cache.py index 1b4fe630..bc19aa84 100644 --- a/bin/clean_cache.py +++ b/bin/clean_cache.py @@ -1,6 +1,6 @@ import sys import redis -REDIS = redis.StrictRedis(host='localhost', port=6379, db=0) +REDIS = redis.Redis(host='localhost', port=6379, db=0) for key in sys.argv[1:]: REDIS.delete(key) diff --git a/lib/cache.py b/lib/cache.py index 5f552763..8e2b1263 100644 --- a/lib/cache.py +++ b/lib/cache.py @@ -19,7 +19,7 @@ _REDIS = None if CONFIG['cache.type'] == 'redis': import redis - _REDIS = redis.StrictRedis( + _REDIS = redis.Redis( host=CONFIG['cache.redis.host'], port=CONFIG['cache.redis.port'], db=CONFIG['cache.redis.db']) From 7578ab7bb035995e6d2be86fddfd064f8f640c8e Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Thu, 6 Aug 2020 06:30:54 +0200 Subject: [PATCH 32/32] minifix --- tests/run-tests.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 9c13b8c8..9f92e8e1 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -86,7 +86,6 @@ while read -r number test_line; do if ! diff -u3 --color=always results/"$number" "$TMP" > "$TMP2"; then if [[ $CHEATSH_UPDATE_TESTS_RESULTS = NO ]]; then if [ "$show_details" = YES ]; then - echo "$ CHEATSH_CACHE_TYPE=none python ../lib/standalone.py $test_line" cat "$TMP2" fi if grep -q "Internal Server Error" "$TMP2"; then