Skip to content

Commit 30d5608

Browse files
committed
- cleaned up the project
- added release script
1 parent 7c078fa commit 30d5608

File tree

7 files changed

+85
-25
lines changed

7 files changed

+85
-25
lines changed

.dockerignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ config.yaml
55
mock_test.go
66
*.db
77
.run
8-
example.yaml
8+
example.yaml
9+
release
10+
release.sh

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
config.yaml
44
mock_test.go
55
*.db
6-
.run
6+
.run
7+
release

.one

-6
This file was deleted.

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module github.com/exelban/JAM
33
go 1.23
44

55
require (
6-
github.com/pkgz/service v0.0.10
6+
github.com/jessevdk/go-flags v1.6.1
7+
github.com/pkgz/logg v0.3.3
78
github.com/stretchr/testify v1.9.0
89
go.etcd.io/bbolt v1.3.11
910
go.mongodb.org/mongo-driver v1.17.0
@@ -13,13 +14,11 @@ require (
1314

1415
require (
1516
github.com/davecgh/go-spew v1.1.1 // indirect
16-
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
1717
github.com/golang/snappy v0.0.4 // indirect
18-
github.com/jessevdk/go-flags v1.6.1 // indirect
1918
github.com/klauspost/compress v1.17.9 // indirect
19+
github.com/kr/pretty v0.1.0 // indirect
2020
github.com/kr/text v0.2.0 // indirect
2121
github.com/montanaflynn/stats v0.7.1 // indirect
22-
github.com/pkgz/logg v0.3.3 // indirect
2322
github.com/pmezard/go-difflib v1.0.0 // indirect
2423
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
2524
github.com/xdg-go/scram v1.1.2 // indirect
@@ -28,5 +27,6 @@ require (
2827
golang.org/x/crypto v0.26.0 // indirect
2928
golang.org/x/sys v0.24.0 // indirect
3029
golang.org/x/text v0.17.0 // indirect
30+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
3131
gopkg.in/yaml.v3 v3.0.1 // indirect
3232
)

go.sum

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4-
github.com/go-jose/go-jose/v4 v4.0.4 h1:VsjPI33J0SB9vQM6PLmNjoHqMQNGPiZ0rHL7Ni7Q6/E=
5-
github.com/go-jose/go-jose/v4 v4.0.4/go.mod h1:NKb5HO1EZccyMpiZNbdUw/14tiXNyUJh188dfnMCAfc=
64
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
75
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
86
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@@ -13,14 +11,14 @@ github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2
1311
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
1412
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
1513
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
14+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
15+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
1616
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1717
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1818
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
1919
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
2020
github.com/pkgz/logg v0.3.3 h1:KGEmdLenbTmK1pQTwfn0d4KznaeJW6hzJv7CldaKRmI=
2121
github.com/pkgz/logg v0.3.3/go.mod h1:rSIxJi1hTXyN0ZZFFWQWH8eihavcKX14vK6V+yGcSZA=
22-
github.com/pkgz/service v0.0.10 h1:v0XGW+NplQvHDWh4PYGrarmXjpniHnEWBNvmOBjqKAI=
23-
github.com/pkgz/service v0.0.10/go.mod h1:tM468W+3gaQf1U85OWncDO/5kytPINf5089AMpNCczI=
2422
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2523
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2624
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=

main.go

+27-9
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ import (
99
"github.com/exelban/JAM/pkg/monitor"
1010
"github.com/exelban/JAM/store"
1111
"github.com/exelban/JAM/types"
12-
"github.com/pkgz/service"
12+
"github.com/jessevdk/go-flags"
13+
"github.com/pkgz/logg"
1314
"log"
1415
"os"
16+
"os/signal"
17+
"syscall"
1518
)
1619

17-
type args struct {
20+
type arguments struct {
1821
ConfigPath string `long:"config-path" env:"CONFIG_PATH" default:"./config.yaml" description:"path to the configuration file"`
19-
service.ARGS
22+
Port int `long:"port" env:"PORT" default:"8822" description:"service rest port"`
23+
Debug bool `long:"debug" env:"DEBUG" description:"debug mode"`
2024
}
2125

2226
type app struct {
@@ -26,7 +30,7 @@ type app struct {
2630
config *types.Cfg
2731
store store.Interface
2832

29-
args args
33+
args arguments
3034
}
3135

3236
//go:embed templates/*
@@ -37,13 +41,27 @@ const version = "v0.0.0"
3741
func main() {
3842
log.Printf("uptime %s", version)
3943

40-
var args args
41-
ctx, _, err := service.Init(&args)
42-
if err != nil {
43-
fmt.Printf("error init: %v", err)
44+
var args arguments
45+
p := flags.NewParser(&args, flags.Default)
46+
if _, err := p.Parse(); err != nil {
47+
fmt.Printf("error parse args: %v", err)
4448
os.Exit(1)
4549
}
4650

51+
ctx, cancel := context.WithCancel(context.Background())
52+
go func() {
53+
stop := make(chan os.Signal, 1)
54+
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
55+
<-stop
56+
log.Print("[INFO] interrupt signal")
57+
cancel()
58+
}()
59+
60+
logg.NewGlobal(os.Stdout)
61+
if args.Debug {
62+
logg.DebugMode()
63+
}
64+
4765
app, err := create(ctx, args)
4866
if err != nil {
4967
log.Printf("[ERROR] create app: %v", err)
@@ -56,7 +74,7 @@ func main() {
5674
}
5775
}
5876

59-
func create(ctx context.Context, args args) (*app, error) {
77+
func create(ctx context.Context, args arguments) (*app, error) {
6078
log.Printf("[DEBUG] %+v", args)
6179

6280
cfg, err := types.NewConfig(ctx, args.ConfigPath)

release.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
version="v0.0.0"
6+
7+
build_darwin() {
8+
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_darwin_x86_64.tar.gz -C bin jam && rm bin/jam
9+
GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_darwin_arm64.tar.gz -C bin jam && rm bin/jam
10+
}
11+
build_linux() {
12+
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_linux_x86_64.tar.gz -C bin jam && rm bin/jam
13+
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_linux_arm64.tar.gz -C bin jam && rm bin/jam
14+
}
15+
build_windows() {
16+
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_windows_x86_64.tar.gz -C bin jam && rm bin/jam
17+
GOOS=windows GOARCH=arm64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_windows_arm64.tar.gz -C bin jam && rm bin/jam
18+
}
19+
20+
build_docker_hub() {
21+
docker buildx build --push --platform=linux/amd64,linux/arm64 --tag=exelban/jam:"$version" .
22+
docker buildx build --push --platform=linux/amd64,linux/arm64 --tag=exelban/jam:latest .
23+
}
24+
build_github_registry() {
25+
docker buildx build --push --platform=linux/amd64,linux/arm64 --tag=ghcr.io/exelban/jam:"$version" .
26+
docker buildx build --push --platform=linux/amd64,linux/arm64 --tag=ghcr.io/exelban/jam:latest .
27+
}
28+
29+
printf "\033[32;1m%s\033[0m\n" "Building docker image with version ${version}..."
30+
build_docker_hub
31+
build_github_registry
32+
33+
printf "\033[32;1m%s\033[0m\n" "Building precompiled binaries with version ${version}..."
34+
35+
rm -rf "bin" && rm -rf "release"
36+
mkdir -p "release"
37+
38+
echo "Building darwin..."
39+
build_darwin
40+
echo "Building linux..."
41+
build_linux
42+
echo "Building windows..."
43+
build_windows
44+
rm -rf "bin"
45+
46+
printf "\033[32;1m%s\033[0m\n" "JAM ${version} was successfully build."
47+
open release

0 commit comments

Comments
 (0)