db initialization dockerized

This commit is contained in:
Gene Sokolov
2015-11-20 15:54:05 -08:00
parent 61f434765c
commit d3232dc147
5 changed files with 26 additions and 12 deletions

View File

@ -1,7 +1,7 @@
# Docker file builds an image with a utility which initializes rethinkdb cluster.
# It needs to be run only once per cluster. Use it as (assuming your running RethinkDB
# container is named 'rethinkdb'):
# $ docker run --link rethinkdb --env SNOWFLAKE_UID_KEY=base64+encoded+24+bytes= init-rethinkdb
# $ docker run --name=init-tinode-db --link rethinkdb --env SNOWFLAKE_UID_KEY=base64+encoded+24+bytes= init-rethinkdb
FROM golang

View File

@ -1,11 +1,17 @@
#!/bin/bash
# Ensure the old config is removed
rm -f /config
# Generate a new config from template and environment
while IFS='' read -r line || [[ -n $line ]] ; do
while [[ "$line" =~ (\$[A-Z_][A-Z_0-9]*) ]] ; do
LHS=${BASH_REMATCH[1]}
RHS="$(eval echo "\"$LHS\"")"
line=${line//$LHS/$RHS}
done
echo "$line" >> config
done < config.template
echo "$line" >> /config
done < /config.template
# Run the generator
/go/bin/tinode-db --reset --config=/config --data=/go/src/github.com/tinode/chat/tinode-db/data.json

View File

@ -1,11 +1,16 @@
#!/bin/bash
# Ensure the old config is removed
rm -f /config
# Generate a new config from template and environment
while IFS='' read -r line || [[ -n $line ]] ; do
while [[ "$line" =~ (\$[A-Z_][A-Z_0-9]*) ]] ; do
LHS=${BASH_REMATCH[1]}
RHS="$(eval echo "\"$LHS\"")"
line=${line//$LHS/$RHS}
done
echo "$line" >> config
done < config.template
echo "$line" >> /config
done < /config.template
/go/bin/server --config=/config --static_data=/go/src/github.com/tinode/chat/server/static

View File

@ -365,7 +365,7 @@ type MsgInvitation struct {
type MsgServerData struct {
Topic string `json:"topic"`
// UseId, could be empty if sent by system
// ID of the user who originated the message as {pub}, could be empty if sent by the system
From string `json:"from,omitempty"`
Timestamp time.Time `json:"ts"`
SeqId int `json:"seq"`

View File

@ -8,13 +8,16 @@ Parameters:
- `--config=FILENAME`: load configuration from FILENAME. Example config:
```js
{
"worker_id": 1,
"uid_key": "la6YsO+bNX/+XIkOqc5Svw==",
"params": {
"database": "tinode",
"addresses": "localhost:28015"
"db_adapter": "rethinkdb",
"adapter_config": {
"worker_id": 1,
"uid_key": "la6YsO+bNX/+XIkOqc5Svw==",
"params": {
"database": "tinode",
"addresses": "localhost:28015"
}
}
}
}
```
RethinkDB adapter uses [snowflake](http://github.com/tinode/snowflake/) to generate object IDs. The `worker_id` and `uid_key` parameters are used to initialize snowflake and only used when sample data is loaded.
- `worker_id` is the snowflake ID of the host running this utility, integer in the range 0 - 1023