Skip to content

Commit ffda558

Browse files
committed
feat(memoh): unify embedded runtime serving and release binaries
1 parent d6914f9 commit ffda558

18 files changed

Lines changed: 1564 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,66 @@ jobs:
2828
env:
2929
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3030

31+
build-binaries:
32+
needs: release
33+
runs-on: ubuntu-latest
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
include:
38+
- goos: linux
39+
goarch: amd64
40+
- goos: linux
41+
goarch: arm64
42+
- goos: linux
43+
goarch: riscv64
44+
- goos: darwin
45+
goarch: amd64
46+
- goos: darwin
47+
goarch: arm64
48+
- goos: windows
49+
goarch: amd64
50+
steps:
51+
- uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 0
54+
55+
- uses: pnpm/action-setup@v4
56+
with:
57+
version: 10
58+
59+
- uses: actions/setup-node@v4
60+
with:
61+
node-version: lts/*
62+
63+
- uses: oven-sh/setup-bun@v2
64+
65+
- uses: actions/setup-go@v5
66+
with:
67+
go-version-file: go.mod
68+
69+
- name: Install JS dependencies
70+
run: pnpm install --frozen-lockfile
71+
72+
- name: Build release binary
73+
env:
74+
TARGET_OS: ${{ matrix.goos }}
75+
TARGET_ARCH: ${{ matrix.goarch }}
76+
VERSION: ${{ github.ref_name }}
77+
COMMIT_HASH: ${{ github.sha }}
78+
OUTPUT_DIR: dist
79+
run: scripts/release.sh
80+
81+
- name: Upload release assets
82+
uses: softprops/action-gh-release@v2
83+
with:
84+
files: |
85+
dist/*.tar.gz
86+
dist/*.zip
87+
tag_name: ${{ github.ref_name }}
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
3191
# # Uncomment the following lines to publish to npm on CI
3292
#
3393
# - run: pnpm install

agent/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { errorMiddleware } from './middlewares/error'
55
import { loadConfig, getBaseUrl as getBaseUrlByConfig } from '@memoh/config'
66
import { AgentAuthContext, AuthFetcher } from '@memoh/agent'
77

8-
const config = loadConfig('../config.toml')
8+
const configuredPath = process.env.MEMOH_CONFIG_PATH?.trim() || process.env.CONFIG_PATH?.trim()
9+
const configPath = configuredPath && configuredPath.length > 0 ? configuredPath : '../config.toml'
10+
const config = loadConfig(configPath)
911

1012
export const getBaseUrl = () => {
1113
return getBaseUrlByConfig(config)

cmd/memoh/main.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func main() {
10+
rootCmd := &cobra.Command{
11+
Use: "memoh",
12+
Short: "Memoh unified binary",
13+
RunE: func(cmd *cobra.Command, args []string) error {
14+
runServe()
15+
return nil
16+
},
17+
}
18+
19+
rootCmd.AddCommand(&cobra.Command{
20+
Use: "serve",
21+
Short: "Start the server",
22+
RunE: func(cmd *cobra.Command, args []string) error {
23+
runServe()
24+
return nil
25+
},
26+
})
27+
28+
rootCmd.AddCommand(&cobra.Command{
29+
Use: "migrate <up|down|version|force N>",
30+
Short: "Run database migrations",
31+
Args: cobra.MinimumNArgs(1),
32+
RunE: func(cmd *cobra.Command, args []string) error {
33+
return runMigrate(args)
34+
},
35+
})
36+
37+
rootCmd.AddCommand(&cobra.Command{
38+
Use: "version",
39+
Short: "Print version information",
40+
RunE: func(cmd *cobra.Command, args []string) error {
41+
return runVersion()
42+
},
43+
})
44+
45+
if err := rootCmd.Execute(); err != nil {
46+
os.Exit(1)
47+
}
48+
}

cmd/memoh/migrate.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/fs"
6+
"log/slog"
7+
8+
dbembed "github.com/memohai/memoh/db"
9+
"github.com/memohai/memoh/internal/db"
10+
"github.com/memohai/memoh/internal/logger"
11+
)
12+
13+
func migrationsFS() fs.FS {
14+
sub, err := fs.Sub(dbembed.MigrationsFS, "migrations")
15+
if err != nil {
16+
panic(fmt.Sprintf("embedded migrations: %v", err))
17+
}
18+
return sub
19+
}
20+
21+
func runMigrate(args []string) error {
22+
cfg, err := provideConfig()
23+
if err != nil {
24+
return fmt.Errorf("config: %w", err)
25+
}
26+
27+
logger.Init(cfg.Log.Level, cfg.Log.Format)
28+
log := logger.L
29+
30+
migrateCmd := args[0]
31+
var migrateArgs []string
32+
if len(args) > 1 {
33+
migrateArgs = args[1:]
34+
}
35+
36+
if err := db.RunMigrate(log, cfg.Postgres, migrationsFS(), migrateCmd, migrateArgs); err != nil {
37+
log.Error("migration failed", slog.Any("error", err))
38+
return err
39+
}
40+
return nil
41+
}

0 commit comments

Comments
 (0)