diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4a1c39c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +fly.toml +.git/ +__pycache__/ +.envrc +.venv/ diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 0000000..b0c246e --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -0,0 +1,18 @@ +# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ + +name: Fly Deploy +on: + push: + branches: + - main +jobs: + deploy: + name: Deploy app + runs-on: ubuntu-latest + concurrency: deploy-group # optional: ensure only one action runs at a time + steps: + - uses: actions/checkout@v4 + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5191502 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.11 AS builder + +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 +WORKDIR /app + +RUN pip install poetry +RUN poetry config virtualenvs.in-project true +COPY pyproject.toml poetry.lock ./ +RUN poetry install +FROM python:3.11-slim +WORKDIR /app +COPY --from=builder /app/.venv .venv/ +COPY . . +CMD ["/app/.venv/bin/flask", "run", "--host=0.0.0.0", "--port=8080"] diff --git a/app.py b/app.py index b3960a0..1106715 100644 --- a/app.py +++ b/app.py @@ -119,7 +119,7 @@ def process(): @app.route("/webhooks", methods=["POST"]) def webhook(): payload = request.json - # print(payload) + app.logger.debug("Payload recieved %s", payload) client = get_mongo_client() @@ -131,7 +131,8 @@ def webhook(): update={"$set": {"status": "PROCESSED", "replicate_response": payload}}, ) - if result.modified_count == 0: + if result.matched_count == 0: + app.logger.error("No document found for id %s", payload["id"]) return jsonify({"error": "No document found"}), 500 return "OK" diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..6cca3b8 --- /dev/null +++ b/fly.toml @@ -0,0 +1,22 @@ +# fly.toml app configuration file generated for iatt on 2024-09-05T10:17:51+01:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'iatt' +primary_region = 'yul' + +[build] + +[http_service] + internal_port = 8080 + force_https = true + auto_stop_machines = 'stop' + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1