Skip to content

Commit

Permalink
build: fix docker compose failure in arm64 machines (#68)
Browse files Browse the repository at this point in the history
* build: fix docker compose failure in arm64 machines

* bump nsq/couchbase containers

* fix error checking by linter

* introduce a new makefile command for minimum services

---------

Co-authored-by: LordNoteworthy <[email protected]>
  • Loading branch information
JLL32 and ayoubfaouzi authored Jul 9, 2024
1 parent 6456f50 commit 73673e0
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 52 deletions.
8 changes: 8 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ run:
# Exit code when at least one issue was found.
# Default: 1
issues-exit-code: 0

# All available settings of specific linters.
linters-settings:
errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
# Such cases aren't reported by default.
# Default: false
check-blank: false
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ docker/release: ## Build and release in a docker container.
fi

compose/up: ## Start docker-compose (args: SVC: name of the service to exclude)
@echo "${GREEN} [*] =============== Docker Compose UP =============== ${RESET}"
@echo "${GREEN} [*] =============== Docker Compose Up =============== ${RESET}"
docker compose config --services | grep -v '${SVC}' | xargs docker compose up

compose/up/min: ## Start docker-compose (args: SVC: name of the service to exclude)
@echo "${YELLOW} [*] =============== Docker Compose Up Minimum =============== ${RESET}"
docker compose config --services | grep -v 'clamav\|sandbox\|meta\|orchestrator\|postprocessor\|aggregator\|pe\|ui' \
| xargs docker compose up

couchbase/start: ## Start Couchbase Server docker container.
$(eval COUCHBASE_CONTAINER_STATUS := $(shell docker container inspect -f '{{.State.Status}}' $(COUCHBASE_CONTAINER_NAME)))
ifeq ($(COUCHBASE_CONTAINER_STATUS),running)
Expand Down
8 changes: 4 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func run(logger log.Logger) error {
uni := ut.New(en, en)
trans, _ := uni.GetTranslator("en")
validate := validator.New()
en_translations.RegisterDefaultTranslations(validate, trans)
err = en_translations.RegisterDefaultTranslations(validate, trans)
if err != nil {
return err
}

// Create a password securer for auth.
sec := password.New(sha256.New())
Expand Down Expand Up @@ -132,9 +135,6 @@ func run(logger log.Logger) error {
if cfg.SMTP.Server != "" {
smtpMailer = mailer.New(cfg.SMTP.Server, cfg.SMTP.Port, cfg.SMTP.User,
cfg.SMTP.Password)
if err != nil {
logger.Errorf("failed to connect to smtp server: %v", err)
}
emailTemplates, err = tpl.New(*flagTplFiles)
if err != nil {
return err
Expand Down
56 changes: 32 additions & 24 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

services:
couchbase:
image: couchbase/server:7.2.0
image: couchbase/server:7.6.1
ports:
- "8091:8091"
- "8092:8092"
Expand All @@ -14,7 +14,8 @@ services:
- couchbase_data:/opt/couchbase/var

nsqlookupd:
image: nsqio/nsq:v1.2.1
platform: linux/amd64
image: nsqio/nsq:v1.3.0
command: >
/nsqlookupd --log-level=error
hostname: nsqlookupd
Expand All @@ -23,9 +24,11 @@ services:
- 4161:4161

nsqd:
image: nsqio/nsq:v1.2.1
platform: linux/amd64
image: nsqio/nsq:v1.3.0
command: >
/nsqd --lookupd-tcp-address=nsqlookupd:4160 --broadcast-address=${EXTERNAL_IP} --max-msg-size=1413820683 --log-level=error
/nsqd --lookupd-tcp-address=nsqlookupd:4160 --broadcast-address=${EXTERNAL_IP} --max-msg-size=1413820683
--log-level=error
hostname: nsqd
depends_on:
- nsqlookupd
Expand All @@ -34,7 +37,8 @@ services:
- 4151:4151

nsqadmin:
image: nsqio/nsq:v1.2.1
platform: linux/amd64
image: nsqio/nsq:v1.3.0
command: >
/nsqadmin --lookupd-http-address=nsqlookupd:4161 --log-level=error
hostname: nsqadmin
Expand All @@ -44,6 +48,7 @@ services:
- 4171:4171

minio:
platform: linux/amd64
image: minio/minio:latest
ports:
- "9000:9000"
Expand All @@ -56,6 +61,7 @@ services:
command: server /data --console-address ":9001"

ui:
platform: linux/amd64
image: saferwall/ui:latest
ports:
- "3000:3000"
Expand All @@ -64,69 +70,71 @@ services:
PUBLIC_AVATAR_API_URL: https://avatar.saferwall.com/{username}

orchestrator:
platform: linux/amd64
image: saferwall/orchestrator:latest
environment:
- SAFERWALL_DEPLOYMENT_KIND=dev
entrypoint: [ /saferwall/orchestrator-svc, -config, /saferwall/conf/ ]
entrypoint: [/saferwall/orchestrator-svc, -config, /saferwall/conf/]
volumes:
- /samples:/samples
- /saferwall:/saferwall/storage
- samples:/samples

aggregator:
platform: linux/amd64
image: saferwall/aggregator:latest
depends_on:
- couchbase
environment:
- SAFERWALL_DEPLOYMENT_KIND=dev
entrypoint: [ /saferwall/aggregator-svc, -config, /saferwall/conf/ ]
entrypoint: [/saferwall/aggregator-svc, -config, /saferwall/conf/]
restart: always

postprocessor:
platform: linux/amd64
image: saferwall/postprocessor:latest
environment:
- SAFERWALL_DEPLOYMENT_KIND=dev
entrypoint:
[
/saferwall/postprocessor-svc,
-config,
/saferwall/conf/
]
entrypoint: [/saferwall/postprocessor-svc, -config, /saferwall/conf/]
volumes:
- /samples:/samples
- samples:/samples
restart: always

pe:
platform: linux/amd64
image: saferwall/pe:latest
environment:
- SAFERWALL_DEPLOYMENT_KIND=dev
entrypoint: [ /saferwall/pe-svc, -config, /saferwall/conf/ ]
entrypoint: [/saferwall/pe-svc, -config, /saferwall/conf/]
volumes:
- /samples:/samples
- samples:/samples

meta:
platform: linux/amd64
image: saferwall/gometa:latest
environment:
- SAFERWALL_DEPLOYMENT_KIND=dev
entrypoint: [ /saferwall/meta-svc, -config, /saferwall/conf/ ]
entrypoint: [/saferwall/meta-svc, -config, /saferwall/conf/]
volumes:
- /samples:/samples
- samples:/samples

clamav:
platform: linux/amd64
image: saferwall/goclamav:latest
environment:
- SAFERWALL_DEPLOYMENT_KIND=dev
entrypoint: [ /saferwall/clamav-svc, -config, /saferwall/conf/ ]
entrypoint: [/saferwall/clamav-svc, -config, /saferwall/conf/]
volumes:
- /samples:/samples
- samples:/samples

sandbox:
platform: linux/amd64
image: saferwall/sandbox:latest
environment:
- SAFERWALL_DEPLOYMENT_KIND=dev
entrypoint: [ /saferwall/sandbox-svc, -config, /saferwall/conf/ ]
entrypoint: [/saferwall/sandbox-svc, -config, /saferwall/conf/]
volumes:
- /samples:/samples
- samples:/samples

volumes:
samples: null
minio_data: null
couchbase_data: null
4 changes: 2 additions & 2 deletions internal/behavior/repostitory.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r repository) Get(ctx context.Context, id string, fields []string) (

behaviors := res.([]interface{})
b, _ := json.Marshal(behaviors[0])
json.Unmarshal(b, &behavior)
_ = json.Unmarshal(b, &behavior)
}

return behavior, err
Expand Down Expand Up @@ -118,7 +118,7 @@ func (r repository) Query(ctx context.Context, offset, limit int) (
for _, u := range res.([]interface{}) {
behavior := entity.Behavior{}
b, _ := json.Marshal(u)
json.Unmarshal(b, &behavior)
_ = json.Unmarshal(b, &behavior)
behaviors = append(behaviors, behavior)
}
return behaviors, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/comment/service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Saferwall. All rights reserved.
// Copyright 2018 Saferwall. All rights reserved.
// Use of this source code is governed by Apache v2 license
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -173,7 +173,7 @@ func (s service) Delete(ctx context.Context, id string) (Comment, error) {
}

// delete corresponsing activity.
if s.actSvc.DeleteWith(ctx, "comment", com.Username, id); err != nil {
if err = s.actSvc.DeleteWith(ctx, "comment", com.Username, id); err != nil {
return Comment{}, err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/file/repository.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Saferwall. All rights reserved.
// Copyright 2018 Saferwall. All rights reserved.
// Use of this source code is governed by Apache v2 license
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -150,7 +150,7 @@ func (r repository) Query(ctx context.Context, offset, limit int, fields []strin
for _, u := range res.([]interface{}) {
file := entity.File{}
b, _ := json.Marshal(u)
json.Unmarshal(b, &file)
_ = json.Unmarshal(b, &file)
files = append(files, file)
}
return files, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/file/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (s service) Unlike(ctx context.Context, sha256 string) error {
}

// delete corresponding activity.
if s.actSvc.DeleteWith(ctx, "like", user.ID(),
if err = s.actSvc.DeleteWith(ctx, "like", user.ID(),
sha256); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func BuildHandler(logger log.Logger, db *dbcontext.DB, sec password.Service,

// Register a custom fields validator.
validate := validator.New()
validate.RegisterValidation("username_or_email", validateUsernameOrEmail)
_ = validate.RegisterValidation("username_or_email", validateUsernameOrEmail)
e.Validator = &CustomValidator{validator: validate}

// Register a custom binder.
Expand Down
6 changes: 3 additions & 3 deletions internal/template/template.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Saferwall. All rights reserved.
// Copyright 2018 Saferwall. All rights reserved.
// Use of this source code is governed by Apache v2 license
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -99,6 +99,6 @@ func (er EmailRequest) Execute(templateData interface{}, wr io.Writer) error {
if err := er.tpl.Execute(buf, templateData); err != nil {
return err
}
wr.Write(buf.Bytes())
return nil
_, err := wr.Write(buf.Bytes())
return err
}
12 changes: 5 additions & 7 deletions internal/user/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,11 @@ func (r resource) email(c echo.Context) error {

err := r.service.UpdateEmail(ctx, req)
if err != nil {
if err != nil {
switch err {
case errWrongPassword:
return errors.Forbidden("")
default:
return err
}
switch err {
case errWrongPassword:
return errors.Forbidden("")
default:
return err
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/user/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r repository) GetByEmail(ctx context.Context, email string) (

user := entity.User{}
b, _ := json.Marshal(res.([]interface{})[0])
json.Unmarshal(b, &user)
_ = json.Unmarshal(b, &user)
return user, nil
}

Expand All @@ -182,7 +182,7 @@ func (r repository) Query(ctx context.Context, offset, limit int) (
for _, u := range res.([]interface{}) {
user := entity.User{}
b, _ := json.Marshal(u)
json.Unmarshal(b, &user)
_ = json.Unmarshal(b, &user)
user.Email = ""
user.Password = ""
users = append(users, user)
Expand Down
6 changes: 3 additions & 3 deletions internal/user/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (s service) UnFollow(ctx context.Context, id string) error {
curUser.FollowingCount -= 1

// delete corresponding activity.
if s.actSvc.DeleteWith(ctx, "follow", curUser.Username,
if err = s.actSvc.DeleteWith(ctx, "follow", curUser.Username,
targetUser.Username); err != nil {
return err
}
Expand All @@ -456,10 +456,10 @@ func (s service) UnFollow(ctx context.Context, id string) error {
targetUser.FollowersCount -= 1
}

if s.repo.Update(ctx, curUser.User); err != nil {
if err = s.repo.Update(ctx, curUser.User); err != nil {
return err
}
if s.repo.Update(ctx, targetUser.User); err != nil {
if err = s.repo.Update(ctx, targetUser.User); err != nil {
return err
}

Expand Down

0 comments on commit 73673e0

Please sign in to comment.