Fly API deployment

This commit is contained in:
Nemo 2022-05-25 20:48:26 +05:30
parent ce9e5ab4c7
commit c6e522f685
10 changed files with 129 additions and 5 deletions

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
*
!ISIN.db
!main.ts
!deps.ts

15
.github/workflows/api.yml vendored Normal file
View File

@ -0,0 +1,15 @@
name: API Deploy
on:
release:
types: [published]
push:
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: make db && flyctl deploy --remote-only

View File

@ -1,7 +1,6 @@
name: Update Data
on:
workflow_dispatch:
push:
schedule:
# 18:07 UTC every day
# 23:37 IST every day
@ -30,4 +29,4 @@ jobs:
pip install -r src/requirements.txt
make release "version=v${{ steps.update_data.outputs.version }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

5
.gitignore vendored
View File

@ -2,4 +2,7 @@ pup
release.md
pup.zip
IN*.csv
notes.md
notes.md
ISIN.db
ISIN.sqbpro
scratchpad.txt

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM denoland/deno:1.22.0
# The port that your application listens to.
EXPOSE 8080
WORKDIR /app
# Prefer not to run as root.
USER deno
# Cache the dependencies as a layer (the following two steps are re-run only when deps.ts is modified).
# Ideally cache deps.ts will download and compile _all_ external files used in main.ts.
COPY deps.ts .
RUN deno cache deps.ts
# These steps will be re-run upon each file change in your working directory:
ADD . .
CMD ["run", "--cached-only", "--allow-net", "--allow-read", "main.ts"]

View File

@ -33,5 +33,10 @@ old:
release-notes: old
python3 src/diff.py
release: release-notes
gh release create "$(version)" --notes-file notes.md ISIN.csv release.md
release: release-notes db
gh release create "$(version)" --notes-file notes.md ISIN.csv release.md ISIN.db
db:
cat ISIN.csv | tail -n +2 > /tmp/ISIN-no-headers.csv
rm -f ISIN.db
cat src/setup.sql | sqlite3 ISIN.db

8
deps.ts Normal file
View File

@ -0,0 +1,8 @@
import { DB } from "https://deno.land/x/sqlite/mod.ts";
import {
app,
get,
post,
redirect,
contentType,
} from "https://denopkg.com/syumai/dinatra@0.15.0/mod.ts";

39
fly.toml Normal file
View File

@ -0,0 +1,39 @@
app = "isin"
kill_signal = "SIGINT"
kill_timeout = 5
[env]
PORT = "8080"
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

27
main.ts Normal file
View File

@ -0,0 +1,27 @@
import { DB } from "https://deno.land/x/sqlite/mod.ts";
import {
app,
get,
post,
redirect,
contentType,
} from "https://denopkg.com/syumai/dinatra@0.15.0/mod.ts";
const db = new DB("ISIN.db", { mode: "read" });
app(
get("/api/:isin", ({ params }) => {
let query = `SELECT * from ISIN WHERE ISIN='${params.isin}'`
let res = db.query(query);
if (res.length == 1) {
let [isin,description,issuer,type,status] = res[0]
if (issuer == "null") {
issuer = null
}
return [200, contentType("json"), JSON.stringify({ isin,description,issuer,type,status })]
} else {
return[404, contentType("json"), "Invalid ISIN"]
}
})
);

5
src/setup.sql Normal file
View File

@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS "ISIN"("ISIN" TEXT, "Description" TEXT, "Issuer" TEXT, "Type" TEXT COLLATE NOCASE, "Status" TEXT COLLATE NOCASE);
CREATE UNIQUE INDEX isinidx on ISIN (ISIN);
CREATE INDEX statusidx on ISIN (Status);
CREATE INDEX typeidx on ISIN (Type);
.import /tmp/ISIN-no-headers.csv ISIN --csv