~ihabunek/hub3-api

API for generating PDF417 2D barcodes according to HUB3 specification
Fix validation field lengths
Handle invalid base64 data
Disable tracing on Sentry

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~ihabunek/hub3-api
read/write
git@git.sr.ht:~ihabunek/hub3-api

You can also use your local clone with git send-email.

#HUB3 API

An API for creating 2D bar codes in HUB3 format.

https://hub3.bigfish.software/

#Deploy

Clone and setup the virtual env:

git clone https://git.sr.ht/~ihabunek/hub3-api
cd hub3-api
mkvirtualenv hub3-api
pip install -r requirements.txt
pip install -r requirements.prod.txt

/etc/systemd/system/hub3-api.service

[Unit]
Description=HUB3 API
Requires=hub3-api.socket
After=network.target

[Service]
Type=notify
User=ihabunek
Group=ihabunek
RuntimeDirectory=gunicorn
WorkingDirectory=/home/ihabunek/projects/hub3-api
ExecStart=/home/ihabunek/.virtualenvs/hub3-api/bin/gunicorn hub3:app
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
PrivateTmp=true

[Install]
WantedBy=multi-user.target
[Unit]
Description=Triglav daemon
After=network.target

[Service]
PIDFile=/run/triglav/pid
User=ihabunek
Group=ihabunek
WorkingDirectory=/home/ihabunek/projects/triglav
EnvironmentFile=/home/ihabunek/projects/triglav/systemd.env
ExecStart=/home/ihabunek/projects/triglav/prod/rel/triglav/bin/triglav start
ExecReload=/home/ihabunek/projects/triglav/prod/rel/triglav/bin/triglav restart
ExecStop=/home/ihabunek/projects/triglav/prod/rel/triglav/bin/triglav stop

[Install]
WantedBy=multi-user.target

/etc/systemd/system/hub3-api.socket

[Unit]
Description=HUB3 API

[Socket]
ListenStream=/run/hub3-api/socket

[Install]
WantedBy=sockets.target

/etc/nginx/sites-available/hub3-beta.bigfish.software

#Rougly based on:

#https://docs.gunicorn.org/en/stable/deploy.html

upstream hub3_beta_server {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response
    server unix:/run/hub3-api/socket fail_timeout=0;
}

server {
    listen 80;
    server_name hub3-beta.bigfish.software;
    return 301 https://hub3-beta.bigfish.software$request_uri;
}

server {
    listen 443 ssl;
    server_name hub3-beta.bigfish.software;

    ssl_certificate /etc/letsencrypt/live/bigfish.software/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/bigfish.software/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    access_log /var/log/nginx/hub3-beta.access.log;
    error_log /var/log/nginx/hub3-beta.error.log;

    # max post size should be ~1kb, set limit a bit larger
    client_max_body_size 10k;

    location /static/ {
        alias /home/ihabunek/projects/hub3-api/hub3/static/;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Prefix /;
        # proxy_redirect off;
        proxy_pass http://hub3_beta_server;
        add_header X-Clacks-Overhead "GNU Terry Pratchett";
    }
}

Enable service (only required once):

sudo systemctl enable hub3-api.service

Read logs:

journalctl -u hub3-api.service