From 1e5f913c704f2fb3c912dfcfaf73aece6293089a Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 21 Aug 2024 17:54:09 -0300 Subject: [PATCH] Portado tapas --- busqueda/funko.cr | 2 +- deploy.sh | 5 ++++- historico/funko.cr | 2 +- tapas/{handler.py => funko.py} | 16 ++++++++++++---- tapas/funko.yml | 18 ++++++++++++++++++ tapas/requirements.txt | 1 + tapas/run.sh | 2 ++ tapas/{__init__.py => static/index.html} | 0 8 files changed, 39 insertions(+), 7 deletions(-) rename tapas/{handler.py => funko.py} (77%) create mode 100644 tapas/funko.yml create mode 100644 tapas/run.sh rename tapas/{__init__.py => static/index.html} (100%) diff --git a/busqueda/funko.cr b/busqueda/funko.cr index 09ce719..a251f99 100644 --- a/busqueda/funko.cr +++ b/busqueda/funko.cr @@ -12,7 +12,7 @@ DBURL = "postgres://#{USER}:#{PASS}@#{DBHOST}:5432/nombres" puts "Connnecting to #{DBURL}" # Create a connection pool to the database -pg = ConnectionPool.new(capacity: 5, timeout: 1.seconds) do +pg = ConnectionPool.new(capacity: 25, timeout: 1.seconds) do PG.connect(DBURL) end diff --git a/deploy.sh b/deploy.sh index 5becf45..c97a2ba 100755 --- a/deploy.sh +++ b/deploy.sh @@ -24,5 +24,8 @@ echo "192.168.0.98" | faaso secret -a busqueda dbhost faaso build historico faaso scale historico 0 faaso scale historico 1 - rsync -rav nombres.ralsina.me/* ralsina@pinky:/data/websites/nombres.ralsina.me/ + +faaso build tapas +faaso scale tapas 0 +faaso scale tapas 1 diff --git a/historico/funko.cr b/historico/funko.cr index 42dfb9e..8274636 100644 --- a/historico/funko.cr +++ b/historico/funko.cr @@ -12,7 +12,7 @@ DBURL = "postgres://#{USER}:#{PASS}@#{DBHOST}:5432/nombres" puts "Connnecting to #{DBURL}" # Create a connection pool to the database -pg = ConnectionPool.new(capacity: 5, timeout: 1.seconds) do +pg = ConnectionPool.new(capacity: 25, timeout: 1.seconds) do PG.connect(DBURL) end diff --git a/tapas/handler.py b/tapas/funko.py similarity index 77% rename from tapas/handler.py rename to tapas/funko.py index d02cbdf..652db3a 100644 --- a/tapas/handler.py +++ b/tapas/funko.py @@ -1,10 +1,12 @@ -from json import loads +from flask import Flask, request from tapita import Cover from io import BytesIO import base64 +app = Flask("tapas") -def handle(req): +@app.route('/', methods=['POST']) +def handle(): """handle a request to the function Args: req (str): request body @@ -15,10 +17,10 @@ def handle(req): "author": "bat", } """ - if not req: + if not request: return "Foo", 200, {"Content-Type": "text/plain"} try: - args = loads(req) + args = request.json except Exception: return "Bad Request", 400 @@ -31,3 +33,9 @@ def handle(req): 200, {"Content-Type": "text/html"}, ) + +@app.route('/ping') +def ping(): + return "OK" + + diff --git a/tapas/funko.yml b/tapas/funko.yml new file mode 100644 index 0000000..f4ccd2f --- /dev/null +++ b/tapas/funko.yml @@ -0,0 +1,18 @@ +name: tapas +runtime: flask +options: + ship_packages: + - jpeg + - zlib + - freetype + devel_packages: + - zlib-dev + - jpeg-dev + - freetype-dev + healthcheck_options: "--interval=1m --timeout=2s --start-period=2s --retries=3" + healthcheck_command: "curl --fail http://localhost:3000/ping || exit 1" + copy_from_build: + - "static static" + - "venv venv" + - "run.sh ." + - "funko.py ." diff --git a/tapas/requirements.txt b/tapas/requirements.txt index 4f493d1..74a4286 100644 --- a/tapas/requirements.txt +++ b/tapas/requirements.txt @@ -1 +1,2 @@ +flask tapita diff --git a/tapas/run.sh b/tapas/run.sh new file mode 100644 index 0000000..892c9f9 --- /dev/null +++ b/tapas/run.sh @@ -0,0 +1,2 @@ +#!/bin/sh +uwsgi --plugins http,python -H venv --http 0.0.0.0:3000 --master -p 1 -w funko:app diff --git a/tapas/__init__.py b/tapas/static/index.html similarity index 100% rename from tapas/__init__.py rename to tapas/static/index.html