Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: add goreleaser

Steven5f26c52b49de
diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml
new file mode 100644
index 000000000..087466e8b
--- /dev/null
+++ b/.github/workflows/build-artifacts.yml
@@ -0,0 +1,33 @@
+name: Build artifacts
+
+on:
+ push:
+ tags:
+ - "*"
+
+permissions:
+ contents: write
+
+jobs:
+ goreleaser:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ - uses: actions/setup-go@v5
+ with:
+ go-version: 1.22
+ check-latest: true
+ cache: true
+ - name: Run GoReleaser
+ uses: goreleaser/goreleaser-action@v5
+ with:
+ # either 'goreleaser' (default) or 'goreleaser-pro'
+ distribution: goreleaser
+ # 'latest', 'nightly', or a semver
+ version: latest
+ args: release --clean
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.gitignore b/.gitignore
index 17f64ee21..976671ca9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,7 +6,6 @@ tmp
# Frontend asset
web/dist
-server/frontend/dist
# build folder
build
@@ -22,3 +21,5 @@ build
bin/air
dev-dist
+
+dist/
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
new file mode 100644
index 000000000..84f97c754
--- /dev/null
+++ b/.goreleaser.yaml
@@ -0,0 +1,38 @@
+version: 1
+
+before:
+ hooks:
+ # You may remove this if you don't use go modules.
+ - go mod tidy
+
+builds:
+ - env:
+ - CGO_ENABLED=0
+ main: ./bin/memos
+ binary: memos
+ goos:
+ - linux
+ - darwin
+
+archives:
+ - format: tar.gz
+ # this name template makes the OS and Arch compatible with the results of `uname`.
+ name_template: >-
+ {{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}
+
+changelog:
+ sort: asc
+ filters:
+ exclude:
+ - "^docs:"
+ - "^test:"
+
+checksum:
+ disable: true
+
+release:
+ draft: true
+ replace_existing_draft: true
+ make_latest: true
+ mode: replace
+ skip_upload: false
diff --git a/Dockerfile b/Dockerfile
index 079c3503b..9a1a9f5e4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -15,6 +15,7 @@ FROM golang:1.22-alpine AS backend
WORKDIR /backend-build
COPY . .
+COPY --from=frontend /frontend-build/web/dist /backend-build/server/route/frontend/dist
RUN CGO_ENABLED=0 go build -o memos ./bin/memos/main.go
@@ -25,7 +26,6 @@ WORKDIR /usr/local/memos
RUN apk add --no-cache tzdata
ENV TZ="UTC"
-COPY --from=frontend /frontend-build/web/dist /usr/local/memos/dist
COPY --from=backend /backend-build/memos /usr/local/memos/
EXPOSE 5230
diff --git a/server/route/frontend/frontend.go b/server/route/frontend/frontend.go
index ecc5607d3..bcb144512 100644
--- a/server/route/frontend/frontend.go
+++ b/server/route/frontend/frontend.go
@@ -2,9 +2,10 @@ package frontend
import (
"context"
+ "embed"
"fmt"
+ "io/fs"
"net/http"
- "os"
"strings"
"github.com/labstack/echo/v4"
@@ -18,6 +19,9 @@ import (
"github.com/usememos/memos/store"
)
+//go:embed dist
+var embeddedFiles embed.FS
+
const (
// maxMetadataDescriptionLength is the maximum length of metadata description.
maxMetadataDescriptionLength = 256
@@ -39,8 +43,8 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
// Use echo static middleware to serve the built dist folder.
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
- Root: "dist",
- HTML5: true,
+ HTML5: true,
+ Filesystem: getFileSystem("dist"),
Skipper: func(c echo.Context) bool {
return util.HasPrefixes(c.Path(), "/api", "/memos.api.v2", "/robots.txt", "/sitemap.xml", "/m/:name")
},
@@ -115,6 +119,15 @@ Sitemap: %s/sitemap.xml`, instanceURL, instanceURL)
})
}
+func getFileSystem(path string) http.FileSystem {
+ fs, err := fs.Sub(embeddedFiles, path)
+ if err != nil {
+ panic(err)
+ }
+
+ return http.FS(fs)
+}
+
func generateMemoMetadata(memo *store.Memo, creator *store.User) *Metadata {
metadata := getDefaultMetadata()
metadata.Title = fmt.Sprintf("%s(@%s) on Memos", creator.Nickname, creator.Username)
@@ -135,7 +148,7 @@ func generateMemoMetadata(memo *store.Memo, creator *store.User) *Metadata {
}
func getRawIndexHTML() string {
- bytes, _ := os.ReadFile("dist/index.html")
+ bytes, _ := embeddedFiles.ReadFile("dist/index.html")
return string(bytes)
}