Commit ca5569fb authored by Alexandre Delanoë's avatar Alexandre Delanoë

[CONFIG] Start server and DB connexion with Ini file (added to the repo for tests).

parent 6fc8d8e9
{-# LANGUAGE NoImplicitPrelude #-}
module Main where module Main where
--import System.Environment (getArgs) import Gargantext.Prelude
import Data.Gargantext.Server (startGargantext) import Gargantext.Server (startGargantext)
import System.Environment (getArgs)
main :: IO () main :: IO ()
-- (iniFile:_) <- getArgs main = do
main = startGargantext -- port iniFile (iniFile:_) <- getArgs
startGargantext iniFile
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
-- --
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
-- --
-- hash: b9bfa189420281ceb8fe8d47b1d7800acdc1f9529c864156abcbfbfea5e06dc6 -- hash: 1afbb68941e4a0da5a3c812595ca12ed611c36aa9ab55736742c3f093dbf7f06
name: gargantext name: gargantext
version: 0.1.0.0 version: 0.1.0.0
...@@ -11,9 +11,9 @@ description: Please see README.md ...@@ -11,9 +11,9 @@ description: Please see README.md
homepage: https://gargantext.org homepage: https://gargantext.org
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Alexandre Delanoë author: Gargantext Team
maintainer: team@gargantext.org maintainer: team@gargantext.org
copyright: Copyright: (c) 2016, copyright: Copyright: (c) 2017,
2018 CNRS Alexandre Delanoë 2018 CNRS Alexandre Delanoë
category: Data category: Data
build-type: Simple build-type: Simple
...@@ -41,6 +41,7 @@ library ...@@ -41,6 +41,7 @@ library
, extra , extra
, filepath , filepath
, http-conduit , http-conduit
, ini
, lens , lens
, logging-effect , logging-effect
, opaleye , opaleye
...@@ -116,6 +117,22 @@ library ...@@ -116,6 +117,22 @@ library
default-language: Haskell2010 default-language: Haskell2010
ghc-options: -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Werror ghc-options: -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Werror
executable gargantext
main-is: Main.hs
hs-source-dirs:
app
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -O2
build-depends:
base
, extra
, gargantext
, ini
, text
, unordered-containers
other-modules:
Paths_gargantext
default-language: Haskell2010
test-suite garg-doctest test-suite garg-doctest
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
main-is: Main.hs main-is: Main.hs
......
[django]
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = %4{Vs(Pc!GU-]@OaAl0)(*4/yERwU<ct`ncV{1)O%32$6q
# Space-separated list of hosts
ALLOWED_HOSTS = localhost
# Time-zone, possible values here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TIME_ZONE = Europe/Paris
# PostgreSQL access
DB_HOST = 127.0.0.1
DB_PORT = 5432
DB_NAME = gargandb
DB_USER = gargantua
DB_PASS = C8kdcUrAQy66U
# Logs
LOG_FILE = /var/log/gargantext/backend/django.log
LOG_LEVEL = DEBUG
LOG_FORMATTER = verbose
# Pidfile of django backend test server
TESTSERVER_PIDFILE = /tmp/gargantext_testserver.pid
# Celery
CELERYD_PID_FILE = /tmp/celery.pid
CELERYD_LOG_FILE = /var/log/gargantext/backend/celery.log
CELERYD_LOG_LEVEL = DEBUG
[uwsgi]
# See: http://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html
# And: http://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html
# Tip from: https://serverfault.com/questions/411361/uwsgi-ini-configuration-for-python-apps
if-env = VIRTUAL_ENV
print = [uWSGI] launched from virtualenv %(_)
virtualenv = %(_)
endif =
# needed to run uwsgi when it was not installed with pipenv
plugins = python35
# needed to run uwsgi outside of pipenv shell, because of this virtualenv bug:
# https://github.com/kennethreitz/pipenv/issues/829
home = /home/alexandre/.local/share/virtualenvs/gargantext-ykNZD4Cw
# unix socket is better than TCP one, there is less overhead
socket = /tmp/gargantext.sock
chmod-socket = 664
# user running uwsgi MUST be a member of www-data group
chown-socket = %U:www-data
# wsgi django module
module = gargantext.backend.wsgi:application
# about master: http://uwsgi-docs.readthedocs.io/en/latest/Management.html?highlight=master#reloading-the-server
master = True
# can do: uwsgi --stop /tmp/gargantext.pid
pidfile = /tmp/gargantext.pid
# clear environment on exit
vacuum = True
max-requests = 5000
# background the process & log
daemonize = /var/log/gargantext/uwsgi/@(exec://date +%%Y-%%m-%%d).log
logfile-chmod = 644
# one log file per day
log-reopen = true
# touch /tmp/gargantext.reload to reload configuration (after git pull for instance)
touch-reload = /tmp/gargantext.reload
{-| {-|
Module : Data.Gargantext... Module : Gargantext.
Description : Short description Description :
Copyright : (c) CNRS, 2017 Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3 License : AGPL + CECILL v3
Maintainer : team@gargantext.org Maintainer : team@gargantext.org
Stability : experimental Stability : experimental
......
...@@ -3,10 +3,10 @@ version: '0.1.0.0' ...@@ -3,10 +3,10 @@ version: '0.1.0.0'
synopsis: Deep (Collaborative) Text mining project synopsis: Deep (Collaborative) Text mining project
description: Please see README.md description: Please see README.md
category: Data category: Data
author: Alexandre Delanoë author: Gargantext Team
maintainer: team@gargantext.org maintainer: team@gargantext.org
copyright: copyright:
- ! 'Copyright: (c) 2016' - ! 'Copyright: (c) 2017'
- 2018 CNRS Alexandre Delanoë - 2018 CNRS Alexandre Delanoë
license: BSD3 license: BSD3
homepage: https://gargantext.org homepage: https://gargantext.org
...@@ -73,6 +73,7 @@ library: ...@@ -73,6 +73,7 @@ library:
- duckling - duckling
- filepath - filepath
- http-conduit - http-conduit
- ini
- lens - lens
- logging-effect - logging-effect
- opaleye - opaleye
...@@ -108,6 +109,17 @@ library: ...@@ -108,6 +109,17 @@ library:
- zlib - zlib
- zip - zip
- path-io - path-io
executable:
main: Main.hs
source-dirs: app
ghc-options: -threaded -rtsopts -with-rtsopts=-N -O2
dependencies:
- gargantext
- ini
- base
- unordered-containers
tests: tests:
garg-test: garg-test:
main: Main.hs main: Main.hs
......
...@@ -15,8 +15,6 @@ import qualified Database.PostgreSQL.Simple as PGS ...@@ -15,8 +15,6 @@ import qualified Database.PostgreSQL.Simple as PGS
import Opaleye import Opaleye
import Gargantext.Database.Private (infoGargandb)
-- Functions only -- Functions only
import Data.List (find) import Data.List (find)
...@@ -66,7 +64,5 @@ findWith f t = find (\x -> f x == t) ...@@ -66,7 +64,5 @@ findWith f t = find (\x -> f x == t)
--userWithId t xs = userWith userUserId t xs --userWithId t xs = userWith userUserId t xs
-- | not optimized (get all ngrams without filters) -- | not optimized (get all ngrams without filters)
ngrams :: IO [Ngram] ngrams :: PGS.Connection -> IO [Ngram]
ngrams = do ngrams conn = runQuery conn queryNgramTable
conn <- PGS.connect infoGargandb
runQuery conn queryNgramTable
...@@ -16,7 +16,6 @@ import qualified Database.PostgreSQL.Simple as PGS ...@@ -16,7 +16,6 @@ import qualified Database.PostgreSQL.Simple as PGS
import Opaleye import Opaleye
import Gargantext.Database.Private (infoGargandb)
data NodeNgramPoly id node_id ngram_id weight data NodeNgramPoly id node_id ngram_id weight
= NodeNgram { nodeNgram_NodeNgramId :: id = NodeNgram { nodeNgram_NodeNgramId :: id
...@@ -56,7 +55,5 @@ instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where ...@@ -56,7 +55,5 @@ instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
-- | not optimized (get all ngrams without filters) -- | not optimized (get all ngrams without filters)
nodeNgrams :: IO [NodeNgram] nodeNgrams :: PGS.Connection -> IO [NodeNgram]
nodeNgrams = do nodeNgrams conn = runQuery conn queryNodeNgramTable
conn <- PGS.connect infoGargandb
runQuery conn queryNodeNgramTable
...@@ -15,8 +15,6 @@ import qualified Database.PostgreSQL.Simple as PGS ...@@ -15,8 +15,6 @@ import qualified Database.PostgreSQL.Simple as PGS
import Opaleye import Opaleye
import Gargantext.Database.Private (infoGargandb)
data NodeNgramNgramPoly node_id ngram1_id ngram2_id weight data NodeNgramNgramPoly node_id ngram1_id ngram2_id weight
= NodeNgramNgram { nodeNgramNgram_NodeNgramNgram_NodeId :: node_id = NodeNgramNgram { nodeNgramNgram_NodeNgramNgram_NodeId :: node_id
, nodeNgramNgram_NodeNgramNgram_Ngram1Id :: ngram1_id , nodeNgramNgram_NodeNgramNgram_Ngram1Id :: ngram1_id
...@@ -50,10 +48,8 @@ queryNodeNgramNgramTable = queryTable nodeNgramNgramTable ...@@ -50,10 +48,8 @@ queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
-- | not optimized (get all ngrams without filters) -- | not optimized (get all ngrams without filters)
nodeNgramNgrams :: IO [NodeNgramNgram] nodeNgramNgrams :: PGS.Connection -> IO [NodeNgramNgram]
nodeNgramNgrams = do nodeNgramNgrams conn = runQuery conn queryNodeNgramNgramTable
conn <- PGS.connect infoGargandb
runQuery conn queryNodeNgramNgramTable
instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
queryRunnerColumnDefault = fieldQueryRunnerColumn queryRunnerColumnDefault = fieldQueryRunnerColumn
......
...@@ -15,7 +15,6 @@ import qualified Database.PostgreSQL.Simple as PGS ...@@ -15,7 +15,6 @@ import qualified Database.PostgreSQL.Simple as PGS
import Opaleye import Opaleye
import Gargantext.Database.Private (infoGargandb)
data NodeNodePoly node1_id node2_id score data NodeNodePoly node1_id node2_id score
= NodeNode { nodeNode_node1_id :: node1_id = NodeNode { nodeNode_node1_id :: node1_id
...@@ -46,10 +45,8 @@ queryNodeNodeTable = queryTable nodeNodeTable ...@@ -46,10 +45,8 @@ queryNodeNodeTable = queryTable nodeNodeTable
-- | not optimized (get all ngrams without filters) -- | not optimized (get all ngrams without filters)
nodeNodes :: IO [NodeNode] nodeNodes :: PGS.Connection -> IO [NodeNode]
nodeNodes = do nodeNodes conn = runQuery conn queryNodeNodeTable
conn <- PGS.connect infoGargandb
runQuery conn queryNodeNodeTable
instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
queryRunnerColumnDefault = fieldQueryRunnerColumn queryRunnerColumnDefault = fieldQueryRunnerColumn
...@@ -16,7 +16,6 @@ import qualified Database.PostgreSQL.Simple as PGS ...@@ -16,7 +16,6 @@ import qualified Database.PostgreSQL.Simple as PGS
import Opaleye import Opaleye
import Gargantext.Database.Private (infoGargandb)
data NodeNodeNgramPoly node1_id node2_id ngram_id score data NodeNodeNgramPoly node1_id node2_id ngram_id score
= NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id = NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id
...@@ -51,10 +50,8 @@ queryNodeNodeNgramTable = queryTable nodeNodeNgramTable ...@@ -51,10 +50,8 @@ queryNodeNodeNgramTable = queryTable nodeNodeNgramTable
-- | not optimized (get all ngrams without filters) -- | not optimized (get all ngrams without filters)
nodeNodeNgrams :: IO [NodeNodeNgram] nodeNodeNgrams :: PGS.Connection -> IO [NodeNodeNgram]
nodeNodeNgrams = do nodeNodeNgrams conn = runQuery conn queryNodeNodeNgramTable
conn <- PGS.connect infoGargandb
runQuery conn queryNodeNodeNgramTable
instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
......
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
module Gargantext.Database.Private where module Gargantext.Database.Private where
import qualified Database.PostgreSQL.Simple as PGS import qualified Database.PostgreSQL.Simple as PGS
import Data.Monoid ((<>))
import Data.Either.Extra (Either(Left, Right))
import Gargantext.Prelude
import Data.Text (unpack, pack)
import Text.Read (read)
import Data.Ini (readIniFile, lookupValue)
import Data.Word (Word16)
import System.IO (FilePath)
-- TODO add a reader Monad here -- TODO add a reader Monad here
-- read this in the init file -- read this in the init file
infoGargandb :: PGS.ConnectInfo
infoGargandb = PGS.ConnectInfo { PGS.connectHost = "127.0.0.1" databaseParameters :: FilePath -> IO PGS.ConnectInfo
, PGS.connectPort = 5432 databaseParameters fp = do
, PGS.connectUser = "gargantua" ini <- readIniFile fp
, PGS.connectPassword = "C8kdcUrAQy66U" let ini'' = case ini of
, PGS.connectDatabase = "gargandb" } Left e -> panic (pack $ "No ini file error" <> show e)
Right ini' -> ini'
let val x = case (lookupValue (pack "django") (pack x) ini'') of
Left _ -> panic (pack $ "no" <> x)
Right p' -> unpack p'
pure $ PGS.ConnectInfo { PGS.connectHost = val "DB_HOST"
, PGS.connectPort = read (val "DB_PORT") :: Word16
, PGS.connectUser = val "DB_USER"
, PGS.connectPassword = val "DB_PASS"
, PGS.connectDatabase = val "DB_NAME" }
...@@ -22,7 +22,6 @@ import Control.Arrow (returnA) ...@@ -22,7 +22,6 @@ import Control.Arrow (returnA)
import qualified Database.PostgreSQL.Simple as PGS import qualified Database.PostgreSQL.Simple as PGS
import Opaleye import Opaleye
import Gargantext.Database.Private (infoGargandb)
-- Functions only -- Functions only
import Data.List (find) import Data.List (find)
...@@ -114,12 +113,8 @@ instance QueryRunnerColumnDefault PGTimestamptz (Maybe UTCTime) where ...@@ -114,12 +113,8 @@ instance QueryRunnerColumnDefault PGTimestamptz (Maybe UTCTime) where
queryRunnerColumnDefault = fieldQueryRunnerColumn queryRunnerColumnDefault = fieldQueryRunnerColumn
users :: IO [User] users :: PGS.Connection -> IO [User]
users = do users conn = runQuery conn queryUserTable
conn <- PGS.connect infoGargandb
runQuery conn queryUserTable
usersLight :: IO [UserLight] usersLight :: PGS.Connection -> IO [UserLight]
usersLight = do usersLight conn = map toUserLight <$> runQuery conn queryUserTable
conn <- PGS.connect infoGargandb
map toUserLight <$> runQuery conn queryUserTable
{-|
Module : Gargantext.Server
Description : Server API
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
...@@ -18,10 +30,11 @@ import Servant ...@@ -18,10 +30,11 @@ import Servant
import Servant.Multipart import Servant.Multipart
import Database.PostgreSQL.Simple (Connection, connect) import Database.PostgreSQL.Simple (Connection, connect)
import Opaleye import Opaleye
import System.IO (FilePath)
import Gargantext.Types.Main (Node, NodeId) import Gargantext.Types.Main (Node, NodeId)
import Gargantext.Database.Node (getNodesWithParentId, getNode) import Gargantext.Database.Node (getNodesWithParentId, getNode)
import Gargantext.Database.Private (infoGargandb) import Gargantext.Database.Private (databaseParameters)
-- | TODO, use MOCK feature of Servant to generate fake data (for tests) -- | TODO, use MOCK feature of Servant to generate fake data (for tests)
...@@ -44,13 +57,13 @@ server conn ...@@ -44,13 +57,13 @@ server conn
where where
echo s = pure s echo s = pure s
connectGargandb :: IO Connection startGargantext :: FilePath -> IO ()
connectGargandb = connect infoGargandb startGargantext file = do
startGargantext :: IO ()
startGargantext = do
print ("Starting server on port " ++ show port) print ("Starting server on port " ++ show port)
conn <- connectGargandb param <- databaseParameters file
conn <- connect param
run port $ app conn run port $ app conn
where where
port = 8008 port = 8008
...@@ -75,7 +88,6 @@ nodeAPI conn id ...@@ -75,7 +88,6 @@ nodeAPI conn id
where where
id' = pgInt4 id id' = pgInt4 id
-- | Upload files -- | Upload files
-- TODO Is it possible to adapt the function according to iValue input ? -- TODO Is it possible to adapt the function according to iValue input ?
upload :: MultipartData -> Handler String upload :: MultipartData -> Handler String
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment