Skip to content

Commit c1e479d

Browse files
authored
Refactor (#44)
* Add pyproject.toml * Add new checks * Add new observer with dispatcher * Move coingecko config out of module * Add CoinGecko prices and config args/vars * Implement crosschain checks * Run isort * Remove logging from checks * Add asyncio support to Datadog client * Remove empty file * Replace mypy with pyright Pyright has better integration with VS Code * Implement check protocol * Consolidate check protocol * Clean up * Add sample input files * Update prometheus-client * Expose prometheus metrics * Update CI workflow * Update README * Rename price feed online check This addresses the confusion around the slot values. * Improve event configuration Document env. variabels in README and bail out earlier if they are not passed. * Add type hints for Observer inputs * Add service tag to Datadog events
1 parent bfe3162 commit c1e479d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3152
-2404
lines changed

.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.flake8

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Python Poetry
2+
description: Sets up a Python environment with Poetry
3+
4+
inputs:
5+
python-version:
6+
required: false
7+
description: Python version
8+
default: "3.10"
9+
poetry-version:
10+
required: false
11+
description: Poetry version
12+
default: "1.2.2"
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- uses: actions/setup-python@v2
18+
with:
19+
python-version: ${{ inputs.python-version }}
20+
- uses: abatilo/[email protected]
21+
with:
22+
poetry-version: ${{ inputs.poetry-version }}
23+
- run: poetry install
24+
shell: sh

.github/workflows/ci.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
tags:
7+
- v*
8+
pull_request:
9+
branches:
10+
- "main"
11+
jobs:
12+
pre-commit:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: ./.github/actions/python-poetry
17+
- uses: pre-commit/[email protected]
18+
run-tests:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: ./.github/actions/python-poetry
23+
- run: poetry run pytest
24+
env:
25+
TEST_MODE: "1"
26+
build-and-push-ecr:
27+
runs-on: ubuntu-latest
28+
needs: [pre-commit, run-tests]
29+
permissions:
30+
id-token: write
31+
contents: read
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: aws-actions/configure-aws-credentials@8a84b07f2009032ade05a88a28750d733cc30db1
35+
with:
36+
role-to-assume: arn:aws:iam::192824654885:role/github-actions-ecr
37+
aws-region: eu-west-2
38+
- uses: docker/login-action@v2
39+
with:
40+
registry: public.ecr.aws
41+
env:
42+
AWS_REGION: us-east-1
43+
- run: docker context create builders
44+
- uses: docker/setup-buildx-action@v2
45+
with:
46+
version: latest
47+
endpoint: builders
48+
- uses: haya14busa/action-cond@v1
49+
id: image_tag
50+
with:
51+
cond: ${{ startsWith(github.ref, 'refs/tags/') }}
52+
if_true: ${{ github.ref_name }}
53+
if_false: ${{ github.sha }}
54+
- uses: docker/build-push-action@v2
55+
with:
56+
push: true
57+
tags: public.ecr.aws/pyth-network/observer:${{ steps.image_tag.outputs.value }}

.github/workflows/ci.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.github/workflows/docker-image.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.gitignore

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
.env
2-
ve
3-
venv
4-
pyth-client-py
5-
publishers.json
6-
**/__pycache__
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
74

85
.DS_Store
9-
.coverage
6+
.envrc
7+
.coverage

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: isort
5+
name: isort
6+
entry: poetry run isort --profile=black --check .
7+
language: system
8+
- id: black
9+
name: black
10+
entry: poetry run black --check .
11+
pass_filenames: false
12+
language: system
13+
- id: pyright
14+
name: pyright
15+
entry: poetry run pyright pyth_observer/ tests/
16+
pass_filenames: false
17+
language: system
18+
- id: pyflakes
19+
name: pyflakes
20+
entry: poetry run pyflakes pyth_observer/ tests/
21+
pass_filenames: false
22+
language: system

Dockerfile

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,95 @@
1-
# syntax=docker/dockerfile:1.2
2-
FROM python:3.8-slim-bullseye
1+
# Reference: https://bmaingret.github.io/blog/2021-11-15-Docker-and-Poetry#multi-stage-build
32

4-
ARG UID=10000
5-
ARG GID=10000
6-
ARG DIR=/data
3+
ARG APP_NAME=pyth-observer
4+
ARG APP_PACKAGE=pyth_observer
5+
ARG APP_PATH=/opt/$APP_NAME
6+
ARG PYTHON_VERSION=3.10.4
7+
ARG POETRY_VERSION=1.2.2
78

8-
WORKDIR ${DIR}
9-
RUN groupadd -o -g ${GID} -r app && adduser --system --home ${DIR} --ingroup app --uid ${UID} app
9+
#
10+
# Stage: base
11+
#
1012

11-
COPY --chown=app:app . ${DIR}
12-
RUN pip install --no-cache-dir -r requirements.txt
13-
USER app
13+
FROM python:$PYTHON_VERSION as base
1414

15-
ENTRYPOINT ["python3", "/data/observer.py"]
16-
CMD ["-l", "debug", "--network", "devnet"]
15+
ARG APP_NAME
16+
ARG APP_PATH
17+
ARG POETRY_VERSION
18+
19+
ENV \
20+
PYTHONDONTWRITEBYTECODE=1 \
21+
PYTHONUNBUFFERED=1 \
22+
PYTHONFAULTHANDLER=1
23+
ENV \
24+
POETRY_VERSION=$POETRY_VERSION \
25+
POETRY_HOME="/opt/poetry" \
26+
POETRY_VIRTUALENVS_IN_PROJECT=true \
27+
POETRY_NO_INTERACTION=1
28+
29+
# Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
30+
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python
31+
ENV PATH="$POETRY_HOME/bin:$PATH"
32+
33+
WORKDIR $APP_PATH
34+
COPY . .
35+
36+
#
37+
# Stage: development
38+
#
39+
40+
FROM base as development
41+
42+
ARG APP_NAME
43+
ARG APP_PATH
44+
45+
WORKDIR $APP_PATH
46+
RUN poetry install
47+
48+
ENV APP_NAME=$APP_NAME
49+
50+
ENTRYPOINT ["poetry", "run"]
51+
CMD ["$APP_NAME"]
52+
53+
#
54+
# Stage: build
55+
#
56+
57+
FROM base as build
58+
59+
ARG APP_NAME
60+
ARG APP_PATH
61+
62+
WORKDIR $APP_PATH
63+
RUN poetry build --format wheel
64+
RUN poetry export --format requirements.txt --output constraints.txt --without-hashes
65+
66+
#
67+
# Stage: production
68+
#
69+
70+
FROM python:$PYTHON_VERSION as production
71+
72+
ARG APP_NAME
73+
ARG APP_PATH
74+
75+
ENV \
76+
PYTHONDONTWRITEBYTECODE=1 \
77+
PYTHONUNBUFFERED=1 \
78+
PYTHONFAULTHANDLER=1
79+
80+
ENV \
81+
PIP_NO_CACHE_DIR=off \
82+
PIP_DISABLE_PIP_VERSION_CHECK=on \
83+
PIP_DEFAULT_TIMEOUT=100
84+
85+
# Get build artifact wheel and install it respecting dependency versions
86+
WORKDIR $APP_PATH
87+
COPY --from=build $APP_PATH/dist/*.whl ./
88+
COPY --from=build $APP_PATH/constraints.txt ./
89+
RUN pip install ./*.whl --requirement constraints.txt
90+
91+
COPY ./entrypoint.sh /entrypoint.sh
92+
RUN chmod +x /entrypoint.sh
93+
94+
ENTRYPOINT ["/entrypoint.sh"]
95+
CMD ["$APP_NAME"]

0 commit comments

Comments
 (0)