Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ae8a9be0f | ||
|
|
647e1b96b1 | ||
|
|
ca239fbce4 | ||
|
|
963c80aaa0 | ||
|
|
be344b97f7 | ||
|
|
59d23a2dc7 |
@@ -0,0 +1,83 @@
|
||||
name: Docker Build (Gitea)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- 'ci/**'
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: git.viaeon.com
|
||||
IMAGE: git.viaeon.com/admin/bepusdt
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
name: Build and Push Docker Image
|
||||
runs-on: ubuntu
|
||||
env:
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
|
||||
steps:
|
||||
- name: Install Docker CLI
|
||||
run: |
|
||||
if ! command -v docker &> /dev/null; then
|
||||
if command -v apk &> /dev/null; then
|
||||
apk add --no-cache docker-cli git
|
||||
elif command -v apt-get &> /dev/null; then
|
||||
apt-get update && apt-get install -y docker.io git
|
||||
else
|
||||
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp
|
||||
mv /tmp/docker/docker /usr/local/bin/
|
||||
chmod +x /usr/local/bin/docker
|
||||
fi
|
||||
fi
|
||||
docker --version
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Prepare version
|
||||
id: ver
|
||||
run: |
|
||||
SHORT_SHA=$(git rev-parse --short=7 HEAD)
|
||||
BASE=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||
# 分支名可能带斜杠(ci/xxx),docker tag 不允许,统一换成短横线
|
||||
REF_SLUG=$(echo "${GITHUB_REF_NAME}" | tr '/' '-')
|
||||
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
|
||||
echo "ref_slug=${REF_SLUG}" >> "$GITHUB_OUTPUT"
|
||||
echo "version=${BASE}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
|
||||
echo "VERSION=${BASE}-${SHORT_SHA}"
|
||||
|
||||
- name: Login to Gitea Container Registry
|
||||
run: |
|
||||
echo "${{ secrets.TOKEN }}" | docker login "${{ env.REGISTRY }}" -u "${{ github.actor }}" --password-stdin 2>&1
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
# latest 只给 main,特性分支别把 latest 顶掉
|
||||
TAGS="-t ${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }} -t ${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}"
|
||||
if [ "${GITHUB_REF_NAME}" = "main" ]; then TAGS="$TAGS -t ${{ env.IMAGE }}:latest"; fi
|
||||
docker build \
|
||||
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
|
||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
||||
--build-arg "VERSION=${{ steps.ver.outputs.version }}" \
|
||||
$TAGS .
|
||||
|
||||
- name: Push Docker image
|
||||
run: |
|
||||
docker push "${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}" 2>&1
|
||||
docker push "${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}" 2>&1
|
||||
if [ "${GITHUB_REF_NAME}" = "main" ]; then docker push "${{ env.IMAGE }}:latest" 2>&1; fi
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "镜像已推送:"
|
||||
echo " ${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}"
|
||||
echo " ${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}"
|
||||
echo " ${{ env.IMAGE }}:latest"
|
||||
@@ -16,6 +16,13 @@ var PostgresDSNFlag = &cli.StringFlag{
|
||||
Sources: cli.EnvVars("POSTGRESQL_DSN"),
|
||||
}
|
||||
|
||||
var MysqlDSNFlag = &cli.StringFlag{
|
||||
Name: "mysql",
|
||||
Value: "",
|
||||
Usage: "MySQL 数据库连接字符串 (DSN),例如: user:pass@tcp(127.0.0.1:3306)/bepusdt?charset=utf8mb4&parseTime=True&loc=Local&timeout=3s",
|
||||
Sources: cli.EnvVars("MYSQL_DSN"),
|
||||
}
|
||||
|
||||
var LogFlag = &cli.StringFlag{
|
||||
Name: "log",
|
||||
Value: "/var/log/bepusdt/",
|
||||
|
||||
+3
-2
@@ -15,11 +15,12 @@ import (
|
||||
var Reset = &cli.Command{
|
||||
Name: "reset",
|
||||
Usage: "忘记密码时,此命令可重置账号密码登录入口",
|
||||
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag},
|
||||
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag, MysqlDSNFlag},
|
||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||
sqlite := c.String("sqlite")
|
||||
postgres := c.String("postgres")
|
||||
if err := model.Init(sqlite, postgres); err != nil {
|
||||
mysql := c.String("mysql")
|
||||
if err := model.Init(sqlite, postgres, mysql); err != nil {
|
||||
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -27,11 +27,12 @@ import (
|
||||
var Start = &cli.Command{
|
||||
Name: "start",
|
||||
Usage: "启动收款网关",
|
||||
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag, LogFlag, ListenFlag},
|
||||
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag, MysqlDSNFlag, LogFlag, ListenFlag},
|
||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||
postgres := c.String("postgres")
|
||||
mysql := c.String("mysql")
|
||||
sqlite := c.String("sqlite")
|
||||
if err := model.Init(sqlite, postgres); err != nil {
|
||||
if err := model.Init(sqlite, postgres, mysql); err != nil {
|
||||
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
||||
}
|
||||
|
||||
|
||||
+50
-5
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/v03413/bepusdt/app/model/migration"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -24,12 +25,17 @@ type AutoTimeAt struct {
|
||||
UpdatedAt *Datetime `gorm:"column:updated_at;not null;comment:最后更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
func Init(db, dsn string) error {
|
||||
if dsn != "" {
|
||||
return initPostgres(dsn)
|
||||
// Init 按优先级选择数据库:MySQL DSN > PostgreSQL DSN > SQLite 文件。
|
||||
// 三者互斥,填了哪个用哪个;都不填就走 SQLite(默认)。
|
||||
func Init(db, postgresDSN, mysqlDSN string) error {
|
||||
switch {
|
||||
case mysqlDSN != "":
|
||||
return initMysql(mysqlDSN)
|
||||
case postgresDSN != "":
|
||||
return initPostgres(postgresDSN)
|
||||
default:
|
||||
return initSqlite(db)
|
||||
}
|
||||
|
||||
return initSqlite(db)
|
||||
}
|
||||
|
||||
func initSqlite(db string) error {
|
||||
@@ -147,3 +153,42 @@ func Close() {
|
||||
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("数据库资源关闭错误:%s", err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
func initMysql(dsn string) error {
|
||||
// 建议 DSN 里带上 charset=utf8mb4&parseTime=True&loc=Local,
|
||||
// 否则中文/时间字段会出问题:中文变 ?,时间按 UTC 存进去。
|
||||
Db, err = gorm.Open(mysql.New(mysql.Config{
|
||||
DSN: dsn,
|
||||
DefaultStringSize: 256,
|
||||
SkipInitializeWithVersion: false,
|
||||
}), &gorm.Config{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
{
|
||||
sqlDB, err := Db.DB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sqlDB.SetMaxIdleConns(10)
|
||||
sqlDB.SetMaxOpenConns(100)
|
||||
sqlDB.SetConnMaxLifetime(30 * time.Minute)
|
||||
sqlDB.SetConnMaxIdleTime(10 * time.Minute)
|
||||
}
|
||||
|
||||
if err = AutoMigrate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var count int64
|
||||
Db.Model(&Conf{}).Count(&count)
|
||||
if count == 0 {
|
||||
ConfInit()
|
||||
}
|
||||
|
||||
FillDefaultConf()
|
||||
RefreshC()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -79,8 +79,8 @@ type Order struct {
|
||||
Status int `gorm:"column:status;not null;default:1;index;index:idx_order_notify_retry,priority:1;comment:交易状态" json:"status"`
|
||||
Name string `gorm:"column:name;type:varchar(64);not null;default:'';comment:商品名称" json:"name"`
|
||||
ApiType string `gorm:"column:api_type;type:varchar(20);not null;default:'epusdt';comment:API类型" json:"api_type"`
|
||||
ReturnUrl string `gorm:"column:return_url;type:text;not null;default:'';comment:同步地址" json:"return_url"`
|
||||
NotifyUrl string `gorm:"column:notify_url;type:text;not null;default:'';comment:异步地址" json:"notify_url"`
|
||||
ReturnUrl string `gorm:"column:return_url;type:varchar(1024);not null;default:'';comment:同步地址" json:"return_url"`
|
||||
NotifyUrl string `gorm:"column:notify_url;type:varchar(1024);not null;default:'';comment:异步地址" json:"notify_url"`
|
||||
NotifyNum int `gorm:"column:notify_num;not null;default:0;index:idx_order_notify_retry,priority:3;comment:回调次数" json:"notify_num"`
|
||||
NotifyState int `gorm:"column:notify_state;not null;default:0;index:idx_order_notify_retry,priority:2;comment:回调状态 1:成功 0:失败" json:"notify_state"`
|
||||
RefHash string `gorm:"column:ref_hash;type:varchar(128);not null;default:'';index;comment:交易哈希" json:"ref_hash"`
|
||||
|
||||
@@ -27,6 +27,7 @@ require (
|
||||
github.com/xssnick/tonutils-go v1.17.2
|
||||
golang.org/x/crypto v0.51.0
|
||||
google.golang.org/grpc v1.81.0
|
||||
gorm.io/driver/mysql v1.6.0
|
||||
gorm.io/driver/postgres v1.6.0
|
||||
gorm.io/gorm v1.31.1
|
||||
)
|
||||
@@ -44,6 +45,7 @@ require (
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.30.2 // indirect
|
||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
||||
github.com/goccy/go-json v0.10.6 // indirect
|
||||
github.com/goccy/go-yaml v1.19.2 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
|
||||
@@ -78,6 +78,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.30.2 h1:JiFIMtSSHb2/XBUbWM4i/MpeQm9ZK2xqPNk8vgvu5JQ=
|
||||
github.com/go-playground/validator/v10 v10.30.2/go.mod h1:mAf2pIOVXjTEBrwUMGKkCWKKPs9NheYGabeB04txQSc=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/go-telegram/bot v1.20.0 h1:4Pea/qTidSspr4WBJw9FbHUMNhYeqszBqQUfsQEyFbc=
|
||||
github.com/go-telegram/bot v1.20.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
|
||||
github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU=
|
||||
@@ -315,6 +317,8 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
|
||||
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
|
||||
gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4=
|
||||
gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo=
|
||||
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
|
||||
|
||||
Reference in New Issue
Block a user