prepare for production

This commit is contained in:
dreamer 2020-10-12 11:17:24 +02:00
parent e6fa005b1a
commit f055cb3002
6 changed files with 38 additions and 12 deletions

View File

@ -4,4 +4,4 @@ RUN docker-luarocks-install busted
WORKDIR /srv/lapis WORKDIR /srv/lapis
CMD lapis server CMD lapis server $ENVIRONMENT

View File

@ -1,19 +1,18 @@
local config = require("lapis.config") local config = require("lapis.config")
config("development", { config({"development", "production"}, {
host = "tracks.intergalactic.fm",
greeting = "dingen", greeting = "dingen",
postgres = { postgres = {
host = "postgres", host = "postgres",
user = "postgres", user = "postgres",
password = "the_password", -- password = "the_password",
database = "postgres" database = "postgres"
} }
}) })
config("test", { config("production", {
greeting = "different greeting",
postgres = { postgres = {
host = "postgres", password = os.getenv('POSTGRES_PASSWORD')
user = "postgres",
password = "the_password",
database = "test"
} }
}) })

View File

@ -8,6 +8,7 @@ function Splhandler(self)
-- TODO: add auth-token -- TODO: add auth-token
-- secret=STATION_SECRET_#&
-- artist_name=%a& -- artist_name=%a&
-- track_name=%t& -- track_name=%t&
-- release_name=%T -- release_name=%T
@ -30,10 +31,19 @@ function Splhandler(self)
local station = models.Stations:find({ station = station_id }) local station = models.Stations:find({ station = station_id })
if not station then if not station then
print("unknown station: " .. station_id) print("unknown station: " .. station_id)
return
else else
print("This is: " .. station["name"]) print("This is: " .. station["name"])
end end
local station_secret = os.getenv('STATION_SECRET_'..station_id) or nil
local request_secret = self.params.secret
if station_secret then
if station_secret ~= request_secret then
return
end
end
local artist = nil local artist = nil
local artist_name = self.params.artist_name -- mandatory local artist_name = self.params.artist_name -- mandatory
@ -52,6 +62,11 @@ function Splhandler(self)
local airtime = self.params.time -- mandatory local airtime = self.params.time -- mandatory
local airdate = self.params.date -- mandatory local airdate = self.params.date -- mandatory
-- check mandatory fields
if not artist_name or track_name or airtime or airdate then
return
end
-- we have to split the `hr:min:sec` and `month/day/year` strings from SPL -- we have to split the `hr:min:sec` and `month/day/year` strings from SPL
local function Split(s, delimiter) local function Split(s, delimiter)
local result = {} local result = {}

View File

@ -58,9 +58,9 @@ function Stationhandler(self)
return { json = self.airtimes } return { json = self.airtimes }
end end
for i, item in ipairs(self.airtimes) do -- for i, item in ipairs(self.airtimes) do
print(to_json(item)) -- print(to_json(item))
end -- end
return { render = "station" } return { render = "station" }

View File

@ -3,6 +3,10 @@ error_log stderr notice;
daemon off; daemon off;
pid logs/nginx.pid; pid logs/nginx.pid;
env POSTGRES_PASSWORD;
env STATION_SECRET_1;
env STATION_SECRET_2;
env STATION_SECRET_3;
events { events {
worker_connections 1024; worker_connections 1024;

View File

@ -1,6 +1,12 @@
version: "3" version: "3"
services: services:
previouslyonifm: previouslyonifm:
environment:
- ENVIRONMENT
- POSTGRES_PASSWORD
- STATION_SECRET_1
- STATION_SECRET_2
- STATION_SECRET_3
build: . build: .
volumes: volumes:
- ./code:/srv/lapis - ./code:/srv/lapis
@ -10,4 +16,6 @@ services:
postgres: postgres:
image: postgres:12-alpine image: postgres:12-alpine
environment: environment:
POSTGRES_PASSWORD: the_password - POSTGRES_PASSWORD
volumes:
- /opt/trackdb:/var/lib/postgresql/data