diff --git a/Dockerfile b/Dockerfile index 48af422..47dda34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,5 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o prev FROM alpine:latest WORKDIR / COPY --from=builder /app/previewer . +RUN mkdir -p /assets/cache CMD ["/previewer"] \ No newline at end of file diff --git a/Makefile b/Makefile index 0e7373d..1215fad 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,5 @@ -docker-build: - sudo docker build -t previewer . - -build: - go build -o bin ./cmd/main.go +lint: install-lint-deps + golangci-lint run ./previewer/... ./internal/... unit-test: go test -race ./internal/... @@ -10,8 +7,15 @@ unit-test: integration-test: go test -v ./cmd/... -lint: install-lint-deps - golangci-lint run ./previewer/... ./internal/... +build: + go build -o bin ./cmd/main.go + + +docker-build: + sudo docker build -t previewer . + +docker-run: + sudo docker run -p 8080:8080 previewer install-lint-deps: rm -rf $(shell go env GOPATH)/bin/golangci-lint diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 3d840c6..0449608 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -32,7 +32,11 @@ type Item struct { func NewCache(capacity int, path string) Cache { if _, err := ioutil.ReadDir(path); err != nil { - log.Fatalf("cache directory %s not exists: %s", path, err.Error()) + log.Printf("cache directory %s not exists. Try to create.\n", path) + err = os.MkdirAll(path, 0777) + if err != nil { + log.Fatalf("can't create cache directory %s: %s", path, err.Error()) + } } return &lruCache{ capacity: capacity, diff --git a/internal/config/config.go b/internal/config/config.go index b5791e1..406c893 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -49,7 +49,7 @@ func (c *Config) SetDefault() { c.Cache = struct { Capacity int StoragePath string - }{Capacity: 20, StoragePath: "../assets/cache"} + }{Capacity: 20, StoragePath: "./assets/cache"} c.Query = struct{ Timeout int }{Timeout: 15} c.Log = struct { File string diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 7211994..3efd699 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -38,7 +38,7 @@ func New(conf Config) (Interface, error) { c := amitralog.Configuration{ EnableConsole: !conf.MuteStdout, - ConsoleLevel: amitralog.Fatal, + ConsoleLevel: amitralog.Debug, ConsoleJSONFormat: false, EnableFile: true, FileLevel: strings.ToLower(conf.Level),