mirror of
https://github.com/snoyberg/keter.git
synced 2024-12-13 19:28:17 +03:00
support remote-server sytax in keter.yaml file, update README
This commit is contained in:
parent
2dd22abdf8
commit
95503ad1f4
@ -50,7 +50,11 @@ instance Default Settings where
|
|||||||
"';\nCREATE DATABASE " <> fromText dbiName <>
|
"';\nCREATE DATABASE " <> fromText dbiName <>
|
||||||
" OWNER " <> fromText dbiUser <>
|
" OWNER " <> fromText dbiUser <>
|
||||||
";"
|
";"
|
||||||
_ <- readProcess "sudo" ["-u", "postgres", "psql"] $ TL.unpack sql
|
cmd = [ "-u", "postgres", "psql"
|
||||||
|
, "-h", (T.unpack $ dbServer dbiServer)
|
||||||
|
, "-p", (show $ dbPort dbiServer)
|
||||||
|
, "-U", "postgres"]
|
||||||
|
_ <- readProcess "sudo" cmd $ TL.unpack sql
|
||||||
return ()
|
return ()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +74,8 @@ data DBServerInfo = DBServerInfo
|
|||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
randomDBI :: DBServerInfo -> R.StdGen -> (DBInfo, R.StdGen)
|
randomDBI :: DBServerInfo -> R.StdGen -> (DBInfo, R.StdGen)
|
||||||
randomDBI dbsi r =
|
randomDBI dbsi =
|
||||||
S.runState (DBInfo <$> rt <*> rt <*> rt <*> (pure dbsi)) r
|
S.runState (DBInfo <$> rt <*> rt <*> rt <*> (pure dbsi))
|
||||||
where
|
where
|
||||||
rt = T.pack <$> replicateM 10 (S.state $ R.randomR ('a', 'z'))
|
rt = T.pack <$> replicateM 10 (S.state $ R.randomR ('a', 'z'))
|
||||||
|
|
||||||
@ -127,21 +131,19 @@ load Settings{..} fp = do
|
|||||||
return Plugin
|
return Plugin
|
||||||
{ pluginGetEnv = \appname o ->
|
{ pluginGetEnv = \appname o ->
|
||||||
case HMap.lookup "postgres" o of
|
case HMap.lookup "postgres" o of
|
||||||
Just (Array x) -> do
|
Just (Array v) -> do
|
||||||
let Object o' = V.head x
|
let dbServer = fromMaybe def . parseMaybe parseJSON $ V.head v
|
||||||
dbServer = fromMaybe def . parseMaybe parseJSON $ V.head x
|
doenv chan appname dbServer
|
||||||
x <- newEmptyMVar
|
|
||||||
writeChan chan $ GetConfig appname dbServer $ putMVar x
|
|
||||||
edbi <- takeMVar x
|
|
||||||
edbiToEnv edbi
|
|
||||||
Just (Bool True) -> do
|
Just (Bool True) -> do
|
||||||
x <- newEmptyMVar
|
doenv chan appname def
|
||||||
writeChan chan $ GetConfig appname def $ putMVar x
|
|
||||||
edbi <- takeMVar x
|
|
||||||
edbiToEnv edbi
|
|
||||||
_ -> return []
|
_ -> return []
|
||||||
}
|
}
|
||||||
|
where doenv chan appname dbs = do
|
||||||
|
x <- newEmptyMVar
|
||||||
|
writeChan chan $ GetConfig appname dbs $ putMVar x
|
||||||
|
edbi <- takeMVar x
|
||||||
|
edbiToEnv edbi
|
||||||
|
|
||||||
tmpfp = fp <.> "tmp"
|
tmpfp = fp <.> "tmp"
|
||||||
|
|
||||||
loop chan = do
|
loop chan = do
|
||||||
|
16
README.md
Normal file → Executable file
16
README.md
Normal file → Executable file
@ -179,8 +179,22 @@ plugins:
|
|||||||
postgres: true
|
postgres: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Keter can be configured to connect to a remote postgres server using the following syntax:
|
||||||
|
```yaml
|
||||||
|
plugins:
|
||||||
|
postgres:
|
||||||
|
- server: remoteServerNameOrIP
|
||||||
|
port: 1234
|
||||||
|
```
|
||||||
|
|
||||||
|
Different webapps can be configured to use different servers using the above syntax.
|
||||||
|
Keter will connect to the remote servers using the `postgres` account. This setup
|
||||||
|
assumes the remote server's `pg_hba.conf` file has been configured to allow connections
|
||||||
|
from the keter-server IP using the `trust` method.
|
||||||
|
|
||||||
(Note: The `plugins` configuration option was added in v1.0 of the
|
(Note: The `plugins` configuration option was added in v1.0 of the
|
||||||
keter configuration syntax. If you are using v0.4 then use `postgres: true`.)
|
keter configuration syntax. If you are using v0.4 then use `postgres: true`.
|
||||||
|
The remote-postgres server syntax was added in v1.4.2.)
|
||||||
|
|
||||||
* Modify your application to get its database connection settings from the following environment variables:
|
* Modify your application to get its database connection settings from the following environment variables:
|
||||||
* `PGHOST`
|
* `PGHOST`
|
||||||
|
Loading…
Reference in New Issue
Block a user