From a04521926ef18013f311e6ef64bc57157b5a5fac Mon Sep 17 00:00:00 2001 From: Shivaprasad Date: Wed, 4 Jan 2023 12:14:57 +0530 Subject: [PATCH] feat: add dockerfile, rename frontend to ui --- Dockerfile | 24 +++++++++++++++++++++ Makefile | 2 +- cli.go | 4 ++-- {frontend => ui}/app/App.svelte | 0 {frontend => ui}/app/index.html | 0 {frontend => ui}/app/main.ts | 0 {frontend => ui}/app/public/vite.svg | 0 {frontend => ui}/app/routes/Home.svelte | 0 {frontend => ui}/app/routes/NotFound.svelte | 0 {frontend => ui}/app/vite-env.d.ts | 0 {frontend => ui}/embed.go | 2 +- {frontend => ui}/globals.css | 0 {frontend => ui}/index.html | 2 +- {frontend => ui}/package.json | 0 {frontend => ui}/postcss.config.cjs | 0 {frontend => ui}/svelte.config.js | 0 {frontend => ui}/tailwind.config.cjs | 0 {frontend => ui}/tsconfig.json | 0 {frontend => ui}/tsconfig.node.json | 0 {frontend => ui}/vite.config.ts | 0 {frontend => ui}/yarn.lock | 0 21 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 Dockerfile rename {frontend => ui}/app/App.svelte (100%) rename {frontend => ui}/app/index.html (100%) rename {frontend => ui}/app/main.ts (100%) rename {frontend => ui}/app/public/vite.svg (100%) rename {frontend => ui}/app/routes/Home.svelte (100%) rename {frontend => ui}/app/routes/NotFound.svelte (100%) rename {frontend => ui}/app/vite-env.d.ts (100%) rename {frontend => ui}/embed.go (93%) rename {frontend => ui}/globals.css (100%) rename {frontend => ui}/index.html (96%) rename {frontend => ui}/package.json (100%) rename {frontend => ui}/postcss.config.cjs (100%) rename {frontend => ui}/svelte.config.js (100%) rename {frontend => ui}/tailwind.config.cjs (100%) rename {frontend => ui}/tsconfig.json (100%) rename {frontend => ui}/tsconfig.node.json (100%) rename {frontend => ui}/vite.config.ts (100%) rename {frontend => ui}/yarn.lock (100%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a2460a0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Build FrontEnd +FROM node:16 as fe-builder +RUN apt update -y && apt install -y golang && npm install -g vite +RUN mkdir /build +ADD ./ui /build/ui +WORKDIR /build/ui +RUN yarn && yarn build + +# Build BackEnd +FROM golang:1.19-alpine3.16 as builder +RUN apk add --no-cache make +RUN mkdir /build +ADD ./ /build/ +RUN rm -rf /build/ui +COPY --from=fe-builder /build/ui /build/ui +WORKDIR /build +RUN make be + +# Package Staage +FROM alpine:3.11.3 +COPY --from=builder /build/dist/go-svelte /app/go-svelte +COPY --from=builder /build/config.yml /app/config.yml +CMD [ "/app/go-svelte", "serve", "-c", "/app/config.yml" ] + diff --git a/Makefile b/Makefile index 27615fc..82d462a 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ tidy: fe: @echo "Building frontend..." - @cd frontend && vite build + @cd ui && yarn && yarn build be: @echo "Building backend..." diff --git a/cli.go b/cli.go index 123cbc5..0e95384 100644 --- a/cli.go +++ b/cli.go @@ -13,9 +13,9 @@ import ( "gopkg.in/yaml.v2" "github.com/saas-templates/go-svelte/api" - "github.com/saas-templates/go-svelte/frontend" "github.com/saas-templates/go-svelte/pkg/httputils" "github.com/saas-templates/go-svelte/pkg/log" + "github.com/saas-templates/go-svelte/ui" ) func newCLI(ctx context.Context) *cobra.Command { @@ -44,7 +44,7 @@ func cmdServe() *cobra.Command { cfg := loadConf(cmd) router := chi.NewRouter() - router.Mount("/", http.FileServer(http.FS(frontend.DistFS))) + router.Mount("/", http.FileServer(http.FS(ui.DistFS))) router.Mount("/api", api.Router(cfg.API)) log.Infof(cmd.Context(), "listening at '%s'...", cfg.Addr) diff --git a/frontend/app/App.svelte b/ui/app/App.svelte similarity index 100% rename from frontend/app/App.svelte rename to ui/app/App.svelte diff --git a/frontend/app/index.html b/ui/app/index.html similarity index 100% rename from frontend/app/index.html rename to ui/app/index.html diff --git a/frontend/app/main.ts b/ui/app/main.ts similarity index 100% rename from frontend/app/main.ts rename to ui/app/main.ts diff --git a/frontend/app/public/vite.svg b/ui/app/public/vite.svg similarity index 100% rename from frontend/app/public/vite.svg rename to ui/app/public/vite.svg diff --git a/frontend/app/routes/Home.svelte b/ui/app/routes/Home.svelte similarity index 100% rename from frontend/app/routes/Home.svelte rename to ui/app/routes/Home.svelte diff --git a/frontend/app/routes/NotFound.svelte b/ui/app/routes/NotFound.svelte similarity index 100% rename from frontend/app/routes/NotFound.svelte rename to ui/app/routes/NotFound.svelte diff --git a/frontend/app/vite-env.d.ts b/ui/app/vite-env.d.ts similarity index 100% rename from frontend/app/vite-env.d.ts rename to ui/app/vite-env.d.ts diff --git a/frontend/embed.go b/ui/embed.go similarity index 93% rename from frontend/embed.go rename to ui/embed.go index 9eff5aa..4c12fe9 100644 --- a/frontend/embed.go +++ b/ui/embed.go @@ -1,4 +1,4 @@ -package frontend +package ui import ( "embed" diff --git a/frontend/globals.css b/ui/globals.css similarity index 100% rename from frontend/globals.css rename to ui/globals.css diff --git a/frontend/index.html b/ui/index.html similarity index 96% rename from frontend/index.html rename to ui/index.html index 53e203a..9cad207 100644 --- a/frontend/index.html +++ b/ui/index.html @@ -4,7 +4,7 @@ - AIGizmos + Go-Svlete diff --git a/frontend/package.json b/ui/package.json similarity index 100% rename from frontend/package.json rename to ui/package.json diff --git a/frontend/postcss.config.cjs b/ui/postcss.config.cjs similarity index 100% rename from frontend/postcss.config.cjs rename to ui/postcss.config.cjs diff --git a/frontend/svelte.config.js b/ui/svelte.config.js similarity index 100% rename from frontend/svelte.config.js rename to ui/svelte.config.js diff --git a/frontend/tailwind.config.cjs b/ui/tailwind.config.cjs similarity index 100% rename from frontend/tailwind.config.cjs rename to ui/tailwind.config.cjs diff --git a/frontend/tsconfig.json b/ui/tsconfig.json similarity index 100% rename from frontend/tsconfig.json rename to ui/tsconfig.json diff --git a/frontend/tsconfig.node.json b/ui/tsconfig.node.json similarity index 100% rename from frontend/tsconfig.node.json rename to ui/tsconfig.node.json diff --git a/frontend/vite.config.ts b/ui/vite.config.ts similarity index 100% rename from frontend/vite.config.ts rename to ui/vite.config.ts diff --git a/frontend/yarn.lock b/ui/yarn.lock similarity index 100% rename from frontend/yarn.lock rename to ui/yarn.lock