Skip to content

Commit

Permalink
ci: ko build
Browse files Browse the repository at this point in the history
  • Loading branch information
VaalaCat committed Dec 24, 2024
1 parent c80788b commit 2a13317
Show file tree
Hide file tree
Showing 17 changed files with 295 additions and 131 deletions.
30 changes: 8 additions & 22 deletions .github/workflows/latest.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,13 @@ jobs:
automatic_release_tag: latest
files: |
dist/*
build-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
- name: Setup ko
uses: ko-build/[email protected]
env:
KO_DOCKER_REPO: docker.io/vaalacat/frp-panel
- env:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile.standalone
push: true
platforms: linux/amd64,linux/arm64
tags: vaalacat/frp-panel:latest
run: |
echo "${password}" | ko login docker.io --username ${username} --password-stdin
ko build ./cmd/frpp --bare
36 changes: 9 additions & 27 deletions .github/workflows/tag.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,14 @@ jobs:
automatic_release_tag: ${{ steps.get_version.outputs.VERSION }}
files: |
dist/*
build-docker:
runs-on: ubuntu-latest
steps:
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get git tag history
run: git fetch -a
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
- name: Setup ko
uses: ko-build/[email protected]
env:
KO_DOCKER_REPO: docker.io/vaalacat/frp-panel
- name: Build image with ko
env:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile.standalone
push: true
platforms: linux/amd64,linux/arm64
tags: vaalacat/frp-panel:${{ steps.get_version.outputs.VERSION }}
run: |
echo "${password}" | ko login docker.io --username ${username} --password-stdin
ko build ./cmd/frpp --bare -t ${{ steps.get_version.outputs.VERSION }}
16 changes: 16 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defaultBaseImage: alpine

builds:
- id: frpp
dir: .
main: ./cmd/frpp
ldflags:
- -s -w
- -X github.com/VaalaCat/frp-panel/conf.buildDate={{.Date}}
- -X github.com/VaalaCat/frp-panel/conf.gitCommit={{.Git.FullCommit}}
- -X github.com/VaalaCat/frp-panel/conf.gitVersion={{.Git.Tag}}
- -X github.com/VaalaCat/frp-panel/conf.gitBranch={{.Git.Branch}}

defaultPlatforms:
- linux/arm64
- linux/amd64
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ARCH="all"
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
GIT_COMMIT="$(git rev-parse HEAD)"
VERSION="$(git describe --tags --abbrev=0 | tr -d '\n')"
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"

# Parse arguments
while [[ "$#" -gt 0 ]]; do
Expand Down Expand Up @@ -50,7 +51,7 @@ echo "Build Date: $BUILD_DATE"
echo "Git Commit: $GIT_COMMIT"
echo "Version: $VERSION"

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}'"
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}'"

if [[ "$SKIP_FRONTEND" == "true" ]]; then
echo "Skipping frontend build"
Expand Down
11 changes: 11 additions & 0 deletions cmd/frpp/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package main
import (
"context"
"fmt"
"os"

"github.com/VaalaCat/frp-panel/conf"
"github.com/VaalaCat/frp-panel/logger"
"github.com/VaalaCat/frp-panel/utils"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

var (
Expand Down Expand Up @@ -140,6 +142,7 @@ func initCommand() {
rootCmd.AddCommand(clientCmd, serverCmd, masterCmd, versionCmd,
installServiceCmd, uninstallServiceCmd,
startServiceCmd, stopServiceCmd, restartServiceCmd)

clientCmd.Flags().StringVarP(&clientSecret, "secret", "s", "", "client secret")
serverCmd.Flags().StringVarP(&clientSecret, "secret", "s", "", "client secret")
clientCmd.Flags().StringVarP(&clientID, "id", "i", "", "client id")
Expand Down Expand Up @@ -191,3 +194,11 @@ func patchConfig(host, secret, clientID, clientSecret, apiScheme string, rpcPort
conf.Get().Master.APIHost, conf.Get().Master.APIPort,
conf.Get().Master.APIScheme)
}

func setMasterCommandIfNonePresent() {
cmd, _, err := rootCmd.Find(os.Args[1:])
if err == nil && cmd.Use == rootCmd.Use && cmd.Flags().Parse(os.Args[1:]) != pflag.ErrHelp {
args := append([]string{"master"}, os.Args[1:]...)
rootCmd.SetArgs(args)
}
}
1 change: 1 addition & 0 deletions cmd/frpp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ func main() {
conf.InitConfig()
rpc.InitRPCClients()

setMasterCommandIfNonePresent()
rootCmd.Execute()
}
7 changes: 7 additions & 0 deletions cmd/frpp/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"embed"
"path/filepath"

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

switch conf.Get().DB.Type {
case "sqlite3":
if err := utils.EnsureDirectoryExists(conf.Get().DB.DSN); err != nil {
logrus.WithError(err).Warnf("ensure directory failed, data location: [%s], keep data in current directory", conf.Get().DB.DSN)
conf.Get().DB.DSN = filepath.Base(conf.Get().DB.DSN)
logrus.Infof("new data location: [%s]", conf.Get().DB.DSN)
}

if sqlitedb, err := gorm.Open(sqlite.Open(conf.Get().DB.DSN), &gorm.Config{}); err != nil {
logrus.Panic(err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion conf/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Config struct {
} `env-prefix:"SERVER_"`
DB struct {
Type string `env:"TYPE" env-default:"sqlite3" env-description:"db type, mysql or sqlite3 and so on"`
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"`
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"`
} `env-prefix:"DB_"`
Client struct {
ID string `env:"ID" env-description:"client id"`
Expand Down
4 changes: 4 additions & 0 deletions conf/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
var (
gitVersion = "dev-build"
gitCommit = ""
gitBranch = ""
buildDate = "1970-01-01T00:00:00Z"
)

type VersionInfo struct {
GitVersion string `json:"gitVersion" yaml:"gitVersion"`
GitCommit string `json:"gitCommit" yaml:"gitCommit"`
GitBranch string `json:"gitBranch" yaml:"gitBranch"`
BuildDate string `json:"buildDate" yaml:"buildDate"`
GoVersion string `json:"goVersion" yaml:"goVersion"`
Compiler string `json:"compiler" yaml:"compiler"`
Expand All @@ -42,6 +44,7 @@ func (v *VersionInfo) ToProto() *pb.ClientVersion {
return &pb.ClientVersion{
GitVersion: v.GitVersion,
GitCommit: v.GitCommit,
GitBranch: v.GitBranch,
BuildDate: v.BuildDate,
GoVersion: v.GoVersion,
Compiler: v.Compiler,
Expand All @@ -53,6 +56,7 @@ func GetVersion() *VersionInfo {
return &VersionInfo{
GitVersion: gitVersion,
GitCommit: gitCommit,
GitBranch: gitBranch,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Expand Down
1 change: 1 addition & 0 deletions idl/api_master.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ message ClientVersion {
string GoVersion = 4;
string Compiler = 5;
string Platform = 6;
string GitBranch = 7;
}

message GetClientsStatusRequest {
Expand Down
92 changes: 51 additions & 41 deletions pb/api_master.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions utils/files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package utils

import (
"os"
"path/filepath"
)

func EnsureDirectoryExists(filePath string) error {
directory := filepath.Dir(filePath)

if _, err := os.Stat(directory); os.IsNotExist(err) {
err = os.MkdirAll(directory, os.ModePerm)
if err != nil {
return err
}
}
return nil
}
Loading

0 comments on commit 2a13317

Please sign in to comment.