mirror of
https://github.com/chubin/cheat.sh.git
synced 2026-06-20 13:16:44 +02:00
Merge pull request #221 from abitrolly/fix-docker
Fix Dockerfile (#172, #156)
This commit is contained in:
+16
-10
@@ -1,13 +1,19 @@
|
||||
FROM alpine:latest
|
||||
FROM alpine:3.12
|
||||
# fetching cheat sheets
|
||||
## installing dependencies
|
||||
RUN apk add --update --no-cache git py3-six py3-pygments py3-yaml py3-gevent \
|
||||
libstdc++ py3-colorama py3-requests py3-icu py3-redis
|
||||
## building missing python packages
|
||||
RUN apk add --no-cache --virtual build-deps py3-pip g++ python3-dev \
|
||||
&& pip3 install --no-cache-dir rapidfuzz colored polyglot pycld2 \
|
||||
&& apk del build-deps
|
||||
## copying
|
||||
WORKDIR /app
|
||||
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 --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"]
|
||||
RUN mkdir -p /root/.cheat.sh/log/ \
|
||||
&& python3 lib/fetch.py fetch-all
|
||||
|
||||
# installing server dependencies
|
||||
RUN apk add --update --no-cache py3-jinja2 py3-flask bash gawk
|
||||
ENTRYPOINT ["python3"]
|
||||
CMD ["bin/srv.py"]
|
||||
|
||||
+11
-7
@@ -96,9 +96,9 @@ def log_query(ip_addr, found, topic, user_agent):
|
||||
"""
|
||||
Log processed query and some internal data
|
||||
"""
|
||||
log_entry = "%s %s %s %s" % (ip_addr, found, topic, user_agent)
|
||||
with open(CONFIG["path.log.queries"], 'a') as my_file:
|
||||
my_file.write(log_entry.encode('utf-8')+"\n")
|
||||
log_entry = "%s %s %s %s\n" % (ip_addr, found, topic, user_agent)
|
||||
with open(CONFIG["path.log.queries"], 'ab') as my_file:
|
||||
my_file.write(log_entry.encode('utf-8'))
|
||||
|
||||
def get_request_ip(req):
|
||||
"""
|
||||
@@ -274,9 +274,13 @@ def answer(topic=None):
|
||||
return result
|
||||
return Response(result, mimetype='text/plain')
|
||||
|
||||
|
||||
if '--debug' in sys.argv:
|
||||
app.debug = True
|
||||
if 'CHEATSH_PORT' in os.environ:
|
||||
SRV = WSGIServer((CONFIG['server.bind'], int(os.environ.get('CHEATSH_PORT'))), app) # log=None)
|
||||
SRV.serve_forever()
|
||||
PORT = int(os.environ.get('CHEATSH_PORT'))
|
||||
else:
|
||||
SRV = WSGIServer((CONFIG['server.bind'], CONFIG['server.port']), app) # log=None)
|
||||
SRV.serve_forever()
|
||||
PORT = CONFIG['server.port']
|
||||
SRV = WSGIServer((CONFIG['server.bind'], PORT), app) # log=None)
|
||||
print("Starting server on {}:{}".format(SRV.address[0], SRV.address[1]))
|
||||
SRV.serve_forever()
|
||||
|
||||
@@ -79,7 +79,7 @@ class GitRepositoryAdapter(RepositoryAdapter): #pylint: disable=abstract-meth
|
||||
if not local_repository_dir:
|
||||
return None
|
||||
|
||||
return ['git', 'clone', cls._repository_url, local_repository_dir]
|
||||
return ['git', 'clone', '--depth=1', cls._repository_url, local_repository_dir]
|
||||
|
||||
@classmethod
|
||||
def update_command(cls):
|
||||
|
||||
+5
-1
@@ -56,7 +56,11 @@ def fetch_all(skip_existing=True):
|
||||
|
||||
sys.stdout.write("Fetching %s..." % (adptr))
|
||||
sys.stdout.flush()
|
||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
try:
|
||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
except OSError:
|
||||
print("\nERROR: %s" % cmd)
|
||||
raise
|
||||
output = process.communicate()[0]
|
||||
if process.returncode != 0:
|
||||
sys.stdout.write("\nERROR:\n---\n" + output)
|
||||
|
||||
@@ -75,13 +75,16 @@ def _render_html(query, result, editable, repository_button, topics_list, reques
|
||||
"""
|
||||
Convert ANSI text `data` to HTML
|
||||
"""
|
||||
proc = Popen(
|
||||
["bash", CONFIG['path.internal.ansi2html'], "--palette=solarized", "--bg=dark"],
|
||||
stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||
cmd = ["bash", CONFIG['path.internal.ansi2html'], "--palette=solarized", "--bg=dark"]
|
||||
try:
|
||||
proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||
except FileNotFoundError:
|
||||
print("ERROR: %s" % cmd)
|
||||
raise
|
||||
data = data.encode('utf-8')
|
||||
stdout, stderr = proc.communicate(data)
|
||||
if proc.returncode != 0:
|
||||
error(stdout + stderr)
|
||||
error((stdout + stderr).decode('utf-8'))
|
||||
return stdout.decode('utf-8')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user