Skip to content

Commit fd671f8

Browse files
authored
feat: add build isntruction (#9)
1 parent bd199e1 commit fd671f8

18 files changed

Lines changed: 162 additions & 113 deletions

File tree

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ FROM scratch
77
WORKDIR /bin
88

99
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
10-
COPY /bin/easyp easyp
10+
COPY /bin/easyp-server easyp-server
1111

12-
ENTRYPOINT ["easyp"]
12+
ENTRYPOINT ["easyp-server"]

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1-
# Server
1+
# easyp-server
2+
3+
TODO:
4+
5+
* Provide an example of a proxy setup
6+
* Elaborate on the roadmap
7+
8+
A backward-compatible server for working with the CLI tool [buf](https://github.com/bufbuild/buf).
9+
10+
## Features
11+
12+
* Support for the package manager with `buf mod update`
13+
14+
## Installation
15+
16+
### Steps
17+
18+
#### Repository Setup
19+
20+
```bash
21+
wget https://github.com/easyp-tech/server/blob/main/scripts/clone_repos.sh -O clone_repos.sh
22+
23+
chmod +x clone_repos.sh
24+
25+
./clone_repos.sh https://github.com/googleapis/googleapis.git https://github.com/bufbuild/protovalidate.git
26+
```
27+
28+
#### Service Configuration
29+
30+
Create a service configuration file, replace easyp.tech with your domain:
31+
32+
```yaml
33+
server:
34+
external:
35+
domain: "easyp.tech"
36+
host: "0.0.0.0"
37+
port:
38+
connect: 8080
39+
metric: 8081
40+
storage:
41+
root: "/cache"
42+
```
43+
44+
#### Docker Compose Setup
45+
46+
```yaml
47+
version: "3.9"
48+
49+
services:
50+
51+
easyp:
52+
image: easyp/server:v0.1.0
53+
restart: always
54+
command: [
55+
"-cfg=/config.yml",
56+
]
57+
volumes:
58+
- "./config.yml:/config.yml"
59+
- "./easyp_volume:/cache/"
60+
```

cmd/easyp/local.config.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
dev_mode: true
21
server:
32
external:
43
domain: "127.0.0.1:8080"
@@ -8,6 +7,3 @@ server:
87
metric: 8081
98
storage:
109
root: "../cache"
11-
urls:
12-
- "https://github.com/bufbuild/protoc-gen-validate.git"
13-
- "https://github.com/RussianInvestments/invest-api-go-sdk.git"

cmd/easyp/main.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/signal"
99
"path/filepath"
10+
"strings"
1011
"syscall"
1112
"time"
1213

@@ -15,10 +16,11 @@ import (
1516
"golang.org/x/exp/slog"
1617
"google.golang.org/grpc/grpclog"
1718

19+
"github.com/easyp-tech/server/internal/logger"
20+
1821
"github.com/easyp-tech/server/internal/api"
1922
"github.com/easyp-tech/server/internal/core"
2023
"github.com/easyp-tech/server/internal/grpchelper"
21-
"github.com/easyp-tech/server/internal/logkey"
2224
"github.com/easyp-tech/server/internal/metrics"
2325
"github.com/easyp-tech/server/internal/serve"
2426
"github.com/easyp-tech/server/internal/store"
@@ -27,9 +29,8 @@ import (
2729
type (
2830
//nolint:tagliatelle
2931
config struct {
30-
DevMode bool `json:"dev_mode"`
31-
Server server `json:"server"`
32-
Store storage `json:"storage"`
32+
Server server `json:"server"`
33+
Store storage `json:"storage"`
3334
}
3435
server struct {
3536
External external `json:"external"`
@@ -44,8 +45,7 @@ type (
4445
Port ports `json:"port"`
4546
}
4647
storage struct {
47-
Root string `json:"root"`
48-
URLS []string `json:"urls"`
48+
Root string `json:"root"`
4949
}
5050
)
5151

@@ -60,9 +60,9 @@ func main() {
6060

6161
grpclog.SetLoggerV2(grpchelper.NewLogger(log))
6262

63-
appName := filepath.Base(os.Args[0])
63+
appName := strings.Replace(filepath.Base(os.Args[0]), "-", "_", -1)
6464

65-
ctxParent := logkey.NewContext(context.Background(), log)
65+
ctxParent := logger.NewContext(context.Background(), log)
6666

6767
ctx, cancel := signal.NotifyContext(
6868
ctxParent,
@@ -77,34 +77,30 @@ func main() {
7777
go forceShutdown(ctx)
7878

7979
if err := start(ctx, cfg, appName); err != nil {
80-
log.Error("shutdown", slog.String(logkey.Error, err.Error()))
80+
log.Error("shutdown", slog.String(logger.Error, err.Error()))
8181
os.Exit(1)
8282
}
8383
}
8484

8585
func start(ctx context.Context, cfg config, namespace string) error {
86-
log := logkey.FromContext(ctx)
86+
log := logger.FromContext(ctx)
8787
reg := prometheus.NewPedanticRegistry()
8888
m := metrics.New(reg, namespace)
8989

90-
s, err := store.New(ctx, cfg.Store.Root, cfg.Store.URLS)
91-
if err != nil {
92-
return fmt.Errorf("store.New: %w", err)
93-
}
94-
90+
s := store.New(ctx, cfg.Store.Root)
9591
module := core.New(s)
9692
_, httpAPI := api.New(ctx, m, module, reg, namespace, cfg.Server.External.Domain)
9793

9894
return serve.Start( //nolint:wrapcheck
9995
ctx,
10096
serve.Metrics(
101-
log.With(slog.String(logkey.Module, "metric")),
97+
log.With(slog.String(logger.Module, "metric")),
10298
cfg.Server.External.Host,
10399
cfg.Server.External.Port.Metric,
104100
reg,
105101
),
106102
serve.HTTP(
107-
log.With(slog.String(logkey.Module, "gRPC-Gateway")),
103+
log.With(slog.String(logger.Module, "connect")),
108104
cfg.Server.External.Host,
109105
cfg.Server.External.Port.Connect,
110106
httpAPI,
@@ -113,7 +109,7 @@ func start(ctx context.Context, cfg config, namespace string) error {
113109
}
114110

115111
func forceShutdown(ctx context.Context) {
116-
log := logkey.FromContext(ctx)
112+
log := logger.FromContext(ctx)
117113

118114
const shutdownDelay = 15 * time.Second
119115

stage/Caddyfile renamed to example/Caddyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
}
1414

15-
https://stage.easyp.tech {
15+
https://easyp.tech {
1616
handle {
1717
root * /build
1818
try_files {path} /index.html

example/config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server:
2+
external:
3+
domain: "easyp.tech"
4+
host: "0.0.0.0"
5+
port:
6+
connect: 8080
7+
metric: 8081
8+
storage:
9+
root: "/cache"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ volumes:
66
services:
77

88
easyp:
9-
image: cr.yandex/crplga9vcvsvk4uv6541/easyp:stage
9+
image: easyp/server:v0.1.0
1010
restart: always
1111
command: [
1212
"-cfg=/config.yml",

internal/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
registryv1alpha1connect "github.com/easyp-tech/server/gen/proto/buf/alpha/registry/v1alpha1/v1alpha1connect"
1515
"github.com/easyp-tech/server/internal/core"
1616
"github.com/easyp-tech/server/internal/grpchelper"
17-
"github.com/easyp-tech/server/internal/logkey"
17+
"github.com/easyp-tech/server/internal/logger"
1818
"github.com/easyp-tech/server/internal/metrics"
1919
)
2020

@@ -39,7 +39,7 @@ func New(
3939
namespace,
4040
domain string,
4141
) (*grpc.Server, *http.ServeMux) {
42-
log := logkey.FromContext(ctx)
42+
log := logger.FromContext(ctx)
4343
subsystem := "api"
4444

4545
grpcMetrics := grpchelper.NewServerMetrics(reg, namespace, subsystem)

internal/grpchelper/grpc_logs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import (
99
"golang.org/x/exp/slog"
1010
"google.golang.org/grpc/codes"
1111

12-
"github.com/easyp-tech/server/internal/logkey"
12+
"github.com/easyp-tech/server/internal/logger"
1313
"github.com/easyp-tech/server/internal/metrics"
1414
)
1515

1616
func recoveryFunc(m metrics.Metrics, err error) grpc_recovery.RecoveryHandlerFuncContext {
1717
return func(ctx context.Context, p interface{}) error {
1818
m.PanicsTotal.Inc()
1919

20-
l := logkey.FromContext(ctx)
20+
l := logger.FromContext(ctx)
2121
l.Error("panic",
22-
slog.String(logkey.GRPCCode, codes.Internal.String()),
23-
slog.Any(logkey.PanicReason, p),
22+
slog.String(logger.GRPCCode, codes.Internal.String()),
23+
slog.Any(logger.PanicReason, p),
2424
)
2525

2626
return err

internal/grpchelper/logger.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,70 @@ import (
88
"google.golang.org/grpc/grpclog"
99
)
1010

11-
var _ grpclog.LoggerV2 = (*logger)(nil)
11+
var _ grpclog.LoggerV2 = (*grpcLogger)(nil)
1212

1313
// NewLogger returns new grpclog Logger.
14-
func NewLogger(l *slog.Logger) *logger {
15-
return &logger{l: l}
14+
func NewLogger(l *slog.Logger) *grpcLogger {
15+
return &grpcLogger{l: l}
1616
}
1717

18-
type logger struct {
18+
type grpcLogger struct {
1919
l *slog.Logger
2020
}
2121

22-
func (l *logger) Info(args ...any) {
22+
func (l *grpcLogger) Info(args ...any) {
2323
l.l.Info(fmt.Sprint(args...))
2424
}
2525

26-
func (l *logger) Infoln(args ...any) {
26+
func (l *grpcLogger) Infoln(args ...any) {
2727
l.l.Info(fmt.Sprint(args...))
2828
}
2929

30-
func (l *logger) Infof(format string, args ...any) {
30+
func (l *grpcLogger) Infof(format string, args ...any) {
3131
l.l.Info(fmt.Sprintf(format, args...))
3232
}
3333

34-
func (l *logger) Warning(args ...any) {
34+
func (l *grpcLogger) Warning(args ...any) {
3535
l.l.Warn(fmt.Sprint(args...))
3636
}
3737

38-
func (l *logger) Warningln(args ...any) {
38+
func (l *grpcLogger) Warningln(args ...any) {
3939
l.l.Warn(fmt.Sprint(args...))
4040
}
4141

42-
func (l *logger) Warningf(format string, args ...any) {
42+
func (l *grpcLogger) Warningf(format string, args ...any) {
4343
l.l.Warn(fmt.Sprintf(format, args...))
4444
}
4545

46-
func (l *logger) Error(args ...any) {
46+
func (l *grpcLogger) Error(args ...any) {
4747
l.l.Error(fmt.Sprint(args...))
4848
}
4949

50-
func (l *logger) Errorln(args ...any) {
50+
func (l *grpcLogger) Errorln(args ...any) {
5151
l.l.Error(fmt.Sprint(args...))
5252
}
5353

54-
func (l *logger) Errorf(format string, args ...any) {
54+
func (l *grpcLogger) Errorf(format string, args ...any) {
5555
l.l.Error(fmt.Sprintf(format, args...))
5656
}
5757

58-
func (l *logger) Fatal(args ...any) {
58+
func (l *grpcLogger) Fatal(args ...any) {
5959
l.fatal(fmt.Sprint(args...))
6060
}
6161

62-
func (l *logger) Fatalln(args ...any) {
62+
func (l *grpcLogger) Fatalln(args ...any) {
6363
l.fatal(fmt.Sprint(args...))
6464
}
6565

66-
func (l *logger) Fatalf(format string, args ...any) {
66+
func (l *grpcLogger) Fatalf(format string, args ...any) {
6767
l.fatal(fmt.Sprintf(format, args...))
6868
}
6969

70-
func (l *logger) V(_ int) bool {
70+
func (l *grpcLogger) V(_ int) bool {
7171
return true
7272
}
7373

74-
func (l *logger) fatal(msg string) {
74+
func (l *grpcLogger) fatal(msg string) {
7575
l.l.Error(msg)
7676
os.Exit(1)
7777
}

0 commit comments

Comments
 (0)