From f055cb30020d58679dc658d26afc287943a1865a Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 12 Oct 2020 11:17:24 +0200 Subject: [PATCH] prepare for production --- Dockerfile | 2 +- code/config.lua | 13 ++++++------- code/handlers/splhandler.lua | 15 +++++++++++++++ code/handlers/stationhandler.lua | 6 +++--- code/nginx.conf | 4 ++++ docker-compose.yml | 10 +++++++++- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 389503c..55a7658 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,4 @@ RUN docker-luarocks-install busted WORKDIR /srv/lapis -CMD lapis server +CMD lapis server $ENVIRONMENT diff --git a/code/config.lua b/code/config.lua index e864256..dc80cbf 100644 --- a/code/config.lua +++ b/code/config.lua @@ -1,19 +1,18 @@ local config = require("lapis.config") -config("development", { +config({"development", "production"}, { + host = "tracks.intergalactic.fm", greeting = "dingen", postgres = { host = "postgres", user = "postgres", - password = "the_password", + -- password = "the_password", database = "postgres" } }) -config("test", { +config("production", { + greeting = "different greeting", postgres = { - host = "postgres", - user = "postgres", - password = "the_password", - database = "test" + password = os.getenv('POSTGRES_PASSWORD') } }) diff --git a/code/handlers/splhandler.lua b/code/handlers/splhandler.lua index 2ef63d7..0e1a899 100644 --- a/code/handlers/splhandler.lua +++ b/code/handlers/splhandler.lua @@ -8,6 +8,7 @@ function Splhandler(self) -- TODO: add auth-token + -- secret=STATION_SECRET_#& -- artist_name=%a& -- track_name=%t& -- release_name=%T @@ -30,10 +31,19 @@ function Splhandler(self) local station = models.Stations:find({ station = station_id }) if not station then print("unknown station: " .. station_id) + return else print("This is: " .. station["name"]) 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_name = self.params.artist_name -- mandatory @@ -52,6 +62,11 @@ function Splhandler(self) local airtime = self.params.time -- 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 local function Split(s, delimiter) local result = {} diff --git a/code/handlers/stationhandler.lua b/code/handlers/stationhandler.lua index 78516e8..c010e79 100644 --- a/code/handlers/stationhandler.lua +++ b/code/handlers/stationhandler.lua @@ -58,9 +58,9 @@ function Stationhandler(self) return { json = self.airtimes } end - for i, item in ipairs(self.airtimes) do - print(to_json(item)) - end + -- for i, item in ipairs(self.airtimes) do + -- print(to_json(item)) + -- end return { render = "station" } diff --git a/code/nginx.conf b/code/nginx.conf index 852ef70..3208438 100644 --- a/code/nginx.conf +++ b/code/nginx.conf @@ -3,6 +3,10 @@ error_log stderr notice; daemon off; pid logs/nginx.pid; +env POSTGRES_PASSWORD; +env STATION_SECRET_1; +env STATION_SECRET_2; +env STATION_SECRET_3; events { worker_connections 1024; diff --git a/docker-compose.yml b/docker-compose.yml index 7804f0d..125efaf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,12 @@ version: "3" services: previouslyonifm: + environment: + - ENVIRONMENT + - POSTGRES_PASSWORD + - STATION_SECRET_1 + - STATION_SECRET_2 + - STATION_SECRET_3 build: . volumes: - ./code:/srv/lapis @@ -10,4 +16,6 @@ services: postgres: image: postgres:12-alpine environment: - POSTGRES_PASSWORD: the_password + - POSTGRES_PASSWORD + volumes: + - /opt/trackdb:/var/lib/postgresql/data