Skip to content

Commit

Permalink
chore:ci: pull tags/v0.22.4 from usememos/memos
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthalles committed Aug 1, 2024
2 parents 18277f1 + b236051 commit 8f166ef
Show file tree
Hide file tree
Showing 82 changed files with 1,718 additions and 3,548 deletions.
6 changes: 3 additions & 3 deletions memos/.github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ updates:
prefix: "chore"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
- package-ecosystem: npm
commit-message:
prefix: "chore"
directory: "/web"
schedule:
interval: "weekly"
interval: "monthly"
- package-ecosystem: "gomod"
commit-message:
prefix: "chore"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
18 changes: 13 additions & 5 deletions memos/.github/workflows/build-and-push-release-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ name: build-and-push-release-image

on:
push:
tags:
# Run on pushing tags like 'v1.0.0'
- "v*.*.*"
branches:
# Run on pushing branches like `release/1.0.0`
- "release/*.*.*"
# Run on pushing branches like 'v1.0.0'
- "v*.*.*"

jobs:
build-and-push-release-image:
Expand All @@ -19,10 +22,10 @@ jobs:
uses: docker/setup-qemu-action@v3

- name: Extract build args
# Extract version from branch name
# Example: branch name `release/1.0.0` sets up env.VERSION=1.0.0
# Extract version from tag name
# Example: tag name `v1.0.0` sets up env.VERSION=1.0.0
run: |
echo "VERSION=${GITHUB_REF_NAME#release/}" >> $GITHUB_ENV
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
Expand Down Expand Up @@ -54,6 +57,11 @@ jobs:
tags: |
type=semver,pattern={{version}},value=${{ env.VERSION }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }}
${{ startsWith(github.ref, 'refs/tags/') && 'type=raw,value=stable' }}
flavor: |
latest=true
labels: |
org.opencontainers.image.version=${{ env.VERSION }}
- name: Build and Push
id: docker_build
Expand Down
61 changes: 0 additions & 61 deletions memos/.github/workflows/build-and-push-stable-image.yml

This file was deleted.

101 changes: 52 additions & 49 deletions memos/bin/memos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/usememos/memos/server"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/version"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store/db"
)
Expand All @@ -30,43 +31,49 @@ const (
)

var (
mode string
addr string
port int
data string
driver string
dsn string
public bool
instanceProfile *profile.Profile

rootCmd = &cobra.Command{
Use: "memos",
Short: `An open source, lightweight note-taking service. Easily capture and share your great thoughts.`,
Run: func(_ *cobra.Command, _ []string) {
instanceProfile := &profile.Profile{
Mode: viper.GetString("mode"),
Addr: viper.GetString("addr"),
Port: viper.GetInt("port"),
Data: viper.GetString("data"),
Driver: viper.GetString("driver"),
DSN: viper.GetString("dsn"),
Public: viper.GetBool("public"),
PasswordAuth: viper.GetBool("password-auth"),
Version: version.GetCurrentVersion(viper.GetString("mode")),
}
if err := instanceProfile.Validate(); err != nil {
panic(err)
}

ctx, cancel := context.WithCancel(context.Background())
dbDriver, err := db.NewDBDriver(instanceProfile)
if err != nil {
cancel()
slog.Error("failed to create db driver", err)
slog.Error("failed to create db driver", "error", err)
return
}
if err := dbDriver.Migrate(ctx); err != nil {
cancel()
slog.Error("failed to migrate database", err)
slog.Error("failed to migrate database", "error", err)
return
}

storeInstance := store.New(dbDriver, instanceProfile)
if err := storeInstance.MigrateManually(ctx); err != nil {
cancel()
slog.Error("failed to migrate manually", err)
slog.Error("failed to migrate manually", "error", err)
return
}

s, err := server.NewServer(ctx, instanceProfile, storeInstance)
if err != nil {
cancel()
slog.Error("failed to create server", err)
slog.Error("failed to create server", "error", err)
return
}

Expand All @@ -78,12 +85,12 @@ var (

if err := s.Start(ctx); err != nil {
if err != http.ErrServerClosed {
slog.Error("failed to start server", err)
slog.Error("failed to start server", "error", err)
cancel()
}
}

printGreetings()
printGreetings(instanceProfile)

go func() {
<-c
Expand All @@ -97,20 +104,22 @@ var (
}
)

func Execute() error {
return rootCmd.Execute()
}

func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVarP(&mode, "mode", "m", "demo", `mode of server, can be "prod" or "dev" or "demo"`)
rootCmd.PersistentFlags().StringVarP(&addr, "addr", "a", "", "address of server")
rootCmd.PersistentFlags().IntVarP(&port, "port", "p", 8081, "port of server")
rootCmd.PersistentFlags().StringVarP(&data, "data", "d", "", "data directory")
rootCmd.PersistentFlags().StringVarP(&driver, "driver", "", "", "database driver")
rootCmd.PersistentFlags().StringVarP(&dsn, "dsn", "", "", "database source name(aka. DSN)")
rootCmd.PersistentFlags().BoolVarP(&public, "public", "", true, "")
viper.SetDefault("mode", "demo")
viper.SetDefault("driver", "sqlite")
viper.SetDefault("addr", "")
viper.SetDefault("port", 8081)
viper.SetDefault("public", false)
viper.SetDefault("password-auth", true)

rootCmd.PersistentFlags().String("mode", "demo", `mode of server, can be "prod" or "dev" or "demo"`)
rootCmd.PersistentFlags().String("addr", "", "address of server")
rootCmd.PersistentFlags().Int("port", 8081, "port of server")
rootCmd.PersistentFlags().String("data", "", "data directory")
rootCmd.PersistentFlags().String("driver", "sqlite", "database driver")
rootCmd.PersistentFlags().String("dsn", "", "database source name(aka. DSN)")
rootCmd.PersistentFlags().Bool("public", false, "")
rootCmd.PersistentFlags().Bool("password-auth", true, "")

err := viper.BindPFlag("mode", rootCmd.PersistentFlags().Lookup("mode"))
if err != nil {
Expand Down Expand Up @@ -140,24 +149,19 @@ func init() {
if err != nil {
panic(err)
}
err = viper.BindPFlag("password-auth", rootCmd.PersistentFlags().Lookup("password-auth"))
if err != nil {
panic(err)
}

viper.SetDefault("mode", "demo")
viper.SetDefault("driver", "sqlite")
viper.SetDefault("addr", "")
viper.SetDefault("port", 8081)
viper.SetDefault("public", true)
viper.SetEnvPrefix("memos")
}

func initConfig() {
viper.AutomaticEnv()
var err error
instanceProfile, err = profile.GetProfile()
if err != nil {
slog.Error("failed to get profile", err)
return
if err := viper.BindEnv("password-auth", "MEMOS_PASSWORD_AUTH"); err != nil {
panic(err)
}
}

func printGreetings(profile *profile.Profile) {
fmt.Printf(`---
Server profile
version: %s
Expand All @@ -166,17 +170,17 @@ dsn: %s
addr: %s
port: %d
mode: %s
public: %t
password-auth: %t
driver: %s
---
`, instanceProfile.Version, instanceProfile.Data, instanceProfile.DSN, instanceProfile.Addr, instanceProfile.Port, instanceProfile.Mode, instanceProfile.Driver)
}
`, profile.Version, profile.Data, profile.DSN, profile.Addr, profile.Port, profile.Mode, profile.Public, profile.PasswordAuth, profile.Driver)

func printGreetings() {
print(greetingBanner)
if len(instanceProfile.Addr) == 0 {
fmt.Printf("Version %s has been started on port %d\n", instanceProfile.Version, instanceProfile.Port)
if len(profile.Addr) == 0 {
fmt.Printf("Version %s has been started on port %d\n", profile.Version, profile.Port)
} else {
fmt.Printf("Version %s has been started on address '%s' and port %d\n", instanceProfile.Version, instanceProfile.Addr, instanceProfile.Port)
fmt.Printf("Version %s has been started on address '%s' and port %d\n", profile.Version, profile.Addr, profile.Port)
}
fmt.Printf(`---
See more in:
Expand All @@ -187,8 +191,7 @@ See more in:
}

func main() {
err := Execute()
if err != nil {
if err := rootCmd.Execute(); err != nil {
panic(err)
}
}
Loading

0 comments on commit 8f166ef

Please sign in to comment.