From 34d7107652590a4be7a6d1dfece6d9453931cdfd Mon Sep 17 00:00:00 2001 From: Vincent Boutour Date: Sun, 10 Jan 2021 21:10:28 +0100 Subject: [PATCH] ci: Switching to amqp mailer --- cmd/ketchup/api.go | 5 ++++- go.mod | 2 +- go.sum | 9 +++------ infra/config.yaml | 12 ++++++------ pkg/scheduler/scheduler.go | 9 +++++---- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/cmd/ketchup/api.go b/cmd/ketchup/api.go index 1f85337b..40c1b761 100644 --- a/cmd/ketchup/api.go +++ b/cmd/ketchup/api.go @@ -78,11 +78,14 @@ func main() { repositoryServiceApp := repositoryService.New(repositoryStore.New(ketchupDb), github.New(githubConfig), helm.New()) ketchupServiceApp := ketchupService.New(ketchupStore.New(ketchupDb), repositoryServiceApp) - schedulerApp := scheduler.New(schedulerConfig, repositoryServiceApp, ketchupServiceApp, mailer.New(mailerConfig)) + mailerApp, err := mailer.New(mailerConfig) + logger.Fatal(err) + defer mailerApp.Close() publicRendererApp, err := renderer.New(rendererConfig, ketchup.FuncMap) logger.Fatal(err) + schedulerApp := scheduler.New(schedulerConfig, repositoryServiceApp, ketchupServiceApp, mailerApp) ketchupApp := ketchup.New(publicRendererApp, ketchupServiceApp, userServiceApp, repositoryServiceApp) publicHandler := publicRendererApp.Handler(ketchupApp.PublicTemplateFunc) diff --git a/go.mod b/go.mod index b31fad31..ae541a27 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/ViBiOh/auth/v2 v2.6.4 github.com/ViBiOh/httputils/v3 v3.36.4 - github.com/ViBiOh/mailer v1.10.0 + github.com/ViBiOh/mailer v1.11.1 github.com/lib/pq v1.9.0 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 3527ceab..612e9d3f 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/ViBiOh/httputils/v3 v3.35.1 h1:CJ3BcpYzxlI2MoxJbUwqzBXTe7BHXoAFkFDwCO github.com/ViBiOh/httputils/v3 v3.35.1/go.mod h1:l4sdVJfRu99dY7rNJfMinJHYb0pJZU9FEz7C83dX6gE= github.com/ViBiOh/httputils/v3 v3.36.4 h1:ddehKRmFWe0x7rjVAVEiG/E9hszEQEe4K7ssdMjht6Q= github.com/ViBiOh/httputils/v3 v3.36.4/go.mod h1:l4sdVJfRu99dY7rNJfMinJHYb0pJZU9FEz7C83dX6gE= -github.com/ViBiOh/mailer v1.10.0 h1:R4pcuP6v6ZZ7g960NoMBCwU6rthd6paDSdBUgFzu6d0= -github.com/ViBiOh/mailer v1.10.0/go.mod h1:IKDtPPmi2Wc87mfP4njtbdX0Zji3eNfhX1B/Lz5lXBY= +github.com/ViBiOh/mailer v1.11.1 h1:J1+c2tD8lx+aTNEu/orooee4rigfo1qvxu6MMeaCjqE= +github.com/ViBiOh/mailer v1.11.1/go.mod h1:D+VW012tqsf8RKLGDRMJ9BOWvzQYFSCg8amsh3ce1rk= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -272,6 +272,7 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3 github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= +github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271 h1:WhxRHzgeVGETMlmVfqhRn8RIeeNoPr2Czh33I4Zdccw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -283,8 +284,6 @@ github.com/tdewolff/minify/v2 v2.9.10 h1:p+ifTTl+JMFFLDYNAm7nxQ9XuCG10HTW00wlPAZ github.com/tdewolff/minify/v2 v2.9.10/go.mod h1:U1Nc+/YBSB0FPEarqcgkYH3Ep4DNyyIbOyl5P4eWMuo= github.com/tdewolff/parse/v2 v2.5.5 h1:b7ICJa4I/54JQGEGgTte8DiyJPKcC5g8V773QMzkeUM= github.com/tdewolff/parse/v2 v2.5.5/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho= -github.com/tdewolff/parse/v2 v2.5.7 h1:9JGh56thUIzOjJdMbAF98FJZ53/zxElrMTj37PojEhs= -github.com/tdewolff/parse/v2 v2.5.7/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho= github.com/tdewolff/test v1.0.6 h1:76mzYJQ83Op284kMT+63iCNCI7NEERsIN8dLM+RiKr4= github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -369,8 +368,6 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e h1:AyodaIpKjppX+cBfTASF2E1US3H2JFBj920Ot3rtDjs= golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201223074533-0d417f636930 h1:vRgIt+nup/B/BwIS0g2oC0haq0iqbV3ZA+u6+0TlNCo= -golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/infra/config.yaml b/infra/config.yaml index 3096e294..80778139 100644 --- a/infra/config.yaml +++ b/infra/config.yaml @@ -8,7 +8,7 @@ spec: chart: spec: chart: app - version: '0.0.42' + version: "0.0.42" sourceRef: kind: HelmRepository name: vibioh @@ -19,19 +19,19 @@ spec: image: repository: vibioh/ketchup:latest # {"$imagepolicy": "default:ketchup"} config: - KETCHUP_LOGGER_JSON: 'true' - KETCHUP_MAILER_URL: http://mailer + KETCHUP_LOGGER_JSON: "true" KETCHUP_DB_HOST: ketchup-db - KETCHUP_DB_PORT: '80' + KETCHUP_DB_PORT: "80" KETCHUP_DB_NAME: ketchup KETCHUP_DB_USER: ketchup secrets: KETCHUP_DB_PASS: AgDOK5Ph8WD8SbBi+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ouVnThrNNg6qz4uZywzWZa3M/G3MqSSRWWI0UAt48di9W1UNHfZEJQ6An+PpzYGyW1HRDRrZqD9zzuNp/ptfLYzmULM1RQ2EDJZbekZD8u5VbgMXE4t7qqrRJyZr2jMbaxE/dZAJaI1tRhUJt4+k1ww10C976hvh5bKa9YXvr4Iu1tkxmXHhFjBirwVIHNBT14PGkDs1cKX+LAX2GF2ao6 ingress: enabled: true hosts: - - ketchup.vibioh.fr + - ketchup.vibioh.fr --- apiVersion: helm.toolkit.fluxcd.io/v2beta1 kind: HelmRelease @@ -43,7 +43,7 @@ spec: chart: spec: chart: postgres - version: '0.0.15' + version: "0.0.15" sourceRef: kind: HelmRepository name: vibioh diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index f0986b24..98c4d4aa 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -17,6 +17,7 @@ import ( "github.com/ViBiOh/ketchup/pkg/service/ketchup" "github.com/ViBiOh/ketchup/pkg/service/repository" mailer "github.com/ViBiOh/mailer/pkg/client" + mailerModel "github.com/ViBiOh/mailer/pkg/model" ) var ( @@ -207,14 +208,14 @@ func (a app) sendNotification(ctx context.Context, ketchupToNotify map[model.Use "releases": releases, } - email := mailer.NewEmail().Template("ketchup").From("ketchup@vibioh.fr").As("Ketchup").To(user.Email).Data(payload) + mailRequest := mailerModel.NewMailRequest().Template("ketchup").From("ketchup@vibioh.fr").As("Ketchup").To(user.Email).Data(payload) if len(releases) > 1 { - email.WithSubject("Ketchup - New releases") + mailRequest.WithSubject("Ketchup - New releases") } else { - email.WithSubject("Ketchup - New release") + mailRequest.WithSubject("Ketchup - New release") } - if err := email.Send(ctx, a.mailerApp); err != nil { + if err := a.mailerApp.Send(ctx, *mailRequest); err != nil { return fmt.Errorf("unable to send email to %s: %s", user.Email, err) } }