diff --git a/jobs/user-projects/general/kylmc-stonks.hcl b/jobs/user-projects/general/kylmc-stonks.hcl new file mode 100644 index 0000000..862bdb3 --- /dev/null +++ b/jobs/user-projects/general/kylmc-stonks.hcl @@ -0,0 +1,221 @@ +job "kylmc-stonks" { + datacenters = ["aperture"] + type = "service" + + meta { + domain = "kylmc-stonks.rb.dcu.ie" + } + + group "stonks" { + network { + mode = "bridge" + port "http" {} + } + + update { + max_parallel = 1 + health_check = "checks" + min_healthy_time = "10s" + healthy_deadline = "5m" + } + + service { + name = "kylmc-stonks" + port = "http" + + check { + type = "http" + path = "/" + interval = "10s" + timeout = "2s" + } + + tags = [ + "traefik.enable=true", + "traefik.port=${NOMAD_PORT_http}", + "traefik.http.routers.kylmc-stonks.entrypoints=web,websecure", + "traefik.http.routers.kylmc-stonks.rule=Host(`${NOMAD_META_domain}`)", + "traefik.http.routers.kylmc-stonks.tls=true", + "traefik.http.routers.kylmc-stonks.tls.certresolver=rb", + ] + } + + task "app" { + driver = "docker" + + config { + image = "ghcr.io/kylemc32532/stock-portfolio-tracker:latest" + ports = ["http"] + force_pull = true + auth { + username = "${DOCKER_USER}" + password = "${DOCKER_PASS}" + } + } + + resources { + cpu = 300 + memory = 300 + } + + template { + destination = "local/.env" + env = true + data = < 0), + PRIMARY KEY (portfolio_uuid, currency) +); + +CREATE TABLE IF NOT EXISTS holdings ( + portfolio_uuid UUID NOT NULL REFERENCES portfolios(uuid) ON DELETE CASCADE, + symbol TEXT NOT NULL, + shares NUMERIC NOT NULL CHECK (shares > 0), + PRIMARY KEY (portfolio_uuid, symbol) +); + +CREATE TABLE IF NOT EXISTS price_history ( + symbol TEXT NOT NULL, + date DATE NOT NULL, + close NUMERIC NOT NULL, + PRIMARY KEY (symbol, date) +); + +CREATE TABLE IF NOT EXISTS watchlist ( + portfolio_uuid UUID NOT NULL REFERENCES portfolios(uuid) ON DELETE CASCADE, + symbol TEXT NOT NULL, + PRIMARY KEY (portfolio_uuid, symbol) +); + +CREATE TABLE IF NOT EXISTS fx_rates ( + base TEXT NOT NULL, + target TEXT NOT NULL, + rate NUMERIC NOT NULL, + fetched_at TIMESTAMPTZ NOT NULL, + PRIMARY KEY (base, target) +); +EOH + } + } + } +}