Rename ServerConfig->RouterConfig, smaller build fixes

master
René Jochum 2 years ago
parent 2237cb4785
commit 7fef5964da

6
.gitignore vendored

@ -1,5 +1,5 @@
.task/
.DS_STORE
!.gitkeep
.task/
.env
!.gitkeep

@ -19,7 +19,7 @@ It looks for services that host "proto/routerclientpb/routerclientpb.RouterClien
Have a look at [internalService](https://github.com/go-micro/router/blob/master/cmd/microrouterd/main.go#L35) or the author's FOSS project [microlobby](https://github.com/pcdummy/microlobby).
Here some code from the microlobby project
Here's some code from the microlobby project
```go
import (
"github.com/go-micro/router"
@ -82,20 +82,22 @@ func main() {
}
```
## Build podman/docker image
## Developers corner
### Prerequesits
### Build podman/docker image
#### Prerequesits
- podman
- [Task](https://taskfile.dev/#/installation)
### Build
#### Build
```bash
task
```
### Remove everything except the resulting podman images created by task
#### Remove everything except the resulting podman images created by task
```bash
task rm

@ -29,9 +29,9 @@ tasks:
deps:
- volume
cmds:
- podman build -v "{{.VOLUME_PATH}}:/go:rw" -t docker.io/pcdummy/go-micro-router-builder:latest -f ./docker/builder/Dockerfile .
- podman build -v "{{.VOLUME_PATH}}:/go:rw" -t docker.io/pcdummy/go-micro-router-builder:latest -f ./docker/builder/Dockerfile ./docker/builder/
sources:
- ./docker/builder/Dockerfile
- ./docker/builder/**/*
vars:
VOLUME_PATH:
sh: podman volume inspect micro_router_go --format "{{"{{"}}.Mountpoint{{"}}"}}"
@ -53,16 +53,13 @@ tasks:
cmds:
- task: builder
vars:
CLI_ARGS: /bin/sh -c 'cd ./internal/proto/routerclientpb; protoc --proto_path=/go/bin:. --micro_out=paths=source_relative:. --go_out=paths=source_relative:. routerclientpb.proto'
- task: builder
vars:
CLI_ARGS: /bin/sh -c 'cd ./internal/proto/routerserverpb; protoc --proto_path=/go/bin:. --micro_out=paths=source_relative:. --go_out=paths=source_relative:. routerserverpb.proto'
CLI_ARGS: /scripts/protoc_gen.sh
build:podman:
deps:
- protoc
cmds:
- podman build -v "$PWD:/code:rw" -v "{{.VOLUME_PATH}}:/go:rw" --build-arg CACHEBUST={{.DATE}} --build-arg VERSION={{.VERSION}} -t docker.io/pcdummy/go-micro-router:latest -f ./docker/go-micro-router/Dockerfile .
- podman build -v "$PWD:/code:rw" -v "{{.VOLUME_PATH}}:/go:rw" --build-arg CACHEBUST={{.DATE}} --build-arg VERSION={{.VERSION}} -t docker.io/pcdummy/go-micro-router:latest -f ./docker/router/Dockerfile .
vars:
DATE:
sh: date +%s
@ -103,7 +100,7 @@ tasks:
cmds:
- task: builder
vars:
CLI_ARGS: go get -u ./...
CLI_ARGS: /scripts/upgrade_deps.sh
rm:
desc: Remove all persistent data

@ -33,7 +33,7 @@ func internalService(engine *gin.Engine) {
routerserverpb.RegisterRouterServerServiceHandler(srv.Server(), routerHandler)
r := router.NewHandler(
config.GetServerConfig().RouterURI,
config.GetRouterConfig().RouterURI,
router.NewRoute(
router.Method(router.MethodGet),
router.Path("/routes"),
@ -68,7 +68,7 @@ func main() {
logger.Fatal(err)
}
if config.GetServerConfig().Env == config.EnvProd {
if config.GetRouterConfig().Env == config.EnvProd {
gin.SetMode(gin.ReleaseMode)
}
@ -76,7 +76,7 @@ func main() {
opts := []micro.Option{
micro.Name(config.Name),
micro.Version(config.Version),
micro.Address(config.GetServerConfig().Address),
micro.Address(config.GetRouterConfig().Address),
micro.Action(func(c *cli.Context) error {
r.Use(gin.Logger(), gin.Recovery())

@ -7,12 +7,14 @@ RUN apt-get update --allow-releaseinfo-change && \
cd /tmp && wget https://github.com/protocolbuffers/protobuf/releases/download/v21.5/protoc-21.5-linux-x86_64.zip && \
unzip protoc-21.5-linux-x86_64.zip -d /usr/local/ && chmod +x /usr/local/bin/protoc
VOLUME [ "/code", "/go" ]
# RUN go mod download
ENV GOPATH="/go"
VOLUME [ "/code", "/go" ]
# Install protoc-gen-go + protoc-gen-micro
RUN cd /tmp; go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28; go install github.com/go-micro/generator/cmd/protoc-gen-micro@v1.0.0
WORKDIR /code
WORKDIR /code
COPY ./scripts /scripts

@ -0,0 +1,2 @@
#!/bin/sh
find . -name '*.proto' -print0 | xargs -0 -I {} /bin/sh -c 'cd $(dirname $1); PATH=$PATH:/go/bin protoc --micro_out=paths=source_relative:. --go_out=paths=source_relative:. $(basename $1)' '_' '{}'

@ -0,0 +1,10 @@
#!/bin/bash
set -ex
go mod tidy -go=1.19
for i in $(find . -name 'main.go'); do
pushd $(dirname $i)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go get -installsuffix cgo -ldflags="-w -s" -u ./...
popd
done

@ -15,10 +15,10 @@ const (
)
type Config struct {
Server ServerConfig
Router RouterConfig
}
type ServerConfig struct {
type RouterConfig struct {
Env string
Address string
RouterURI string
@ -29,6 +29,6 @@ func GetConfig() Config {
return *_cfg
}
func GetServerConfig() ServerConfig {
return _cfg.Server
func GetRouterConfig() RouterConfig {
return _cfg.Router
}

@ -18,7 +18,7 @@ import (
// internal instance of Config
var _cfg *Config = &Config{
Server: ServerConfig{
Router: RouterConfig{
Env: EnvProd,
Address: ":8080",
RouterURI: "router",

@ -86,7 +86,7 @@ func (h *Handler) Start() error {
}
}
time.Sleep(time.Duration(config.GetServerConfig().RefreshSeconds) * time.Second)
time.Sleep(time.Duration(config.GetRouterConfig().RefreshSeconds) * time.Second)
}
}()

Loading…
Cancel
Save