Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
5f26c52b
Commit
5f26c52b
authored
Apr 26, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add goreleaser
parent
647602be
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
6 deletions
+91
-6
build-artifacts.yml
.github/workflows/build-artifacts.yml
+33
-0
.gitignore
.gitignore
+2
-1
.goreleaser.yaml
.goreleaser.yaml
+38
-0
Dockerfile
Dockerfile
+1
-1
frontend.go
server/route/frontend/frontend.go
+17
-4
No files found.
.github/workflows/build-artifacts.yml
0 → 100644
View file @
5f26c52b
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 }}
.gitignore
View file @
5f26c52b
...
@@ -6,7 +6,6 @@ tmp
...
@@ -6,7 +6,6 @@ tmp
# Frontend asset
# Frontend asset
web/dist
web/dist
server/frontend/dist
# build folder
# build folder
build
build
...
@@ -22,3 +21,5 @@ build
...
@@ -22,3 +21,5 @@ build
bin/air
bin/air
dev-dist
dev-dist
dist/
.goreleaser.yaml
0 → 100644
View file @
5f26c52b
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
Dockerfile
View file @
5f26c52b
...
@@ -15,6 +15,7 @@ FROM golang:1.22-alpine AS backend
...
@@ -15,6 +15,7 @@ FROM golang:1.22-alpine AS backend
WORKDIR
/backend-build
WORKDIR
/backend-build
COPY
. .
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
RUN
CGO_ENABLED
=
0 go build
-o
memos ./bin/memos/main.go
...
@@ -25,7 +26,6 @@ WORKDIR /usr/local/memos
...
@@ -25,7 +26,6 @@ WORKDIR /usr/local/memos
RUN
apk add
--no-cache
tzdata
RUN
apk add
--no-cache
tzdata
ENV
TZ="UTC"
ENV
TZ="UTC"
COPY
--from=frontend /frontend-build/web/dist /usr/local/memos/dist
COPY
--from=backend /backend-build/memos /usr/local/memos/
COPY
--from=backend /backend-build/memos /usr/local/memos/
EXPOSE
5230
EXPOSE
5230
...
...
server/route/frontend/frontend.go
View file @
5f26c52b
...
@@ -2,9 +2,10 @@ package frontend
...
@@ -2,9 +2,10 @@ package frontend
import
(
import
(
"context"
"context"
"embed"
"fmt"
"fmt"
"io/fs"
"net/http"
"net/http"
"os"
"strings"
"strings"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
...
@@ -18,6 +19,9 @@ import (
...
@@ -18,6 +19,9 @@ import (
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
//go:embed dist
var
embeddedFiles
embed
.
FS
const
(
const
(
// maxMetadataDescriptionLength is the maximum length of metadata description.
// maxMetadataDescriptionLength is the maximum length of metadata description.
maxMetadataDescriptionLength
=
256
maxMetadataDescriptionLength
=
256
...
@@ -39,8 +43,8 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
...
@@ -39,8 +43,8 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
// Use echo static middleware to serve the built dist folder.
// Use echo static middleware to serve the built dist folder.
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
e
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
e
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
Root
:
"dist"
,
HTML5
:
true
,
HTML5
:
true
,
Filesystem
:
getFileSystem
(
"dist"
)
,
Skipper
:
func
(
c
echo
.
Context
)
bool
{
Skipper
:
func
(
c
echo
.
Context
)
bool
{
return
util
.
HasPrefixes
(
c
.
Path
(),
"/api"
,
"/memos.api.v2"
,
"/robots.txt"
,
"/sitemap.xml"
,
"/m/:name"
)
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)
...
@@ -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
{
func
generateMemoMetadata
(
memo
*
store
.
Memo
,
creator
*
store
.
User
)
*
Metadata
{
metadata
:=
getDefaultMetadata
()
metadata
:=
getDefaultMetadata
()
metadata
.
Title
=
fmt
.
Sprintf
(
"%s(@%s) on Memos"
,
creator
.
Nickname
,
creator
.
Username
)
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 {
...
@@ -135,7 +148,7 @@ func generateMemoMetadata(memo *store.Memo, creator *store.User) *Metadata {
}
}
func
getRawIndexHTML
()
string
{
func
getRawIndexHTML
()
string
{
bytes
,
_
:=
o
s
.
ReadFile
(
"dist/index.html"
)
bytes
,
_
:=
embeddedFile
s
.
ReadFile
(
"dist/index.html"
)
return
string
(
bytes
)
return
string
(
bytes
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment