From 408207df928c94cb67a07834947004f3c0b314f9 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 22:39:49 +0000 Subject: [PATCH 1/7] Fix yarn call not doing anything --- docker/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 86408a2..2f486aa 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,8 +9,9 @@ RUN apk --no-cache add go nodejs yarn bash curl git git-perl tmux ADD docker/build.sh / RUN yarn global add @vue/cli ENV PATH="/root/.yarn/bin/:${PATH}" -WORKDIR /src +WORKDIR /src/web ADD web/package.json web/yarn.lock /src/web/ RUN yarn COPY --from=godeps /root/go/bin/task /root/go/bin/sqlc /root/go/bin/golangci-lint /usr/local/bin/ +WORKDIR /src CMD /build.sh -- 2.47.2 From 27ce8d250f565dfee76551656a0c8afc80284a26 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 22:44:09 +0000 Subject: [PATCH 2/7] Move WORKDIR call --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 2f486aa..1775bfb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -12,6 +12,6 @@ ENV PATH="/root/.yarn/bin/:${PATH}" WORKDIR /src/web ADD web/package.json web/yarn.lock /src/web/ RUN yarn -COPY --from=godeps /root/go/bin/task /root/go/bin/sqlc /root/go/bin/golangci-lint /usr/local/bin/ WORKDIR /src +COPY --from=godeps /root/go/bin/task /root/go/bin/sqlc /root/go/bin/golangci-lint /usr/local/bin/ CMD /build.sh -- 2.47.2 From 52bb343402a81e465ac7efc39bfbd93e8deb1f5e Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 22:52:08 +0000 Subject: [PATCH 3/7] Reorganize routes and remove legacy ones --- server/http.go | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/server/http.go b/server/http.go index 74e1fad..80e9bd4 100644 --- a/server/http.go +++ b/server/http.go @@ -41,20 +41,12 @@ func (h *Handler) LoadRoutes(router *gin.Engine) { router.Use(enableCachingForStaticFiles()) router.NoRoute(h.ServeStatic) - withLogin := router.Group("") - withLogin.Use(h.verifyLoginWithRedirect) - - withBudget := router.Group("") - withBudget.Use(h.verifyLoginWithForbidden) - withBudget.GET("/budget/:budgetid/:year/:month", h.budgeting) - withBudget.GET("/budget/:budgetid/settings/clean-negative", h.cleanNegativeBudget) - api := router.Group("/api/v1") - unauthenticated := api.Group("/user") - unauthenticated.GET("/login", func(c *gin.Context) { c.Redirect(http.StatusPermanentRedirect, "/login") }) - unauthenticated.POST("/login", h.loginPost) - unauthenticated.POST("/register", h.registerPost) + anonymous := api.Group("/user") + anonymous.GET("/login", func(c *gin.Context) { c.Redirect(http.StatusPermanentRedirect, "/login") }) + anonymous.POST("/login", h.loginPost) + anonymous.POST("/register", h.registerPost) authenticated := api.Group("") authenticated.Use(h.verifyLoginWithForbidden) @@ -62,18 +54,19 @@ func (h *Handler) LoadRoutes(router *gin.Engine) { authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount) authenticated.POST("/account/:accountid", h.editAccount) authenticated.GET("/admin/clear-database", h.clearDatabase) - authenticated.GET("/budget/:budgetid", h.budgeting) - authenticated.GET("/budget/:budgetid/:year/:month", h.budgetingForMonth) - authenticated.GET("/budget/:budgetid/autocomplete/payees", h.autocompletePayee) - authenticated.GET("/budget/:budgetid/autocomplete/categories", h.autocompleteCategories) - authenticated.DELETE("/budget/:budgetid", h.deleteBudget) - authenticated.POST("/budget/:budgetid/import/ynab", h.importYNAB) - authenticated.POST("/budget/:budgetid/export/ynab/transactions", h.exportYNABTransactions) - authenticated.POST("/budget/:budgetid/export/ynab/assignments", h.exportYNABAssignments) - authenticated.POST("/budget/:budgetid/settings/clear", h.clearBudget) budget := authenticated.Group("/budget") budget.POST("/new", h.newBudget) + budget.GET("/:budgetid", h.budgeting) + budget.GET("/:budgetid/:year/:month", h.budgetingForMonth) + budget.GET("/:budgetid/autocomplete/payees", h.autocompletePayee) + budget.GET("/:budgetid/autocomplete/categories", h.autocompleteCategories) + budget.DELETE("/:budgetid", h.deleteBudget) + budget.POST("/:budgetid/import/ynab", h.importYNAB) + budget.POST("/:budgetid/export/ynab/transactions", h.exportYNABTransactions) + budget.POST("/:budgetid/export/ynab/assignments", h.exportYNABAssignments) + budget.POST("/:budgetid/settings/clear", h.clearBudget) + budget.POST("/:budgetid/settings/clean-negative", h.cleanNegativeBudget) transaction := authenticated.Group("/transaction") transaction.POST("/new", h.newTransaction) -- 2.47.2 From a73c5ce04b1c1dda28deb1badb275798d08f8749 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 22:54:51 +0000 Subject: [PATCH 4/7] Build images only on master push or tag --- .drone.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 60faecb..151660e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -24,10 +24,26 @@ steps: tags: - latest when: + branch: + - master event: - exclude: - - pull_request + - push +- name: docker tag + image: plugins/docker + settings: + registry: hub.javil.eu + username: + from_secret: docker_user + password: + from_secret: docker_password + repo: hub.javil.eu/budgeteer + context: build + dockerfile: build/Dockerfile + auto_tag: true + when: + event: + - tag image_pull_secrets: - hub.javil.eu \ No newline at end of file -- 2.47.2 From adcb64f4ad35790c5a55311889f70a088f7758a0 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 22:55:48 +0000 Subject: [PATCH 5/7] Remove unused method --- server/session.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/server/session.go b/server/session.go index 3e0c98b..12af8e1 100644 --- a/server/session.go +++ b/server/session.go @@ -53,18 +53,6 @@ func (h *Handler) verifyLoginWithForbidden(c *gin.Context) { c.Next() } -func (h *Handler) verifyLoginWithRedirect(c *gin.Context) { - token, err := h.verifyLogin(c) - if err != nil { - c.Redirect(http.StatusTemporaryRedirect, "/login") - c.Abort() - return - } - - c.Set(ParamName, token) - c.Next() -} - type loginInformation struct { Password string `json:"password"` User string `json:"user"` -- 2.47.2 From eb52bd5def7813f7f8a8854e7d6592b02a82587f Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 22:57:19 +0000 Subject: [PATCH 6/7] Fix pull definition --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 151660e..d843d0c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,7 +6,7 @@ name: budgeteer steps: - name: Taskfile.dev image: hub.javil.eu/budgeteer:dev - pull: true + pull: always commands: - task ci -- 2.47.2 From 71f4d2384ba9f3d797a828e263514027a67b8e85 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 23:00:15 +0000 Subject: [PATCH 7/7] Fetch image only if not in PR --- .drone.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.drone.yml b/.drone.yml index d843d0c..be4392a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,11 +4,23 @@ type: docker name: budgeteer steps: +- name: Taskfile.dev PR + image: hub.javil.eu/budgeteer:dev + commands: + - task ci + when: + event: + - pull_request + - name: Taskfile.dev image: hub.javil.eu/budgeteer:dev pull: always commands: - task ci + when: + event: + exclude: + - pull_request - name: docker image: plugins/docker -- 2.47.2