diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..ccae1311 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +/vendor +/.git +/dist diff --git a/Dockerfile b/Dockerfile index b2cd6da1..06abe7ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,15 +6,21 @@ RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh WORKDIR $GOPATH/src/github.com/vibrato/TechTestApp +COPY Gopkg.toml Gopkg.lock $GOPATH/src/github.com/vibrato/TechTestApp/ + +RUN dep ensure -vendor-only -v + COPY . . -RUN ./build.sh \ - && cp -r ./dist /TechTestApp +RUN go build -o /TechTestApp FROM alpine:latest WORKDIR /TechTestApp -COPY --from=build /TechTestApp . +COPY assets ./assets +COPY conf.toml ./conf.toml + +COPY --from=build /TechTestApp TechTestApp -ENTRYPOINT [ "./TechTestApp" ] \ No newline at end of file +ENTRYPOINT [ "./TechTestApp" ] diff --git a/Gopkg.lock b/Gopkg.lock index 3731e818..2133a3bf 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,10 +2,10 @@ [[projects]] - name = "github.com/BurntSushi/toml" + name = "github.com/fsnotify/fsnotify" packages = ["."] - revision = "b26d9c308763d68093482582cea63d69be07a0f0" - version = "v0.3.0" + revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" + version = "v1.4.7" [[projects]] name = "github.com/gorilla/context" @@ -19,6 +19,23 @@ revision = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf" version = "v1.6.2" +[[projects]] + branch = "master" + name = "github.com/hashicorp/hcl" + packages = [ + ".", + "hcl/ast", + "hcl/parser", + "hcl/printer", + "hcl/scanner", + "hcl/strconv", + "hcl/token", + "json/parser", + "json/scanner", + "json/token" + ] + revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168" + [[projects]] name = "github.com/inconshreveable/mousetrap" packages = ["."] @@ -34,34 +51,91 @@ ] revision = "d34b9ff171c21ad295489235aec8b6626023cd04" +[[projects]] + name = "github.com/magiconair/properties" + packages = ["."] + revision = "c2353362d570a7bfa228149c62842019201cfb71" + version = "v1.8.0" + +[[projects]] + branch = "master" + name = "github.com/mitchellh/mapstructure" + packages = ["."] + revision = "f15292f7a699fcc1a38a80977f80a046874ba8ac" + +[[projects]] + name = "github.com/pelletier/go-toml" + packages = ["."] + revision = "c01d1270ff3e442a8a57cddc1c92dc1138598194" + version = "v1.2.0" + +[[projects]] + name = "github.com/spf13/afero" + packages = [ + ".", + "mem" + ] + revision = "787d034dfe70e44075ccc060d346146ef53270ad" + version = "v1.1.1" + +[[projects]] + name = "github.com/spf13/cast" + packages = ["."] + revision = "8965335b8c7107321228e3e3702cab9832751bac" + version = "v1.2.0" + [[projects]] name = "github.com/spf13/cobra" packages = ["."] revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385" version = "v0.0.3" +[[projects]] + branch = "master" + name = "github.com/spf13/jwalterweatherman" + packages = ["."] + revision = "7c0cea34c8ece3fbeb2b27ab9b59511d360fb394" + [[projects]] name = "github.com/spf13/pflag" packages = ["."] revision = "583c0c0531f06d5278b7d917446061adc344b5cd" version = "v1.0.1" +[[projects]] + name = "github.com/spf13/viper" + packages = ["."] + revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736" + version = "v1.0.2" + [[projects]] branch = "master" - name = "github.com/vibrato/TechTestApp" + name = "golang.org/x/sys" + packages = ["unix"] + revision = "e072cadbbdc8dd3d3ffa82b8b4b9304c261d9311" + +[[projects]] + name = "golang.org/x/text" packages = [ - "cmd", - "config", - "daemon", - "db", - "model", - "ui" + "internal/gen", + "internal/triegen", + "internal/ucd", + "transform", + "unicode/cldr", + "unicode/norm" ] - revision = "93f52082fefa8d378199308b092fafa38d605a8a" + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" + +[[projects]] + name = "gopkg.in/yaml.v2" + packages = ["."] + revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" + version = "v2.2.1" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "c9641a21c878ca87f7866f8a876e2925dcc1f3c47a985f150ec147f83da2f7fa" + inputs-digest = "a6206f1fd59a3738fe306f830af481f6ced7083739e46c13d75951cecd4fab51" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 66aa4e85..1cf6b797 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,7 +1,3 @@ -[[constraint]] - name = "github.com/BurntSushi/toml" - version = "0.3.0" - [[constraint]] name = "github.com/gorilla/mux" version = "1.6.2" diff --git a/cmd/root.go b/cmd/root.go index a2eb95ca..f725b447 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -71,7 +71,7 @@ func init() { // initConfig reads in config file and ENV variables if set. func initConfig() { - conf, err := config.LoadConfig("conf.toml") + conf, err := config.LoadConfig() if err != nil { fmt.Print(err) diff --git a/config/config.go b/config/config.go index 657c5f68..bce247bc 100644 --- a/config/config.go +++ b/config/config.go @@ -21,9 +21,7 @@ package config import ( - "io/ioutil" - - "github.com/BurntSushi/toml" + "github.com/spf13/viper" ) // internalConfig wraps the config values as the toml library was @@ -38,25 +36,40 @@ type Config struct { ListenPort string } -// LoadConfig loads the configuration from file, -// and falls back to default calues if file -// could not be be loaded -func LoadConfig(path string) (Config, error) { - var conf = Config{} +func LoadConfig() (*Config, error) { + var conf = &Config{} - bytes, err := ioutil.ReadFile(path) + v := viper.New() - if err != nil { - return conf, err - } + v.SetConfigName("conf") + v.SetConfigType("toml") + v.AddConfigPath(".") - tomlcontent := string(bytes) + v.SetEnvPrefix("VTT") + v.AutomaticEnv() - _, err = toml.Decode(tomlcontent, &conf) + v.SetDefault("DbUser", "postgres") + v.SetDefault("DbPassword", "postgres") + v.SetDefault("DbName", "postgres") + v.SetDefault("DbPort", "postgres") + v.SetDefault("DbHost", "localhost") + + v.SetDefault("ListenHost", "127.0.0.1") + v.SetDefault("ListenPort", "3000") + + err := v.ReadInConfig() // Find and read the config file if err != nil { - return conf, err + return nil, err } + conf.DbUser = v.GetString("DbUser") + conf.DbPassword = v.GetString("DbPassword") + conf.DbName = v.GetString("DbName") + conf.DbHost = v.GetString("DbHost") + conf.DbPort = v.GetString("DbPort") + conf.ListenHost = v.GetString("ListenHost") + conf.ListenPort = v.GetString("ListenPort") + return conf, nil }