# HG changeset patch # User drewp@bigasterisk.com # Date 1639377145 28800 # Node ID a4778c56cc03acf9802f69c3934c4ef946a5fa3c # Parent db403728559273f5a9bb29b2d3f7ccb8f92f569c update deps and k8s setup diff -r db4037285592 -r a4778c56cc03 Dockerfile --- a/Dockerfile Fri Aug 27 13:40:49 2021 -0700 +++ b/Dockerfile Sun Dec 12 22:32:25 2021 -0800 @@ -1,28 +1,21 @@ -FROM bang5:5000/base_x86 +FROM bang5:5000/base_basic WORKDIR /opt -RUN echo 2021-07-22 && apt-get update -RUN apt-get install -y python3.8 libpython3.8-dev python3-openssl python3-cffi-backend -RUN python3.8 -m pip install mercurial +RUN apt-get install -y python3 libpython3-dev python3-openssl python3-cffi-backend +RUN python3 -m pip install mercurial -RUN python3.8 -m pip install -U pip +RUN python3 -m pip install -U pip COPY requirements.txt ./ -RUN python3.8 -m pip install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt -RUN python3.8 -m pip install -U 'https://github.com/drewp/cyclone/archive/python3.zip?v3' -RUN python3.8 -m pip install -U cffi -RUN python3.8 -m pip install 'https://foss.heptapod.net/mercurial/hg-git/-/archive/branch/default/hg-git-branch-default.zip' +RUN python3 -m pip install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt +RUN python3 -m pip install -U 'https://github.com/drewp/cyclone/archive/python3.zip?v3' +RUN python3 -m pip install -U cffi +RUN python3 -m pip install 'https://foss.heptapod.net/mercurial/hg-git/-/archive/branch/default/hg-git-branch-default.zip' RUN groupadd --gid 1000 drewp && useradd --uid 501 --gid 1000 drewp COPY root-hgrc /root/.hgrc -COPY entrypoint.sh config.yaml hg_status.py index.html ./ +COPY config.yaml hg_status.py index.html ./ COPY dot-ssh/* /root/.ssh/ #USER drewp -ENV TZ=America/Los_Angeles -ENV LANG=en_US.UTF-8 - -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - - -CMD ["/bin/sh", "entrypoint.sh"] +CMD ["python3", "hg_status.py", "-v"] diff -r db4037285592 -r a4778c56cc03 entrypoint.sh --- a/entrypoint.sh Fri Aug 27 13:40:49 2021 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -#!/bin/sh - - -exec python3.8 hg_status.py -v \ No newline at end of file diff -r db4037285592 -r a4778c56cc03 hg_status.py --- a/hg_status.py Fri Aug 27 13:40:49 2021 -0700 +++ b/hg_status.py Sun Dec 12 22:32:25 2021 -0800 @@ -1,28 +1,28 @@ -from dataclasses import dataclass, field import datetime import json -import logging -from pathlib import Path import time import traceback +from dataclasses import dataclass, field +from pathlib import Path from typing import Dict, Optional, Tuple import cyclone.httpserver import cyclone.sse import cyclone.web +import docopt +import treq +import tzlocal from cycloneerr import PrettyErrorHandler from dateutil.parser import parse from dateutil.tz import tzlocal -import docopt +from prometheus_client.exposition import generate_latest +from prometheus_client.registry import REGISTRY from ruamel.yaml import YAML from standardservice.logsetup import log, verboseLogging -import treq from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks, returnValue -from twisted.internet.utils import getProcessOutput, _UnexpectedErrorOutput -import tzlocal +from twisted.internet.utils import _UnexpectedErrorOutput, getProcessOutput -local = tzlocal.get_localzone() githubOwner = 'drewp' @@ -76,7 +76,7 @@ rows = yield runHg(self.path, ['log', '--limit', '1']) commit = rows[0] sec = commit['date'][0] - t = datetime.datetime.fromtimestamp(sec, local) + t = datetime.datetime.fromtimestamp(sec, tzlocal()) self._save('log', {'email': commit['user'], 't': t.isoformat(), 'message': commit['desc']}) returnValue(self._get('log')) @@ -91,7 +91,7 @@ }) ret = yield treq.json_content(resp) commit = ret[0]['commit'] - t = parse(commit['committer']['date']).astimezone(local).isoformat() + t = parse(commit['committer']['date']).astimezone(tzlocal()).isoformat() self._save('github', {'email': commit['committer']['email'], 't': t, 'message': commit['message']}) returnValue(self._get('github')) @@ -109,7 +109,7 @@ ? then push then github setdefault to master -then github delete clearing +then github delete clearing ''' @inlineCallbacks @@ -161,6 +161,13 @@ reactor.callLater(0, self.runOne) +class Metrics(cyclone.web.RequestHandler): + + def get(self): + self.add_header('content-type', 'text/plain') + self.write(generate_latest(REGISTRY)) + + def main(): args = docopt.docopt(''' Usage: @@ -171,9 +178,9 @@ ''') verboseLogging(args['--verbose']) - import sys - sys.path.append('/usr/lib/python3/dist-packages') - import OpenSSL + # import sys + # sys.path.append('/usr/lib/python3/dist-packages') + # import OpenSSL yaml = YAML(typ='safe') config = yaml.load(open('config.yaml')) @@ -192,6 +199,7 @@ }), (r'/status/events', Statuses), (r'/githubSync', GithubSync), + (r'/metrics', Metrics), ] cyclone.web.Application.__init__( self, diff -r db4037285592 -r a4778c56cc03 requirements.txt --- a/requirements.txt Fri Aug 27 13:40:49 2021 -0700 +++ b/requirements.txt Sun Dec 12 22:32:25 2021 -0800 @@ -1,14 +1,14 @@ -cffi==1.14.6 +cffi==1.15.0 cyclone==1.3 docopt==0.6.2 -prometheus_client==0.11.0 -pyopenssl==20.0.1 +prometheus_client==0.12.0 +pyopenssl python-dateutil==2.8.2 requests==2.26.0 -ruamel.yaml==0.17.10 +ruamel.yaml==0.17.17 treq==21.5.0 -twisted[tls]==21.2.0 -tzlocal==2.1 +twisted[tls] +tzlocal==4.1 cycloneerr==0.4.0 standardservice==0.6.0