Skip to content

Commit

Permalink
fix: Fixing image not generated when redis is active
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Sep 9, 2022
1 parent 9d35578 commit 878f28b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
8 changes: 7 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
version: '2.1'

services:
site:
service:
image: vibioh/fibr
environment:
FIBR_AUTH_USERS: '${BASIC_USERS}'
FIBR_EXIF_DIRECT_ACCESS: 'true'
FIBR_THUMBNAIL_DIRECT_ACCESS: 'true'
FIBR_REDIS_ADDRESS: redis:6379
ports:
- '1080:1080/tcp'
volumes:
Expand All @@ -20,6 +21,11 @@ services:
restart: on-failure
read_only: true

redis:
image: redis
restart: on-failure
read_only: true

vith:
image: vibioh/vith
environment:
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github.com/ViBiOh/fibr
go 1.19

require (
github.com/ViBiOh/ChatPotte v0.2.9
github.com/ViBiOh/absto v1.0.3
github.com/ViBiOh/auth/v2 v2.14.6
github.com/ViBiOh/ChatPotte v0.2.11
github.com/ViBiOh/absto v1.0.4
github.com/ViBiOh/auth/v2 v2.14.7
github.com/ViBiOh/exas v0.5.0
github.com/ViBiOh/flags v1.2.0
github.com/ViBiOh/httputils/v4 v4.47.4
github.com/ViBiOh/httputils/v4 v4.47.6
github.com/ViBiOh/vith v0.5.0
github.com/golang/mock v1.6.0
github.com/prometheus/client_golang v1.13.0
Expand All @@ -32,10 +32,10 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.1.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.35 // indirect
github.com/minio/minio-go/v7 v7.0.36 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -50,8 +50,8 @@ require (
go.opentelemetry.io/otel/exporters/jaeger v1.9.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.9.0 // indirect
golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c // indirect
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
golang.org/x/net v0.0.0-20220907135653-1e95f45603a7 // indirect
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
34 changes: 17 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ViBiOh/ChatPotte v0.2.9 h1:RbCiNCAYg8udO+GO7Ap0YVfyXKolZ393P4BHE+cRvhc=
github.com/ViBiOh/ChatPotte v0.2.9/go.mod h1:SOJMFIJf5rsLWzVeaavZzVU2ml3XmrNDbTxNEIr31uE=
github.com/ViBiOh/absto v1.0.3 h1:guwVdRN7mIJM6XO65ABqDjz/7JiFMGJ7+VfmE/Ni3Zw=
github.com/ViBiOh/absto v1.0.3/go.mod h1:nu8N6LQnyxYhdnTAOtlpr4zca2tOcj5uUgI30oCF4vo=
github.com/ViBiOh/auth/v2 v2.14.6 h1:zDhOzwjurrUAsNElh4VXc5MnYKcENoAu25E5eQiw1j0=
github.com/ViBiOh/auth/v2 v2.14.6/go.mod h1:GcCYmx8SzH7LhnmeB9x3bGWRa5g4uAY4GszxNKwFJjE=
github.com/ViBiOh/ChatPotte v0.2.11 h1:zMJidUjpqUMhZCJpWsbm0Sagc+soEIC82dBqdpWFA3I=
github.com/ViBiOh/ChatPotte v0.2.11/go.mod h1:LbGXtNVr5OMaL8DGxmos56Pkm4gJY8Qg95dt0ilWIc8=
github.com/ViBiOh/absto v1.0.4 h1:j7GKLQzIyrCJUGU8Gvagse5wG5lLzJLNSSrMgVVDCnQ=
github.com/ViBiOh/absto v1.0.4/go.mod h1:+e6RyntSHivIJ3FwVL8jefGVvYkDBS5gZ5XvdqXRtT0=
github.com/ViBiOh/auth/v2 v2.14.7 h1:ljZEutGnEqA3xVXfXW7J1PuCX+4lgxRpqAo2IO6GnGM=
github.com/ViBiOh/auth/v2 v2.14.7/go.mod h1:W24m80U3TLWlMr0Jy72BZY0vfpvZhFnnzl16TlRmQig=
github.com/ViBiOh/exas v0.5.0 h1:ZL5v5rUOkkwo6PxhbOVe96L0RUre7SfStaVcqhE/IbU=
github.com/ViBiOh/exas v0.5.0/go.mod h1:sKRV/vz85Vj0caT+a3XWVFp0gyzXe36eZWL+XKge93E=
github.com/ViBiOh/flags v1.2.0 h1:DaujjNXzD29KxKyp4eZdn7c9+uBN5DokWgDAe7DcUmc=
github.com/ViBiOh/flags v1.2.0/go.mod h1:UyMB5zeD/aId7Xw3x7577ZNU298JmukzOcV8p/H2W1s=
github.com/ViBiOh/httputils/v4 v4.47.4 h1:W0e+aciohDP+qaJk7JDo1OtGn7Lf+W0DPgu9S5H+vSQ=
github.com/ViBiOh/httputils/v4 v4.47.4/go.mod h1:ghw8fNnYr+1450CNeTyaDreaMDC7plFutd54ttT3EMs=
github.com/ViBiOh/httputils/v4 v4.47.6 h1:T0no0RjRpvYv80dTfb9OnsKr0LXFu65p2bCqRfYKHgU=
github.com/ViBiOh/httputils/v4 v4.47.6/go.mod h1:qMX3opWLo3TBnjIOL4L/IOgObQf0gGsH0uF40sYydu8=
github.com/ViBiOh/vith v0.5.0 h1:BpmjwWxd4NGmUJF12XpFOngK32539Lw3mvbMOaeOmhE=
github.com/ViBiOh/vith v0.5.0/go.mod h1:Wf40eedOBEcxeLzGzGpuO+2G8qe5Ov1WIIBPXohyKco=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -169,7 +169,7 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
github.com/jackc/pgproto3/v2 v2.3.1 h1:nwj7qwf0S+Q7ISFfBndqeLwSwxs+4DPsbRFjECT1Y4Y=
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
github.com/jackc/pgtype v1.12.0 h1:Dlq8Qvcch7kiehm8wPGIW0W3KsCCHJnRacKW0UM8n5w=
github.com/jackc/pgx/v4 v4.17.1 h1:tASdE79tX9LOQu3MMvioWT6YaZkf58ZhmLHhV4sv5WM=
github.com/jackc/pgx/v4 v4.17.2 h1:0Ut0rpeKwvIVbMQ1KbMBU4h6wxehBI535LK6Flheh8E=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand All @@ -185,8 +185,8 @@ github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQan
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0=
github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/klauspost/cpuid/v2 v2.1.1 h1:t0wUqjowdm8ezddV5k0tLWVklVuvLJpoHeb4WBdydm0=
github.com/klauspost/cpuid/v2 v2.1.1/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
Expand All @@ -198,8 +198,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.35 h1:JuPPxWLdxQmNLSaS8AWZnO5HBadeI1xg6FGrEELQEVU=
github.com/minio/minio-go/v7 v7.0.35/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
github.com/minio/minio-go/v7 v7.0.36 h1:KPzAl8C6jcRFEUsGUHR6deRivvKATPNZThzi7D9y/sc=
github.com/minio/minio-go/v7 v7.0.36/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g=
github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -361,8 +361,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c h1:JVAXQ10yGGVbSyoer5VILysz6YKjdNT2bsvlayjqhes=
golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220907135653-1e95f45603a7 h1:1WGATo9HAhkWMbfyuVU0tEFP88OIkUvwaHFveQPvzCQ=
golang.org/x/net v0.0.0-20220907135653-1e95f45603a7/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -423,8 +423,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 h1:TyKJRhyo17yWxOMCTHKWrc5rddHORMlnZ/j57umaUd8=
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 h1:wM1k/lXfpc5HdkJJyW9GELpd8ERGdnh8sMGL6Gzq3Ho=
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
Expand Down
25 changes: 15 additions & 10 deletions pkg/exif/exif.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exif

import (
"context"
"errors"
"flag"
"fmt"
"net/http"
Expand All @@ -23,6 +24,8 @@ import (
"go.opentelemetry.io/otel/trace"
)

var errInvalidItemType = errors.New("invalid item type")

type App struct {
tracer trace.Tracer
storageApp absto.Storage
Expand Down Expand Up @@ -103,28 +106,30 @@ func New(config Config, storageApp absto.Storage, prometheusRegisterer prometheu

app.exifCacheApp = cache.New(redisClient, redisKey, func(ctx context.Context, item absto.Item) (exas.Exif, error) {
if item.IsDir {
return exas.Exif{}, cache.ErrIgnore
return exas.Exif{}, errInvalidItemType
}

value, err := app.loadExif(ctx, item)
if absto.IsNotExist(err) {
return value, cache.ErrIgnore
return app.loadExif(ctx, item)
}, func(item absto.Item, err error) {
if absto.IsNotExist(err) || errors.Is(err, errInvalidItemType) {
return
}

return value, err
logger.WithField("item", item.Pathname).Error("load exif: %s", item.Pathname, err)
}, cacheDuration, provider.MaxConcurrency, tracerApp.GetTracer("exif_cache"))

app.aggregateCacheApp = cache.New(redisClient, redisKey, func(ctx context.Context, item absto.Item) (provider.Aggregate, error) {
if !item.IsDir {
return provider.Aggregate{}, cache.ErrIgnore
return provider.Aggregate{}, errInvalidItemType
}

value, err := app.loadAggregate(ctx, item)
if absto.IsNotExist(err) {
return value, cache.ErrIgnore
return app.loadAggregate(ctx, item)
}, func(item absto.Item, err error) {
if absto.IsNotExist(err) || errors.Is(err, errInvalidItemType) {
return
}

return value, err
logger.WithField("item", item.Pathname).Error("load exif: %s", item.Pathname, err)
}, cacheDuration, provider.MaxConcurrency, tracerApp.GetTracer("ggregate_cache"))

return app, nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/thumbnail/thumbnail.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@ func New(config Config, storage absto.Storage, redisClient redis.App, prometheus
}

app.cacheApp = cache.New(redisClient, redisKey, func(ctx context.Context, pathname string) (absto.Item, error) {
value, err := app.storageApp.Info(ctx, pathname)
return app.storageApp.Info(ctx, pathname)
}, func(pathname string, err error) {
if absto.IsNotExist(err) {
return value, cache.ErrIgnore
return
}

return value, err
logger.WithField("item", pathname).Error("get info: %s", pathname, err)
}, redisCacheDuration, provider.MaxConcurrency, tracerApp.GetTracer("thumbnail_cache"))

return app, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/thumbnail/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestHasThumbnail(t *testing.T) {
storageMock := mocks.NewStorage(ctrl)

tc.instance.storageApp = storageMock
tc.instance.cacheApp = cache.New(nil, nil, storageMock.Info, 0, 0, nil)
tc.instance.cacheApp = cache.New(nil, nil, storageMock.Info, nil, 0, 0, nil)

if intention == "found" {
storageMock.EXPECT().Info(gomock.Any(), gomock.Any()).Return(absto.Item{}, nil)
Expand Down

0 comments on commit 878f28b

Please sign in to comment.