Skip to content

Commit

Permalink
chore: add Docker + fly deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
leggetter committed Sep 5, 2024
1 parent ee808eb commit 91d9cd0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fly.toml
.git/
__pycache__/
.envrc
.venv/
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 3 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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"
22 changes: 22 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 91d9cd0

Please sign in to comment.