From 8781854b620b1fb63dc649661d5c9d4ad3e00124 Mon Sep 17 00:00:00 2001 From: AKP Date: Tue, 5 Apr 2022 20:50:54 +0100 Subject: Prepare for deploy Signed-off-by: AKP --- Dockerfile | 13 ++++++++++++ Makefile | 4 ++-- walrss/internal/http/http.go | 2 ++ walrss/internal/http/testEmail.go | 30 ++++++++++++++++++++++++++++ walrss/internal/http/views/main.qtpl.html | 2 +- walrss/internal/http/views/main.qtpl.html.go | 4 ++++ walrss/internal/http/views/page.qtpl.html | 4 +--- walrss/internal/http/views/page.qtpl.html.go | 15 ++++---------- walrss/internal/urls/urls.go | 2 ++ 9 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 Dockerfile create mode 100644 walrss/internal/http/testEmail.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2072089 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1-alpine as builder + +RUN mkdir /build +ADD . /build/ +WORKDIR /build +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static" -s -w' -o main github.com/codemicro/walrss/walrss + +FROM alpine +COPY --from=builder /build/main / +WORKDIR /run + +ENV WALRSS_DIR /run +CMD ["../main"] \ No newline at end of file diff --git a/Makefile b/Makefile index 948bf1e..fad7acf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: prebuild fmt -build: templates writeVersionNumber +build: templates mkdir -p bin go build -o bin/walrss github.com/codemicro/walrss/walrss @@ -12,4 +12,4 @@ fmt: go fmt github.com/codemicro/walrss/... templates: - qtc -skipLineComments -ext qtpl.html -dir walrss/internal/http/views \ No newline at end of file + qtc -skipLineComments -ext qtpl.html -dir walrss/internal/http/views diff --git a/walrss/internal/http/http.go b/walrss/internal/http/http.go index 67be3c2..72a8634 100644 --- a/walrss/internal/http/http.go +++ b/walrss/internal/http/http.go @@ -89,6 +89,8 @@ func (s *Server) registerHandlers() { s.app.Get(urls.NewFeedItem, s.newFeedItem) s.app.Post(urls.NewFeedItem, s.newFeedItem) + s.app.Post(urls.SendTestEmail, s.sendTestEmail) + s.app.Use(urls.Statics, static.NewHandler()) } diff --git a/walrss/internal/http/testEmail.go b/walrss/internal/http/testEmail.go new file mode 100644 index 0000000..1aab514 --- /dev/null +++ b/walrss/internal/http/testEmail.go @@ -0,0 +1,30 @@ +package http + +import ( + "github.com/codemicro/walrss/walrss/internal/core" + "github.com/codemicro/walrss/walrss/internal/rss" + "github.com/codemicro/walrss/walrss/internal/urls" + "github.com/gofiber/fiber/v2" + "github.com/rs/zerolog/log" +) + +func (s *Server) sendTestEmail(ctx *fiber.Ctx) error { + currentUserID := getCurrentUserID(ctx) + if currentUserID == "" { + return requestFragmentSignIn(ctx, urls.Index) + } + + user, err := core.GetUserByID(s.state, currentUserID) + if err != nil { + return err + } + + go func() { + if err := rss.ProcessUserFeed(s.state, user); err != nil { + log.Error().Err(err).Str("location", "test email").Str("user", user.ID).Send() + } + }() + + fragmentEmitSuccess(ctx) + return nil +} diff --git a/walrss/internal/http/views/main.qtpl.html b/walrss/internal/http/views/main.qtpl.html index c9ab30f..47e1d54 100644 --- a/walrss/internal/http/views/main.qtpl.html +++ b/walrss/internal/http/views/main.qtpl.html @@ -282,7 +282,7 @@ - + diff --git a/walrss/internal/http/views/main.qtpl.html.go b/walrss/internal/http/views/main.qtpl.html.go index 83ddd03..9ff4393 100644 --- a/walrss/internal/http/views/main.qtpl.html.go +++ b/walrss/internal/http/views/main.qtpl.html.go @@ -497,6 +497,10 @@ func (p *MainPage) StreamRenderScheduleCard(qw422016 *qt422016.Writer) { + + `) diff --git a/walrss/internal/http/views/page.qtpl.html b/walrss/internal/http/views/page.qtpl.html index 2f35937..dd993f2 100644 --- a/walrss/internal/http/views/page.qtpl.html +++ b/walrss/internal/http/views/page.qtpl.html @@ -1,5 +1,3 @@ -{% import "github.com/codemicro/walrss/walrss/internal/urls" %} - {% interface Page { Title() @@ -71,7 +69,7 @@ Page prints a page implementing Page interface. PolyPage is used to create a basic page dynamically using Daz. {% code type PolyPage struct { - BasePageuuu + BasePage TitleString string BodyContent string ExtraHeadContent string diff --git a/walrss/internal/http/views/page.qtpl.html.go b/walrss/internal/http/views/page.qtpl.html.go index 926ee88..2c9a6ca 100644 --- a/walrss/internal/http/views/page.qtpl.html.go +++ b/walrss/internal/http/views/page.qtpl.html.go @@ -3,8 +3,6 @@ package views -import "github.com/codemicro/walrss/walrss/internal/urls" - import ( qtio422016 "io" @@ -39,16 +37,11 @@ func StreamRenderPage(qw422016 *qt422016.Writer, p Page) { qw422016.N().S(makePageTitle(p)) qw422016.N().S(` - - + + - + +