diff --git a/CHANGELOG.md b/CHANGELOG.md index 19311e4..fa93c5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog +## 4.3.0 (2021-04-15) + +* Added configurable main table + ## 4.2.0 (2020-07-29) * Added GoBGP processing_timeout source config option diff --git a/Dockerfile b/Dockerfile index 48702aa..4453cfa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,22 +31,16 @@ ADD go.mod . ADD go.sum . RUN go mod download +ADD . . + # Add client COPY --from=frontend /src/alice-lg/client/build client/build -# Build backend -WORKDIR /src/alice-lg -ADD VERSION . -ADD go.mod go.sum . - -WORKDIR /src/alice-lg/backend -ADD backend . - -# RUN go build -o alice-lg-linux-amd64 -ldflags="-X main.version=4.0.3" +WORKDIR /src/alice-lg/cmd/alice-lg RUN make alpine FROM alpine:latest -COPY --from=backend /src/alice-lg/backend/alice-lg-linux-amd64 /usr/bin/alice-lg +COPY --from=backend /src/alice-lg/cmd/alice-lg/alice-lg-linux-amd64 /usr/bin/alice-lg RUN ls -lsha /usr/bin/alice-lg EXPOSE 7340:7340 diff --git a/Makefile b/Makefile index 5c91e71..0c720ea 100644 --- a/Makefile +++ b/Makefile @@ -35,15 +35,14 @@ client_dev: client_prod: $(MAKE) -C client/ client_prod - backend_prod: client_prod $(MAKE) -C cmd/alice-lg/ linux backend: $(MAKE) -C cmd/alice-lg/ linux -alice: client_prod backend_prod - mv backend/alice-lg-* bin/ +alice: backend_prod + cp cmd/alice-lg/alice-lg-* bin/ dist: clean alice diff --git a/Makefile.docker b/Makefile.docker new file mode 100644 index 0000000..0c64d01 --- /dev/null +++ b/Makefile.docker @@ -0,0 +1,16 @@ + +# Build a local alice binary using docker. + +DOCKER := docker + +all: alice + cp cmd/alice-lg/alice-lg-* bin/ + +client: + $(MAKE) -C client/ -f Makefile.docker client_prod + +alice: client + $(MAKE) -C cmd/alice-lg -f Makefile.docker + +.PHONY: client alice + diff --git a/README.md b/README.md index aae45a7..f5898dc 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ Take a look at an Alice-LG production examples at: And checkout the API at: - https://lg.de-cix.net/api/v1/config - https://lg.de-cix.net/api/v1/routeservers -- https://lg.de-cix.net/api/v1/routeservers/0/status -- https://lg.de-cix.net/api/v1/routeservers/0/neighbours -- https://lg.de-cix.net/api/v1/routeservers/0/neighbours/ID109_AS31078/routes +- https://lg.de-cix.net/api/v1/routeservers/rs1_fra_ipv4/status +- https://lg.de-cix.net/api/v1/routeservers/rs1_fra_ipv4/neighbors +- https://lg.de-cix.net/api/v1/routeservers/rs1_fra_ipv4/neighbors/R194_106/routes - https://lg.de-cix.net/api/v1/lookup/prefix?q=217.115.0.0 ## Explanations diff --git a/VERSION b/VERSION index 6aba2b2..cc2fbe8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.0 +4.3.2 diff --git a/client/Makefile.docker b/client/Makefile.docker index 7af9d03..8e2e0a9 100644 --- a/client/Makefile.docker +++ b/client/Makefile.docker @@ -1,7 +1,8 @@ +DOCKER := docker DOCKER_CONTAINER := alice-lg-node-build DOCKER_IMAGE := alice-lg-node:latest -DOCKER_EXEC := docker run --rm -t -i \ +DOCKER_EXEC := $(DOCKER) run --rm -t -i \ -a stdin -a stdout -a stderr \ -v `pwd`:/client/ \ --name $(DOCKER_CONTAINER) \ @@ -11,7 +12,7 @@ all: client @echo "Built alice-lg client" image: - docker build . -t $(DOCKER_IMAGE) + $(DOCKER) build . -t $(DOCKER_IMAGE) deps: image $(DOCKER_EXEC) "yarn install" @@ -29,12 +30,12 @@ watch: stop: @echo "Stopping docker container: $(DOCKER_CONTAINER)" - -docker stop $(DOCKER_CONTAINER) + -$(DOCKER) stop $(DOCKER_CONTAINER) @sleep 1 kill: @echo "Killing docker container: $(DOCKER_CONTAINER)" - -docker kill $(DOCKER_CONTAINER) + -$(DOCKER) kill $(DOCKER_CONTAINER) @sleep 1 diff --git a/cmd/alice-lg/Makefile b/cmd/alice-lg/Makefile index 7067099..616abbe 100644 --- a/cmd/alice-lg/Makefile +++ b/cmd/alice-lg/Makefile @@ -9,7 +9,6 @@ ARCH=amd64 APP_VERSION=$(shell cat ../../VERSION) VERSION=$(APP_VERSION)_$(shell git rev-parse --short HEAD) -LOCAL_RPMS=RPMS # OS Detection UNAME=$(shell uname) @@ -20,7 +19,9 @@ else endif -LDFLAGS=-ldflags="-X main.version=$(APP_VERSION)" +LDFLAGS=-ldflags="-X github.com/alice-lg/alice-lg/pkg/backend.Version=$(APP_VERSION)" +LDFLAGS_STATIC=-ldflags="-X github.com/alice-lg/alice-lg/pkg/backend.Version=$(APP_VERSION) -extldflags '-static'" + FILES=$(shell find . -depth 1 ! -name "*_test.go" -name "*.go") all: deps $(TARGET) @@ -43,11 +44,18 @@ alpine: -a -installsuffix cgo \ $(LDFLAGS) -o $(PROG)-linux-$(ARCH) +static: + GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) \ + go build $(CFLAGS) \ + -a $(LDFLAGS_STATIC) \ + -o $(PROG)-linux-$(ARCH) + + test: GO111MODULE=on go test -v - cd api/ && GO111MODULE=on go test -v - cd caches/ && GO111MODULE=on go test -v - cd sources/birdwatcher && GO111MODULE=on go test -v + cd ../../pkg/api/ && GO111MODULE=on go test -v + cd ../../pkg/caches/ && GO111MODULE=on go test -v + cd ../../pkg/sources/birdwatcher && GO111MODULE=on go test -v dev: clean all diff --git a/cmd/alice-lg/Makefile.docker b/cmd/alice-lg/Makefile.docker new file mode 100644 index 0000000..0ff99a0 --- /dev/null +++ b/cmd/alice-lg/Makefile.docker @@ -0,0 +1,20 @@ + +# +# Build alice using a dockerized go version +# + +DOCKER := docker + +DOCKER_CONTAINER := alice-lg-build +DOCKER_IMAGE := golang:1.16 + +DOCKER_EXEC := $(DOCKER) run --rm -t -i \ + -a stdin -a stdout -a stderr \ + -v `pwd`/../../:/src/alice-lg \ + --name $(DOCKER_CONTAINER) \ + --workdir /src/alice-lg/cmd/alice-lg \ + $(DOCKER_IMAGE) + +all: + $(DOCKER_EXEC) make static + diff --git a/etc/alice-lg/alice.example.conf b/etc/alice-lg/alice.example.conf index 59485c0..9591cd6 100644 --- a/etc/alice-lg/alice.example.conf +++ b/etc/alice-lg/alice.example.conf @@ -150,6 +150,8 @@ blackholes = 10.23.6.666, 10.23.6.665 api = http://rs1.example.com:29184/ # single_table / multi_table type = multi_table + +main_table = master4 # default is master in bird1x peer_table_prefix = T pipe_protocol_prefix = M # Timeout in seconds to wait for the status data (only required if enable_neighbors_status_refresh is true) diff --git a/pkg/backend/api_endpoints_neighbors.go b/pkg/backend/api_endpoints_neighbors.go index 6f775a8..4bcf564 100644 --- a/pkg/backend/api_endpoints_neighbors.go +++ b/pkg/backend/api_endpoints_neighbors.go @@ -29,7 +29,7 @@ func apiNeighborsList( // Make response neighborsResponse = &api.NeighboursResponse{ Api: api.ApiStatus{ - Version: version, + Version: Version, CacheStatus: api.CacheStatus{ OrigTtl: 0, CachedAt: sourceStatus.LastRefresh, diff --git a/pkg/backend/config.go b/pkg/backend/config.go index 723926f..5eec906 100644 --- a/pkg/backend/config.go +++ b/pkg/backend/config.go @@ -631,6 +631,7 @@ func getSources(config *ini.File) ([]*SourceConfig, error) { switch backendType { case SOURCE_BIRDWATCHER: sourceType := backendConfig.Key("type").MustString("") + mainTable := backendConfig.Key("main_table").MustString("master") peerTablePrefix := backendConfig.Key("peer_table_prefix").MustString("T") pipeProtocolPrefix := backendConfig.Key("pipe_protocol_prefix").MustString("M") @@ -653,6 +654,7 @@ func getSources(config *ini.File) ([]*SourceConfig, error) { ServerTimeExt: "Mon, 02 Jan 2006 15:04:05 -0700", Type: sourceType, + MainTable: mainTable, PeerTablePrefix: peerTablePrefix, PipeProtocolPrefix: pipeProtocolPrefix, } diff --git a/pkg/backend/status.go b/pkg/backend/status.go index 1c5946b..d4abc9c 100644 --- a/pkg/backend/status.go +++ b/pkg/backend/status.go @@ -1,6 +1,10 @@ package backend -var version = "unknown" +// Version Alice (set during the build) +var Version = "unknown" + +// Build is the current revision pointing at HEAD +var Build = "unknown" // AppStatus contains application status information type AppStatus struct { @@ -25,7 +29,7 @@ func NewAppStatus() (*AppStatus, error) { } status := &AppStatus{ - Version: version, + Version: Version, Routes: routesStatus, Neighbours: neighboursStatus, } diff --git a/pkg/caches/neighbors_test.go b/pkg/caches/neighbors_test.go index 71df01c..ccc8c25 100644 --- a/pkg/caches/neighbors_test.go +++ b/pkg/caches/neighbors_test.go @@ -1,7 +1,7 @@ package caches import ( - "github.com/alice-lg/alice-lg/backend/api" + "github.com/alice-lg/alice-lg/pkg/api" "testing" "time" diff --git a/pkg/caches/routes_test.go b/pkg/caches/routes_test.go index 9adfec8..efab5df 100644 --- a/pkg/caches/routes_test.go +++ b/pkg/caches/routes_test.go @@ -1,7 +1,7 @@ package caches import ( - "github.com/alice-lg/alice-lg/backend/api" + "github.com/alice-lg/alice-lg/pkg/api" "testing" "time" diff --git a/pkg/sources/birdwatcher/client.go b/pkg/sources/birdwatcher/client.go index eccc908..595ace5 100644 --- a/pkg/sources/birdwatcher/client.go +++ b/pkg/sources/birdwatcher/client.go @@ -50,7 +50,7 @@ func (self *Client) Get(client *http.Client, url string) (ClientResponse, error) func (self *Client) GetJson(endpoint string) (ClientResponse, error) { client := &http.Client{} - return self.Get(client, self.Api + endpoint) + return self.Get(client, self.Api+endpoint) } // Make API request, parse response and return map or error @@ -59,5 +59,5 @@ func (self *Client) GetJsonTimeout(timeout time.Duration, endpoint string) (Clie Timeout: timeout, } - return self.Get(client, self.Api + endpoint) + return self.Get(client, self.Api+endpoint) } diff --git a/pkg/sources/birdwatcher/config.go b/pkg/sources/birdwatcher/config.go index 47bf059..cfeda39 100644 --- a/pkg/sources/birdwatcher/config.go +++ b/pkg/sources/birdwatcher/config.go @@ -12,6 +12,7 @@ type Config struct { ShowLastReboot bool `ini:"show_last_reboot"` Type string `ini:"type"` + MainTable string `ini:"main_table"` PeerTablePrefix string `ini:"peer_table_prefix"` PipeProtocolPrefix string `ini:"pipe_protocol_prefix"` NeighborsRefreshTimeout int `ini:"neighbors_refresh_timeout"` diff --git a/pkg/sources/birdwatcher/source_multitable.go b/pkg/sources/birdwatcher/source_multitable.go index fd39bd1..da8d90a 100644 --- a/pkg/sources/birdwatcher/source_multitable.go +++ b/pkg/sources/birdwatcher/source_multitable.go @@ -480,9 +480,10 @@ func (self *MultiTableBirdwatcher) AllRoutes() (*api.RoutesResponse, error) { if err != nil { return nil, err } + mainTable := self.GenericBirdwatcher.config.MainTable // Fetch received routes first - birdImported, err := self.client.GetJson("/routes/table/master") + birdImported, err := self.client.GetJson("/routes/table/" + mainTable) if err != nil { return nil, err } diff --git a/pkg/sources/birdwatcher/source_singletable.go b/pkg/sources/birdwatcher/source_singletable.go index 358a9c7..2363d2f 100644 --- a/pkg/sources/birdwatcher/source_singletable.go +++ b/pkg/sources/birdwatcher/source_singletable.go @@ -276,13 +276,14 @@ func (self *SingleTableBirdwatcher) RoutesNotExported(neighborId string) (*api.R func (self *SingleTableBirdwatcher) AllRoutes() (*api.RoutesResponse, error) { // First fetch all routes from the master table - birdImported, err := self.client.GetJson("/routes/table/master") + mainTable := self.GenericBirdwatcher.config.MainTable + birdImported, err := self.client.GetJson("/routes/table/" + mainTable) if err != nil { return nil, err } // Then fetch all filtered routes from the master table - birdFiltered, err := self.client.GetJson("/routes/table/master/filtered") + birdFiltered, err := self.client.GetJson("/routes/table/" + mainTable + "/filtered") if err != nil { return nil, err }