From 5acfdb491b5e7f6ce9530c2cf5882e805f2e0ba9 Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Sun, 29 Jul 2018 20:34:29 -0700 Subject: [PATCH 01/11] Updated .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e5d9ef6..d95c119 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ ve/ share/vim/.vim/ share/vim/.viminfo typescript +venv/ From 22953bb109adc45c142e0653ca87f10d7a798065 Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Sun, 29 Jul 2018 23:51:41 -0700 Subject: [PATCH 02/11] Can now build a Docker image of the app with cheatsheets pulled in at build time and use Docker Compose to get it running with Redis --- Dockerfile | 9 +++++++++ bin/srv.py | 3 ++- docker-compose.yml | 15 +++++++++++++++ lib/beautifier.py | 4 ++-- lib/get_answer.py | 4 ++-- lib/globals.py | 3 ++- lib/stateful_queries.py | 3 ++- share/scripts/get-sheets.sh | 2 +- 8 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c4586bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:latest +RUN apk add --update --no-cache python2 py2-pip py2-gevent \ + py2-flask py2-requests py2-pygments py2-redis \ + py2-cffi py2-icu bash vim gawk sed +WORKDIR /app +COPY . /app +RUN apk add --update --no-cache --virtual build-deps python2-dev build-base git && pip install -r requirements.txt && sh share/scripts/get-sheets.sh && apk del build-deps +ENTRYPOINT ["python2"] +CMD ["bin/srv.py"] \ No newline at end of file diff --git a/bin/srv.py b/bin/srv.py index ce646aa..858cf3b 100644 --- a/bin/srv.py +++ b/bin/srv.py @@ -6,8 +6,9 @@ Main server program. """ from __future__ import print_function -from gevent.pywsgi import WSGIServer from gevent.monkey import patch_all +from gevent.pywsgi import WSGIServer + patch_all() # pylint: disable=wrong-import-position,wrong-import-order diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..91a6f84 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '3.6' +services: + app: + build: + context: . + depends_on: + - redis + ports: + - "8002:8002" + redis: + image: redis:3.2-alpine + volumes: + - redis_data:/data +volumes: + redis_data: \ No newline at end of file diff --git a/lib/beautifier.py b/lib/beautifier.py index 3a257d2..1518b33 100644 --- a/lib/beautifier.py +++ b/lib/beautifier.py @@ -36,10 +36,10 @@ import redis MYDIR = os.path.abspath(os.path.join(__file__, '..', '..')) sys.path.append("%s/lib/" % MYDIR) from languages_data import VIM_NAME -from globals import PATH_VIM_ENVIRONMENT +from globals import PATH_VIM_ENVIRONMENT, REDISHOST # pylint: enable=wrong-import-position,wrong-import-order -REDIS = redis.StrictRedis(host='localhost', port=6379, db=1) +REDIS = redis.StrictRedis(host=REDISHOST, port=6379, db=1) FNULL = open(os.devnull, 'w') TEXT = 0 CODE = 1 diff --git a/lib/get_answer.py b/lib/get_answer.py index e4363cf..aac6fb8 100644 --- a/lib/get_answer.py +++ b/lib/get_answer.py @@ -25,13 +25,13 @@ from polyglot.detect.base import UnknownLanguage import time import beautifier -from globals import MYDIR, PATH_TLDR_PAGES, PATH_CHEAT_PAGES, PATH_CHEAT_SHEETS, COLOR_STYLES +from globals import MYDIR, PATH_TLDR_PAGES, PATH_CHEAT_PAGES, PATH_CHEAT_SHEETS, COLOR_STYLES, REDISHOST from adapter_learnxiny import get_learnxiny, get_learnxiny_list, is_valid_learnxy from languages_data import LANGUAGE_ALIAS, SO_NAME from colorize_internal import colorize_internal # pylint: enable=wrong-import-position,wrong-import-order -REDIS = redis.StrictRedis(host='localhost', port=6379, db=0) +REDIS = redis.StrictRedis(host=REDISHOST, port=6379, db=0) MAX_SEARCH_LEN = 20 diff --git a/lib/globals.py b/lib/globals.py index c285369..3c3b700 100644 --- a/lib/globals.py +++ b/lib/globals.py @@ -9,6 +9,7 @@ import os from pygments.styles import get_all_styles MYDIR = os.path.abspath(os.path.join(__file__, '..', '..')) +REDISHOST = 'redis' ANSI2HTML = os.path.join(MYDIR, "share/ansi2html.sh") @@ -18,7 +19,7 @@ TEMPLATES = os.path.join(MYDIR, 'share/templates') STATIC = os.path.join(MYDIR, 'share/static') PATH_VIM_ENVIRONMENT = os.path.join(MYDIR, 'share/vim') -USE_OS_PACKAGES = True # change it False if you pull cheat sheets repositories from GitHub +USE_OS_PACKAGES = False # change it False if you pull cheat sheets repositories from GitHub if USE_OS_PACKAGES: PATH_TLDR_PAGES = "/home/igor/.tldr/cache/pages/*/*.md" PATH_CHEAT_PAGES = "/usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/*" diff --git a/lib/stateful_queries.py b/lib/stateful_queries.py index 424072a..578e2e2 100644 --- a/lib/stateful_queries.py +++ b/lib/stateful_queries.py @@ -3,8 +3,9 @@ Support for the stateful queries """ import redis +from globals import REDISHOST -REDIS = redis.StrictRedis(host='localhost', port=6379, db=1) +REDIS = redis.StrictRedis(host=REDISHOST, port=6379, db=1) def save_query(client_id, query): """ diff --git a/share/scripts/get-sheets.sh b/share/scripts/get-sheets.sh index 7145e54..c72184b 100644 --- a/share/scripts/get-sheets.sh +++ b/share/scripts/get-sheets.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ## this doesn't error check, if it breaks and destroys things I'm sorry From 13ec7989db784870b839796e3ecca0c8341a080f Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Mon, 30 Jul 2018 13:01:25 -0700 Subject: [PATCH 03/11] TravisCI test --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..22a824f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +env: + DOCKER_COMPOSE_VERSION: 1.22.0 + +before_install: + - sudo apt-get update + - sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-engine + - docker-compose --version + - sudo rm /usr/local/bin/docker-compose + - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose + - chmod +x docker-compose + - sudo mv docker-compose /usr/local/bin + - docker-compose --version + - docker-compose build + - docker-compose start + - docker ps From f5833732f5da3a7ab2cfe6f005fe24a80ca56b5c Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Mon, 30 Jul 2018 13:09:10 -0700 Subject: [PATCH 04/11] Fix up .travisci.yml --- .travis.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22a824f..bf137c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,22 @@ +dist: trusty +sudo: required + +services: + - docker + env: DOCKER_COMPOSE_VERSION: 1.22.0 +addons: + apt: + packages: + - docker-ce + before_install: - - sudo apt-get update - - sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-engine - - docker-compose --version - sudo rm /usr/local/bin/docker-compose - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose - chmod +x docker-compose - sudo mv docker-compose /usr/local/bin - - docker-compose --version - docker-compose build - docker-compose start - docker ps From 80dedbb9ea6086a34a3d0d7a19c9efa3e52cd1cb Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Mon, 30 Jul 2018 13:17:35 -0700 Subject: [PATCH 05/11] Fix up .travisci.yml, compose up instead of start --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bf137c5..203aa96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,5 @@ before_install: - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose - chmod +x docker-compose - sudo mv docker-compose /usr/local/bin - - docker-compose build - - docker-compose start + - docker-compose up -d - docker ps From 1d042ed1040c83cd6bed1ca59798c84671ff8f66 Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Mon, 30 Jul 2018 13:27:07 -0700 Subject: [PATCH 06/11] Stupid little issues with .travisci.yml, changed language to generic --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 203aa96..3a40513 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ dist: trusty sudo: required +language: + - generic + services: - docker From 6b48b06f203066db95a76542c259d49d101a9468 Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Mon, 30 Jul 2018 20:44:47 -0700 Subject: [PATCH 07/11] Dockerfile clean up --- Dockerfile | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index c4586bb..7a05870 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,14 @@ FROM alpine:latest -RUN apk add --update --no-cache python2 py2-pip py2-gevent \ - py2-flask py2-requests py2-pygments py2-redis \ - py2-cffi py2-icu bash vim gawk sed WORKDIR /app COPY . /app -RUN apk add --update --no-cache --virtual build-deps python2-dev build-base git && pip install -r requirements.txt && sh share/scripts/get-sheets.sh && apk del build-deps +RUN apk add --update --no-cache python2 py2-pip py2-gevent \ + py2-flask py2-requests py2-pygments py2-redis \ + py2-cffi py2-icu bash vim gawk sed \ + && apk add --update --no-cache --virtual build-deps python2-dev \ + build-base git \ + && pip install -r requirements.txt \ + && sh share/scripts/get-sheets.sh \ + && apk del build-deps \ + && rm -rf /var/cache/apk/* ENTRYPOINT ["python2"] -CMD ["bin/srv.py"] \ No newline at end of file +CMD ["bin/srv.py"] From 5ac5ae5117a64d46fe902adc0d2cb448ffaa3b5c Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Mon, 30 Jul 2018 20:45:35 -0700 Subject: [PATCH 08/11] Add dockerignore --- .dockerignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..30a9ca2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.travis.yml +.git +.gitignore +docker-compose.yml +Dockerfile From 06af6b158779f07106fbdb488b3b9e6c07109e15 Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Tue, 31 Jul 2018 09:20:50 -0700 Subject: [PATCH 09/11] Changed docker-compose.yml version from 3.6 to 2 for compatibility --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 91a6f84..29ffb36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.6' +version: '2' services: app: build: From 81aa27f1631080e8ae77f888dea9925d019795d9 Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Tue, 31 Jul 2018 10:50:25 -0700 Subject: [PATCH 10/11] Update docker-compose.yml redis 3.2 -> 4 --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 29ffb36..589033c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,8 +8,8 @@ services: ports: - "8002:8002" redis: - image: redis:3.2-alpine + image: redis:4-alpine volumes: - redis_data:/data volumes: - redis_data: \ No newline at end of file + redis_data: From 3200925e2e313cea10227fa02fcdcdf8aac0bb9a Mon Sep 17 00:00:00 2001 From: Brandon Lopez Date: Tue, 31 Jul 2018 10:54:14 -0700 Subject: [PATCH 11/11] Update Dockerfile Little more Dockerfile cleanup --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a05870..95c26a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,11 +4,10 @@ COPY . /app RUN apk add --update --no-cache python2 py2-pip py2-gevent \ py2-flask py2-requests py2-pygments py2-redis \ py2-cffi py2-icu bash vim gawk sed \ - && apk add --update --no-cache --virtual build-deps python2-dev \ + && apk add --no-cache --virtual build-deps python2-dev \ build-base git \ && pip install -r requirements.txt \ && sh share/scripts/get-sheets.sh \ - && apk del build-deps \ - && rm -rf /var/cache/apk/* + && apk del build-deps ENTRYPOINT ["python2"] CMD ["bin/srv.py"]