Skip to content

Commit 99ae5c4

Browse files
authored
Merge pull request #221 from abitrolly/fix-docker
Fix Dockerfile (#172, #156)
2 parents 38edd23 + fbe5414 commit 99ae5c4

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

Dockerfile

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
FROM alpine:latest
1+
FROM alpine:3.12
2+
# fetching cheat sheets
3+
## installing dependencies
4+
RUN apk add --update --no-cache git py3-six py3-pygments py3-yaml py3-gevent \
5+
libstdc++ py3-colorama py3-requests py3-icu py3-redis
6+
## building missing python packages
7+
RUN apk add --no-cache --virtual build-deps py3-pip g++ python3-dev \
8+
&& pip3 install --no-cache-dir rapidfuzz colored polyglot pycld2 \
9+
&& apk del build-deps
10+
## copying
211
WORKDIR /app
312
COPY . /app
4-
RUN apk add --update --no-cache python2 py2-pip py2-gevent \
5-
py2-flask py2-requests py2-pygments py2-redis \
6-
py2-cffi py2-icu bash vim gawk sed \
7-
&& apk add --no-cache --virtual build-deps python2-dev \
8-
build-base git \
9-
&& pip install -r requirements.txt \
10-
&& sh share/scripts/get-sheets.sh \
11-
&& apk del build-deps
12-
ENTRYPOINT ["python2"]
13+
RUN mkdir -p /root/.cheat.sh/log/ \
14+
&& python3 lib/fetch.py fetch-all
15+
16+
# installing server dependencies
17+
RUN apk add --update --no-cache py3-jinja2 py3-flask bash gawk
18+
ENTRYPOINT ["python3"]
1319
CMD ["bin/srv.py"]

bin/srv.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def log_query(ip_addr, found, topic, user_agent):
9696
"""
9797
Log processed query and some internal data
9898
"""
99-
log_entry = "%s %s %s %s" % (ip_addr, found, topic, user_agent)
100-
with open(CONFIG["path.log.queries"], 'a') as my_file:
101-
my_file.write(log_entry.encode('utf-8')+"\n")
99+
log_entry = "%s %s %s %s\n" % (ip_addr, found, topic, user_agent)
100+
with open(CONFIG["path.log.queries"], 'ab') as my_file:
101+
my_file.write(log_entry.encode('utf-8'))
102102

103103
def get_request_ip(req):
104104
"""
@@ -274,9 +274,13 @@ def answer(topic=None):
274274
return result
275275
return Response(result, mimetype='text/plain')
276276

277+
278+
if '--debug' in sys.argv:
279+
app.debug = True
277280
if 'CHEATSH_PORT' in os.environ:
278-
SRV = WSGIServer((CONFIG['server.bind'], int(os.environ.get('CHEATSH_PORT'))), app) # log=None)
279-
SRV.serve_forever()
281+
PORT = int(os.environ.get('CHEATSH_PORT'))
280282
else:
281-
SRV = WSGIServer((CONFIG['server.bind'], CONFIG['server.port']), app) # log=None)
282-
SRV.serve_forever()
283+
PORT = CONFIG['server.port']
284+
SRV = WSGIServer((CONFIG['server.bind'], PORT), app) # log=None)
285+
print("Starting server on {}:{}".format(SRV.address[0], SRV.address[1]))
286+
SRV.serve_forever()

lib/adapter/git_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def fetch_command(cls):
7979
if not local_repository_dir:
8080
return None
8181

82-
return ['git', 'clone', cls._repository_url, local_repository_dir]
82+
return ['git', 'clone', '--depth=1', cls._repository_url, local_repository_dir]
8383

8484
@classmethod
8585
def update_command(cls):

lib/fetch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def _fetch_locations(known_location):
5656

5757
sys.stdout.write("Fetching %s..." % (adptr))
5858
sys.stdout.flush()
59-
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
59+
try:
60+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
61+
except OSError:
62+
print("\nERROR: %s" % cmd)
63+
raise
6064
output = process.communicate()[0]
6165
if process.returncode != 0:
6266
sys.stdout.write("\nERROR:\n---\n" + output)

lib/frontend/html.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ def _html_wrapper(data):
7575
"""
7676
Convert ANSI text `data` to HTML
7777
"""
78-
proc = Popen(
79-
["bash", CONFIG['path.internal.ansi2html'], "--palette=solarized", "--bg=dark"],
80-
stdin=PIPE, stdout=PIPE, stderr=PIPE)
78+
cmd = ["bash", CONFIG['path.internal.ansi2html'], "--palette=solarized", "--bg=dark"]
79+
try:
80+
proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
81+
except FileNotFoundError:
82+
print("ERROR: %s" % cmd)
83+
raise
8184
data = data.encode('utf-8')
8285
stdout, stderr = proc.communicate(data)
8386
if proc.returncode != 0:
84-
error(stdout + stderr)
87+
error((stdout + stderr).decode('utf-8'))
8588
return stdout.decode('utf-8')
8689

8790

0 commit comments

Comments
 (0)