Use env for config instead of flags
parent
f897b74878
commit
140433f720
|
@ -3,7 +3,7 @@ FROM golang:1.11-rc-alpine as build
|
||||||
RUN apk add --no-cache git=2.18.1-r0
|
RUN apk add --no-cache git=2.18.1-r0
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY go.mod go.sum *.go ./
|
COPY go.mod go.sum .env *.go ./
|
||||||
RUN go get -d -v ./...
|
RUN go get -d -v ./...
|
||||||
RUN CGO_ENABLED=0 go build -ldflags "-s -w"
|
RUN CGO_ENABLED=0 go build -ldflags "-s -w"
|
||||||
RUN mkdir -p /tmp/badger
|
RUN mkdir -p /tmp/badger
|
||||||
|
@ -12,5 +12,6 @@ FROM scratch
|
||||||
|
|
||||||
COPY --from=build /src/store /store
|
COPY --from=build /src/store /store
|
||||||
COPY --from=build /tmp/badger /tmp/badger
|
COPY --from=build /tmp/badger /tmp/badger
|
||||||
|
COPY --from=build /src/.env /.env
|
||||||
|
|
||||||
ENTRYPOINT ["/store"]
|
ENTRYPOINT ["/store"]
|
||||||
|
|
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
Single Badger store to serve bite, transcription and any others. Is kinda bite-centric, so required values revolve around a Bite. Transacts through NATS.
|
Single Badger store to serve bite, transcription and any others. Is kinda bite-centric, so required values revolve around a Bite. Transacts through NATS.
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
Supply environment variables by either exporting them or editing ```.env```.
|
||||||
|
|
||||||
|
| ENV | Description | Default |
|
||||||
|
| ---- | ----------- | ------- |
|
||||||
|
| DBPATH | Path to store badger files in. Please make sure it exists. | /tmp/badger |
|
||||||
|
| NATS | Host and port of nats | nats://localhost:4222 |
|
||||||
|
|
||||||
## Key format
|
## Key format
|
||||||
|
|
||||||
Takes in three variables: ```type```, ```key``` and ```start```. Type is the type of data to be inserted, e.g. ```bite```, ```bite_user``` or ```transcription```. Key could be some secret passphrase declaring you the Raj of British India for all I know. Start is the Epoch timestamp of the start of the Bite.
|
Takes in three variables: ```type```, ```key``` and ```start```. Type is the type of data to be inserted, e.g. ```bite```, ```bite_user``` or ```transcription```. Key could be some secret passphrase declaring you the Raj of British India for all I know. Start is the Epoch timestamp of the start of the Bite.
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -5,6 +5,7 @@ require (
|
||||||
github.com/dgraph-io/badger v1.5.4
|
github.com/dgraph-io/badger v1.5.4
|
||||||
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f // indirect
|
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f // indirect
|
||||||
github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157
|
github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157
|
||||||
|
github.com/joho/godotenv v1.3.0
|
||||||
github.com/nats-io/gnatsd v1.4.1 // indirect
|
github.com/nats-io/gnatsd v1.4.1 // indirect
|
||||||
github.com/nats-io/go-nats v1.7.0
|
github.com/nats-io/go-nats v1.7.0
|
||||||
github.com/nats-io/nkeys v0.0.2 // indirect
|
github.com/nats-io/nkeys v0.0.2 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -6,10 +6,10 @@ github.com/dgraph-io/badger v1.5.4 h1:gVTrpUTbbr/T24uvoCaqY2KSHfNLVGm0w+hbee2HMe
|
||||||
github.com/dgraph-io/badger v1.5.4/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
|
github.com/dgraph-io/badger v1.5.4/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
|
||||||
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f h1:dDxpBYafY/GYpcl+LS4Bn3ziLPuEdGRkRjYAbSlWxSA=
|
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f h1:dDxpBYafY/GYpcl+LS4Bn3ziLPuEdGRkRjYAbSlWxSA=
|
||||||
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157 h1:SdQMHsZ18/XZCHuwt3IF+dvHgYTO2XMWZjv3XBKQqAI=
|
github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157 h1:SdQMHsZ18/XZCHuwt3IF+dvHgYTO2XMWZjv3XBKQqAI=
|
||||||
github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
|
github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
|
||||||
|
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||||
|
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||||
github.com/nats-io/gnatsd v1.4.1 h1:RconcfDeWpKCD6QIIwiVFcvForlXpWeJP7i5/lDLy44=
|
github.com/nats-io/gnatsd v1.4.1 h1:RconcfDeWpKCD6QIIwiVFcvForlXpWeJP7i5/lDLy44=
|
||||||
github.com/nats-io/gnatsd v1.4.1/go.mod h1:nqco77VO78hLCJpIcVfygDP2rPGfsEHkGTUk94uh5DQ=
|
github.com/nats-io/gnatsd v1.4.1/go.mod h1:nqco77VO78hLCJpIcVfygDP2rPGfsEHkGTUk94uh5DQ=
|
||||||
github.com/nats-io/go-nats v1.7.0 h1:oQOfHcLr8hb43QG8yeVyY2jtarIaTjOv41CGdF3tTvQ=
|
github.com/nats-io/go-nats v1.7.0 h1:oQOfHcLr8hb43QG8yeVyY2jtarIaTjOv41CGdF3tTvQ=
|
||||||
|
|
15
main.go
15
main.go
|
@ -2,10 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
"github.com/dgraph-io/badger"
|
"github.com/dgraph-io/badger"
|
||||||
"github.com/nats-io/go-nats"
|
"github.com/nats-io/go-nats"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
@ -18,17 +19,19 @@ var db *badger.DB
|
||||||
var nc *nats.Conn
|
var nc *nats.Conn
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Parse flags
|
// Load .env
|
||||||
flag.StringVar(&dbPath, "dbpath", "/tmp/badger", "path to store data")
|
err := godotenv.Load()
|
||||||
flag.StringVar(&natsHost, "nats", "nats://localhost:4222", "host and port of NATS")
|
if err != nil {
|
||||||
flag.Parse()
|
log.Fatal("Error loading .env file")
|
||||||
|
}
|
||||||
|
dbPath = os.Getenv("DBPATH")
|
||||||
|
natsHost = os.Getenv("NATS")
|
||||||
|
|
||||||
// Open badger
|
// Open badger
|
||||||
log.Printf("starting badger at %s", dbPath)
|
log.Printf("starting badger at %s", dbPath)
|
||||||
opts := badger.DefaultOptions
|
opts := badger.DefaultOptions
|
||||||
opts.Dir = dbPath
|
opts.Dir = dbPath
|
||||||
opts.ValueDir = dbPath
|
opts.ValueDir = dbPath
|
||||||
var err error
|
|
||||||
db, err = badger.Open(opts)
|
db, err = badger.Open(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue