Skip to content

Commit de14104

Browse files
authored
Experemental (#24)
go native sqlite dockerfile go releaser cli
1 parent 796988c commit de14104

File tree

12 files changed

+389
-34
lines changed

12 files changed

+389
-34
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.idea
2-
bin
2+
dist
3+
4+
dist/

.goreleaser.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
before:
4+
hooks:
5+
- go mod tidy
6+
builds:
7+
- env:
8+
- CGO_ENABLED=0
9+
ldflags:
10+
- -s -w -X main.version={{ .Version }}
11+
goos:
12+
- linux
13+
- windows
14+
- darwin
15+
goarch:
16+
- amd64
17+
- arm
18+
- arm64
19+
goarm:
20+
- 6
21+
- 7
22+
ignore:
23+
- goos: windows
24+
goarch: arm
25+
goarm: 7
26+
- goos: windows
27+
goarch: arm
28+
goarm: 6
29+
- goos: windows
30+
goarch: arm64
31+
changelog:
32+
sort: asc
33+
filters:
34+
exclude:
35+
- '^docs:'
36+
- '^test:'
37+
release:
38+
github:
39+
owner: mikekonan
40+
name: freqtrade-proxy
41+
draft: true
42+
name_template: "{{.ProjectName}}-v{{.Version}}"
43+

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ RUN cd /src && go build -o /src/bin/proxy
88

99
FROM alpine:3.15
1010

11+
RUN adduser -g "proxy" -D -H proxy proxy
12+
1113
RUN apk --no-cache add ca-certificates \
1214
&& rm -rf /var/cache/apk/*
1315

1416
COPY --from=builder /src/bin/proxy /bin/proxy
1517

18+
USER proxy
19+
1620
EXPOSE 8080
1721

1822
ENTRYPOINT ["/bin/proxy"]

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
.DEFAULT_GOAL := help
44

55
build-local:
6-
go build -trimpath -o ./bin/freqtrade-proxy
6+
go build -trimpath -o ./dist/freqtrade-proxy
77

88
build: ## build binaries
9-
go build -trimpath -o ./bin/freqtrade-proxy-darwin-amd64
9+
go build -trimpath -o ./dist/freqtrade-proxy-darwin-amd64
1010
for arch in "linux/amd64" "linux/arm/v6" "linux/arm/v7" "linux/arm64" ; do \
1111
echo $${arch//\//-}; \
12-
docker run --platform $$arch -v $(PWD):/tmp/src golang:buster /bin/bash -c "cd /tmp/src && go build -trimpath -o ./bin/freqtrade-proxy-"$${arch//\//-} ;\
12+
docker run --platform $$arch -v $(PWD):/tmp/src golang:buster /bin/bash -c "cd /tmp/src && go build -trimpath -o ./dist/freqtrade-proxy-"$${arch//\//-} ;\
1313
done
1414

1515
clean: ## clean
16-
rm ./bin/freqtrade-proxy*
16+
rm ./dist/freqtrade-proxy*
1717

1818
help:
1919
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

bin/.gitkeep

Whitespace-only changes.

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
--strategy SampleStrategy
1616
1717
freqtrade-proxy:
18-
image: mikekonan/freqtrade-proxy:main
18+
image: mikekonan/freqtrade-proxy:main-amd64
1919
restart: unless-stopped
2020
command: -verbose 1
2121
container_name: freqtrade-proxy

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ require (
88
github.com/doug-martin/goqu/v9 v9.16.0
99
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
1010
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible // indirect
11+
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
1112
github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f // indirect
13+
github.com/jaffee/commandeer v0.5.0
1214
github.com/jmoiron/sqlx v1.3.4
13-
github.com/mattn/go-sqlite3 v1.14.8
1415
github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87
1516
github.com/sirupsen/logrus v1.4.1
16-
github.com/spf13/cast v1.1.0
17+
github.com/spf13/cast v1.3.0
1718
github.com/valyala/fasthttp v1.29.0
1819
go.uber.org/ratelimit v0.2.0
1920
go4.org v0.0.0-20201209231011-d4a079459e60
21+
modernc.org/sqlite v1.14.2
2022
)

go.sum

Lines changed: 230 additions & 4 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,70 @@
11
package main
22

33
import (
4-
"flag"
4+
"fmt"
55
"os"
66

7-
"github.com/Gurpartap/logrus-stack"
7+
logrus_stack "github.com/Gurpartap/logrus-stack"
8+
"github.com/jaffee/commandeer"
89
"github.com/mikekonan/freqtradeProxy/proxy/kucoin"
910
"github.com/mikekonan/freqtradeProxy/store"
1011
"github.com/sirupsen/logrus"
1112
)
1213

13-
func main() {
14-
logrus.SetOutput(os.Stdout)
15-
logrus.AddHook(logrus_stack.StandardHook())
14+
var version = "dev"
1615

17-
port := flag.Int("port", 8080, "listen port")
18-
verbose := flag.Int("verbose", 0, "verbose level. 0 - info [default]. 1 - debug. 2 - trace.")
19-
flag.Parse()
16+
type app struct {
17+
Config kucoin.Config `flag:"!embed"`
18+
Verbose int `help:"verbose level: 0 - info, 1 - debug, 2 - trace"`
19+
}
20+
21+
func newApp() *app {
22+
return &app{
23+
Verbose: 0,
24+
Config: kucoin.Config{
25+
Port: "8080",
26+
Bindaddr: "0.0.0.0",
27+
},
28+
}
29+
}
2030

21-
switch *verbose {
31+
func (m *app) configure() {
32+
switch m.Verbose {
2233
case 0:
2334
logrus.SetLevel(logrus.InfoLevel)
2435
case 1:
2536
logrus.SetLevel(logrus.DebugLevel)
2637
case 2:
2738
logrus.SetLevel(logrus.TraceLevel)
2839
}
40+
}
41+
42+
func (a *app) Run() error {
43+
logrus.SetOutput(os.Stdout)
44+
logrus.AddHook(logrus_stack.StandardHook())
45+
46+
logrus.Infof("freqtrade-proxy version - %s", version)
2947

30-
s := store.New()
31-
k := kucoin.New(s)
32-
k.Start(*port)
48+
if a.Verbose > 2 {
49+
return fmt.Errorf("wrong verbose level '%d'", a.Verbose)
50+
}
51+
52+
a.configure()
53+
54+
if err := a.Config.Validate(); err != nil {
55+
return err
56+
}
57+
58+
k := kucoin.New(store.New(), a.Config)
59+
k.Start()
60+
61+
return nil
62+
}
63+
64+
func main() {
65+
app := newApp()
66+
67+
if err := commandeer.Run(app); err != nil {
68+
logrus.Fatal(err)
69+
}
3370
}

proxy/kucoin/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package kucoin
2+
3+
import (
4+
"github.com/go-ozzo/ozzo-validation/v4"
5+
"github.com/go-ozzo/ozzo-validation/v4/is"
6+
)
7+
8+
type Config struct {
9+
Port string `help:"listen port"`
10+
Bindaddr string `help:"bindable address"`
11+
//Localaddr string `help:"local address (use it if you understand what you are doing)"`
12+
}
13+
14+
func (c Config) Validate() error {
15+
return validation.ValidateStruct(&c,
16+
validation.Field(&c.Port, is.Port),
17+
validation.Field(&c.Bindaddr, is.IPv4),
18+
//validation.Field(&c.Localaddr, validation.When(c.Localaddr != "", is.IPv4)),
19+
)
20+
}

0 commit comments

Comments
 (0)