Skip to content

Commit b45dfe2

Browse files
committed
ci: ko build
1 parent c80788b commit b45dfe2

File tree

13 files changed

+266
-82
lines changed

13 files changed

+266
-82
lines changed

.ko.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defaultBaseImage: alpine
2+
3+
builds:
4+
- id: frpp
5+
# env:
6+
# - GOCACHE=/.gocache
7+
ldflags:
8+
- -s -w
9+
- -X github.com/VaalaCat/frp-panel/conf.buildDate={{.Date}}
10+
- -X github.com/VaalaCat/frp-panel/conf.gitCommit={{.Git.FullCommit}}
11+
- -X github.com/VaalaCat/frp-panel/conf.gitVersion={{.Git.Tag}}
12+
- -X github.com/VaalaCat/frp-panel/conf.gitBranch={{.Git.Branch}}
13+
14+
defaultPlatforms:
15+
- linux/arm64
16+
- linux/amd64

build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ARCH="all"
1919
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
2020
GIT_COMMIT="$(git rev-parse HEAD)"
2121
VERSION="$(git describe --tags --abbrev=0 | tr -d '\n')"
22+
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
2223

2324
# Parse arguments
2425
while [[ "$#" -gt 0 ]]; do
@@ -50,7 +51,7 @@ echo "Build Date: $BUILD_DATE"
5051
echo "Git Commit: $GIT_COMMIT"
5152
echo "Version: $VERSION"
5253

53-
BUILD_LD_FLAGS="-X 'github.com/VaalaCat/frp-panel/conf.buildDate=${BUILD_DATE}' -X 'github.com/VaalaCat/frp-panel/conf.gitCommit=${GIT_COMMIT}' -X 'github.com/VaalaCat/frp-panel/conf.gitVersion=${VERSION}'"
54+
BUILD_LD_FLAGS="-X 'github.com/VaalaCat/frp-panel/conf.buildDate=${BUILD_DATE}' -X 'github.com/VaalaCat/frp-panel/conf.gitCommit=${GIT_COMMIT}' -X 'github.com/VaalaCat/frp-panel/conf.gitVersion=${VERSION}' -X 'github.com/VaalaCat/frp-panel/conf.gitBranch=${GIT_BRANCH}'"
5455

5556
if [[ "$SKIP_FRONTEND" == "true" ]]; then
5657
echo "Skipping frontend build"

cmd/frpp/master.go

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"embed"
6+
"path/filepath"
67

78
bizmaster "github.com/VaalaCat/frp-panel/biz/master"
89
"github.com/VaalaCat/frp-panel/biz/master/auth"
@@ -80,6 +81,12 @@ func initDatabase(c context.Context) {
8081

8182
switch conf.Get().DB.Type {
8283
case "sqlite3":
84+
if err := utils.EnsureDirectoryExists(conf.Get().DB.DSN); err != nil {
85+
logrus.WithError(err).Warnf("ensure directory failed, data location: [%s], keep data in current directory", conf.Get().DB.DSN)
86+
conf.Get().DB.DSN = filepath.Base(conf.Get().DB.DSN)
87+
logrus.Infof("new data location: [%s]", conf.Get().DB.DSN)
88+
}
89+
8390
if sqlitedb, err := gorm.Open(sqlite.Open(conf.Get().DB.DSN), &gorm.Config{}); err != nil {
8491
logrus.Panic(err)
8592
} else {

conf/settings.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Config struct {
4343
} `env-prefix:"SERVER_"`
4444
DB struct {
4545
Type string `env:"TYPE" env-default:"sqlite3" env-description:"db type, mysql or sqlite3 and so on"`
46-
DSN string `env:"DSN" env-default:"data.db" env-description:"db dsn, for sqlite is path, other is dsn, look at https://github.com/go-sql-driver/mysql#dsn-data-source-name"`
46+
DSN string `env:"DSN" env-default:"/data/data.db" env-description:"db dsn, for sqlite is path, other is dsn, look at https://github.com/go-sql-driver/mysql#dsn-data-source-name"`
4747
} `env-prefix:"DB_"`
4848
Client struct {
4949
ID string `env:"ID" env-description:"client id"`

conf/version.go

+4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import (
1212
var (
1313
gitVersion = "dev-build"
1414
gitCommit = ""
15+
gitBranch = ""
1516
buildDate = "1970-01-01T00:00:00Z"
1617
)
1718

1819
type VersionInfo struct {
1920
GitVersion string `json:"gitVersion" yaml:"gitVersion"`
2021
GitCommit string `json:"gitCommit" yaml:"gitCommit"`
22+
GitBranch string `json:"gitBranch" yaml:"gitBranch"`
2123
BuildDate string `json:"buildDate" yaml:"buildDate"`
2224
GoVersion string `json:"goVersion" yaml:"goVersion"`
2325
Compiler string `json:"compiler" yaml:"compiler"`
@@ -42,6 +44,7 @@ func (v *VersionInfo) ToProto() *pb.ClientVersion {
4244
return &pb.ClientVersion{
4345
GitVersion: v.GitVersion,
4446
GitCommit: v.GitCommit,
47+
GitBranch: v.GitBranch,
4548
BuildDate: v.BuildDate,
4649
GoVersion: v.GoVersion,
4750
Compiler: v.Compiler,
@@ -53,6 +56,7 @@ func GetVersion() *VersionInfo {
5356
return &VersionInfo{
5457
GitVersion: gitVersion,
5558
GitCommit: gitCommit,
59+
GitBranch: gitBranch,
5660
BuildDate: buildDate,
5761
GoVersion: runtime.Version(),
5862
Compiler: runtime.Compiler,

idl/api_master.proto

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ message ClientVersion {
2727
string GoVersion = 4;
2828
string Compiler = 5;
2929
string Platform = 6;
30+
string GitBranch = 7;
3031
}
3132

3233
message GetClientsStatusRequest {

pb/api_master.pb.go

+51-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/files.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package utils
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
)
7+
8+
func EnsureDirectoryExists(filePath string) error {
9+
directory := filepath.Dir(filePath)
10+
11+
if _, err := os.Stat(directory); os.IsNotExist(err) {
12+
err = os.MkdirAll(directory, os.ModePerm)
13+
if err != nil {
14+
return err
15+
}
16+
}
17+
return nil
18+
}

www/components/stats/client_stats_card.tsx

+27-30
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import { ProxyInfo } from '@/lib/pb/common'
1212
import { Button } from '../ui/button'
1313
import { CheckCircle2, CircleX, RefreshCcw } from "lucide-react"
1414
import { useTranslation } from 'react-i18next';
15+
import TrafficStatsCard from './stats-item'
16+
import { Separator } from '@radix-ui/react-separator'
17+
import { formatBytes } from '@/lib/utils'
1518

1619
export interface ClientStatsCardProps {
1720
clientID?: string
1821
}
1922
export const ClientStatsCard: React.FC<ClientStatsCardProps> = ({ clientID: defaultClientID }: ClientStatsCardProps = {}) => {
2023
const { t } = useTranslation();
2124
const [clientID, setClientID] = useState<string | undefined>()
22-
const [proxyName, setProxyName] = useState<string | undefined>()
2325
const [status, setStatus] = useState<"loading" | "success" | "error" | undefined>()
2426
const [timeoutId, setTimeoutId] = useState<NodeJS.Timeout | null>(null);
2527

@@ -69,11 +71,6 @@ export const ClientStatsCard: React.FC<ClientStatsCardProps> = ({ clientID: defa
6971
return Array.from(mergedMap.values());
7072
};
7173

72-
function removeDuplicateCharacters(input: string): string {
73-
const uniqueChars = new Set(input);
74-
return Array.from(uniqueChars).join('');
75-
}
76-
7774
return (
7875
<Card className="w-full">
7976
<CardHeader>
@@ -88,18 +85,16 @@ export const ClientStatsCard: React.FC<ClientStatsCardProps> = ({ clientID: defa
8885
<Label>{t('client.stats.label')}</Label>
8986
<ClientSelector clientID={clientID} setClientID={handleClientChange} onOpenChange={() => {
9087
refetchClientStats()
91-
setProxyName(undefined)
9288
}} />
9389
<Label>{t('proxy.stats.label')}</Label>
94-
<ProxySelector
95-
// @ts-ignore
96-
proxyNames={Array.from(new Set(clientStatsList?.proxyInfos.map((proxyInfo) => proxyInfo.name).filter((value) => value !== undefined))) || []}
97-
proxyName={proxyName}
98-
setProxyname={setProxyName} />
99-
<div className="w-full grid gap-4 grid-cols-1">
90+
<div className="w-full grid gap-2 grid-cols-1 overflow-x-auto">
10091
{clientStatsList && clientStatsList.proxyInfos.length > 0 &&
101-
<ProxyStatusCard
102-
proxyInfo={mergeProxyInfos(clientStatsList.proxyInfos).find((proxyInfo) => proxyInfo.name === proxyName)} />}
92+
clientStatsList.proxyInfos.map((proxyInfo) => {
93+
return (
94+
<ProxyStatusCard key={proxyInfo.name} proxyInfo={proxyInfo} />
95+
)
96+
})
97+
}
10398
</div>
10499
</CardContent>
105100
<CardFooter>
@@ -135,21 +130,23 @@ const ProxyStatusCard: React.FC<{ proxyInfo: ProxyInfo | undefined }> = ({ proxy
135130
}
136131

137132
return (
138-
<div key={proxyInfo.name} className="flex flex-col space-y-4">
133+
<Card key={proxyInfo.name} className="flex flex-row gap-2 p-4 w-full min-w-[900px] shadow-none justify-between">
139134
<Label>{t('proxy.stats.tunnel_traffic', { name: proxyInfo.name })}</Label>
140-
<ProxyTrafficOverview proxyInfo={proxyInfo} />
141-
<div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4'>
142-
<ProxyTrafficPieChart
143-
title={t('proxy.stats.today_traffic_title')}
144-
chartLabel={t('proxy.stats.today_traffic_total')}
145-
trafficIn={proxyInfo.todayTrafficIn || BigInt(0)}
146-
trafficOut={proxyInfo.todayTrafficOut || BigInt(0)} />
147-
<ProxyTrafficPieChart
148-
title={t('proxy.stats.history_traffic_title')}
149-
chartLabel={t('proxy.stats.history_traffic_total')}
150-
trafficIn={proxyInfo.historyTrafficIn || BigInt(0)}
151-
trafficOut={proxyInfo.historyTrafficOut || BigInt(0)} />
152-
</div>
153-
</div>
135+
<Separator orientation="vertical" />
136+
<ProxyTrafficField label={t('traffic.today.total')} value={formatBytes(Number(proxyInfo.todayTrafficOut || BigInt(0)))} />
137+
<ProxyTrafficField label={t('traffic.today.inbound')} value={formatBytes(Number(proxyInfo.todayTrafficIn || BigInt(0)))} />
138+
<ProxyTrafficField label={t('traffic.today.outbound')} value={formatBytes(Number(proxyInfo.todayTrafficOut || BigInt(0)))} />
139+
<Separator orientation="vertical" />
140+
<ProxyTrafficField label={t('traffic.history.total')} value={formatBytes(Number(proxyInfo.historyTrafficOut || BigInt(0)))} />
141+
<ProxyTrafficField label={t('traffic.history.inbound')} value={formatBytes(Number(proxyInfo.historyTrafficIn || BigInt(0)))} />
142+
<ProxyTrafficField label={t('traffic.history.outbound')} value={formatBytes(Number(proxyInfo.historyTrafficOut || BigInt(0)))} />
143+
</Card>
154144
);
145+
}
146+
147+
const ProxyTrafficField = ({ label, value }: { label: string, value: string }) => {
148+
return <div className="flex w-fit flex-col">
149+
<p className="text-xs text-muted-foreground text-nowrap">{label}</p>
150+
<div className="flex items-center text-xs font-semibold text-nowrap">{value}</div>
151+
</div>
155152
}

0 commit comments

Comments
 (0)