Skip to content

Commit

Permalink
Update repo to more modern tooling (#19)
Browse files Browse the repository at this point in the history
- Remove `bin/dep` and other unused scripts
- Update how Go protobuf bindings are generated
- Switch Deployments in example configs to `apps/v1`
- Update Dockerfile to build with go modules
- Fix failing http-egress test
- Fix malformed GET requests in http-egress
- Add http-egress example config for testing
- Update README.md

Signed-off-by: Kevin Ingelman <ki@buoyant.io>
  • Loading branch information
klingerf authored May 21, 2024
1 parent 67fb1e9 commit 9cac781
Show file tree
Hide file tree
Showing 21 changed files with 514 additions and 321 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.11.6-stretch
working_directory: /go/src/github.com/buoyantio/bb
- image: cimg/go:1.22.3
steps:
- checkout
- run: bin/dep ensure -vendor-only
- run: bin/precheck.sh
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.dep
vendor
vendor
target
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
vendor
target
.idea
.protoc
.dep*
29 changes: 19 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
FROM golang:1.11.6-stretch as golang
WORKDIR /go/src/github.com/buoyantio/bb
ADD . /go/src/github.com/buoyantio/bb
# cache go modules in a separate image
FROM --platform=$BUILDPLATFORM golang:1.22.3-alpine as go-deps
WORKDIR /bb-build
COPY go.mod go.sum main.go ./
COPY cmd cmd
COPY gen gen
COPY protocols protocols
COPY service service
COPY strategies strategies
RUN go mod vendor

RUN mkdir -p /out
RUN ./bin/dep ensure
RUN go build -o /out/bb .
# build the bb binary
FROM --platform=$BUILDPLATFORM go-deps as golang
WORKDIR /bb-build
RUN CGO_ENABLED=0 go build -o /out/bb -mod=vendor .

FROM gcr.io/linkerd-io/base:2019-02-19.01
RUN apt-get update
RUN apt-get install -y ca-certificates
COPY --from=golang /out /out
# package a runtime image
FROM scratch
LABEL org.opencontainers.image.source=https://github.com/buoyantio/bb
COPY --from=golang /out/bb /out/bb
COPY --from=golang /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT ["/out/bb"]
106 changes: 51 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@

# bb

Building Blocks or `bb` is a tool that can simulate many of the typical scenarios
of a cloud-native Service-Oriented Architecture based on microservices.
Building Blocks or `bb` is a tool that can simulate many of the typical
scenarios of a cloud-native Service-Oriented Architecture based on
microservices.

## Using `bb`
`bb` publishes a single container, `buoyantio/bb:v0.0.5`. Instances of this
container receive and return a simple message, described by the protobuf schema
[in this repository](api.proto). This known interface allows for `bb`
containers to be arranged in many different ways, just like building a structure
using LEGO blocks.
`bb` publishes a single container, `buoyantio/bb`. Instances of this container
receive and return a simple message, described by the protobuf schema [in this
repository](api.proto). This known interface allows for `bb` containers to be
arranged in many different ways, like building a structure using LEGO blocks.

The best way to find out about `bb` features is by using the `--help` command and
checking out the self-contained documentation.
The best way to find out about `bb` features is by using the `--help` command
and checking out the self-contained documentation.

### Running locally
If you want to run `bb` locally, outside a Kubernetes cluster or Docker, you need
to build a binary for your environment. The usual way to go about this is using Go's
standard build tools. From this repository's root, run:
If you want to run `bb` locally, outside a Kubernetes cluster or Docker, you
need to build a binary for your environment. The usual way to go about this is
using Go's standard build tools. From this repository's root, run:

$ mkdir -p target && go build -o target/bb .

This will create a `bb` binary in the `target` directory. You can run this on your
computer but, unless you use Linux, you won't be able to use this same binary on
Docker or Kubernetes.
This will create a `bb` binary in the `target` directory. You can run this on
your computer but, unless you use Linux, you won't be able to use this same
binary on Docker or Kubernetes.

As an example of how to use `bb` on your computer, let's create a simple two-service
setup. Open a terminal and type in the following:
As an example of how to use `bb` on your computer, let's create a simple
two-service setup. Open a terminal and type in the following:

$ target/bb terminus --grpc-server-port 9090 --response-text BANANA

Expand All @@ -41,57 +41,45 @@ Now, on a third terminal, type this and you should see a similar response:
$ curl localhost:8080
{"requestUid":"in:http-sid:point-to-point-channel-grpc:-1-h1:8080-387107000","payload":"BANANA"}

The first command you typed created a gRPC server on port 9090 following the [terminus strategy](strategies/terminus.go),
which will return the payload defined as the `--response-text` argument for any valid request.
The first command you typed created a gRPC server on port 9090 following the
[terminus strategy](strategies/terminus.go), which will return the payload
defined as the `--response-text` argument for any valid request.

The second command creates an HTTP 1.1 server on port 8080 following the
[point-to-point channel strategy](strategies/point_to_point_channel.go), and has the gRPC server
previously defined as its downstream. It will receive any HTTP 1.1 request, convert it to gRPC,
and forward it to the downstream server. It will also get the gRPC response from the server, convert
it to JSON-over-HTTP, and return to its client.
[point-to-point channel strategy](strategies/point_to_point_channel.go), and has
the gRPC server previously defined as its downstream. It will receive any HTTP
1.1 request, convert it to gRPC, and forward it to the downstream server. It
will also get the gRPC response from the server, convert it to JSON-over-HTTP,
and return to its client.

## Running on Kubernetes
Although `bb` can be useful to test things locally as described above, its main use case is to create
complicated environments inside Kubernetes clusters.
Although `bb` can be useful to test things locally as described above, its main
use case is to create complicated environments inside Kubernetes clusters.

To use `bb` with Kubernetes, the first step you need to take is to publish its Docker image to your
Kubernetes cluster. Here we will be using a local Minikube installation to demonstrate its use.
To use `bb` with Kubernetes, the first step you need to take is to publish its
Docker image to your Kubernetes cluster. Here we will be using a local [kind
cluster](https://kind.sigs.k8s.io/) to demonstrate its use.

First, make sure that Minikube is running:
First, start your cluster:

$ minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100

Now, make sure that your Docker environment variables are set to use Minikube as the Docker repository
for images:

$ eval "$(minikube docker-env)"
$ kind create cluster

You should then build a Docker image for `bb`:

$ bin/docker-build-bb.sh
Sending build context to Docker daemon 136.7MB
Step 1/6 : FROM buoyantio/base:2017-10-30.01
---> 14aa74f25501
Step 2/6 : RUN apt-get update
[...]
Removing intermediate container f4f571b01dd8
Successfully built e6d76c5df612
Successfully tagged buoyantio/bb:v0.0.5

A test run using the Docker CLI should return usage information and confirm that everything is ok:
$ docker build -t buoyantio/bb:latest .

$ docker run buoyantio/bb:v0.0.5
A test run using the Docker CLI should return usage information and confirm that
everything is ok:

$ docker run buoyantio/bb:latest
Building Blocks or `bb` is a tool that can simulate many of the typical scenarios of a cloud-native Service-Oriented Architecture based on microservices.

Usage:
bb [command]

Available Commands:
broadcast-channel Forwards the request to all downstream services.
completion Generate the autocompletion script for the specified shell
help Help about any command
http-egress Receives a request, makes a HTTP(S) call to a specified URL and return the body of the response
point-to-point-channel Forwards the request to one and only one downstream service.
Expand All @@ -114,13 +102,21 @@ A test run using the Docker CLI should return usage information and confirm that

Use "bb [command] --help" for more information about a command.

To build the exact same scenario we had above, but for Kubernetes, you can deploy the should have
a YAML configuration like the one in our [examples directory](examples). You can deploy it to your Kubernetes
cluster by running:
Next load the image into your kind cluster, with:

$ kind load docker-image buoyantio/bb:latest

To build the exact same scenario we had above, but for Kubernetes, you can
deploy a YAML configuration like the one in our [examples directory](examples).
You can deploy it to your Kubernetes cluster by running:

$ kubectl apply -f examples/bb-readme/application.yaml

You can then use `curl`to query the service:
You can then port-forward and use `curl` to query the service:

$ kubectl -n bb-readme port-forward svc/bb-readme-gateway-svc 8080 &
Forwarding from [::1]:8080 -> 8080

$ curl `minikube -n bb-readme service bb-readme-gateway-svc --url`
{"requestUid":"in:http-sid:point-to-point-channel-grpc:-1-h1:8080-66349706","payload":"BANANA"}
$ curl http://localhost:8080
Handling connection for 8080
{"requestUID":"in:http-sid:point-to-point-channel-grpc:-1-h1:8080-395520418","payload":"BANANA"}
4 changes: 3 additions & 1 deletion api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package buoyantio.bb;

option go_package = "github.com/buoyantio/bb/gen";

message TheRequest {
string requestUID = 1;
}
Expand All @@ -14,4 +16,4 @@ message TheResponse {
service TheService {
rpc theFunction (TheRequest) returns (TheResponse) {
}
}
}
45 changes: 0 additions & 45 deletions bin/dep

This file was deleted.

2 changes: 0 additions & 2 deletions bin/docker-build-bb.sh

This file was deleted.

17 changes: 10 additions & 7 deletions bin/protoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

set -eu

Expand All @@ -9,16 +9,19 @@ else
fi
arch=$(uname -m)

protocbin=.protoc
protocversion=3.4.0
protocurl="https://github.com/google/protobuf/releases/download/v${protocversion}/protoc-${protocversion}-${os}-${arch}.zip"
protocversion=3.20.1

targetbin=target/bin
protocbin=$targetbin/protoc-${protocversion}
protocurl="https://github.com/protocolbuffers/protobuf/releases/download/v${protocversion}/protoc-${protocversion}-${os}-${arch}.zip"

if [ ! -f "$protocbin" ]; then
tmp=$(mktemp -d -t protoc.XXX)
mkdir -p $targetbin
(
cd $tmp
curl -L --silent --fail -o "$protocbin.zip" "$protocurl"
jar xf "$protocbin.zip"
cd "$tmp"
curl -L --silent --fail -o "./protoc.zip" "$protocurl"
unzip -q "./protoc.zip" bin/protoc
chmod +x bin/protoc
)
mv "$tmp/bin/protoc" "$protocbin"
Expand Down
25 changes: 19 additions & 6 deletions bin/protoc-go.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
#!/bin/sh
#!/usr/bin/env bash

set -eu

generated_src_dir=./gen
# keep in sync with google.golang.org/protobuf in go.mod
protoc_gen_go_version=v1.33.0
# keep in sync with google.golang.org/grpc/cmd/protoc-gen-go-grpc in go.mod
protoc_gen_go_grpc_version=v1.3.0

go install ./vendor/github.com/golang/protobuf/protoc-gen-go
# fetch tools and dependencies
go install google.golang.org/protobuf/cmd/protoc-gen-go@$protoc_gen_go_version
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$protoc_gen_go_grpc_version

rm -rf $generated_src_dir
mkdir $generated_src_dir
bin/protoc -I . --go_out=plugins=grpc:$generated_src_dir ./api.proto
basedir=$(cd "$(dirname "$0")"/..; pwd)
outdir="$basedir"/gen
rm -rf "$outdir"
mkdir "$outdir"

"$basedir"/bin/protoc \
--proto_path="$basedir" \
--go_out="$outdir" \
--go_opt=paths=source_relative \
--go-grpc_out="$outdir" \
--go-grpc_opt=paths=source_relative \
"$basedir"/api.proto
9 changes: 4 additions & 5 deletions examples/bb-readme/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Namespace
metadata:
name: bb-readme
---
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: bb-readme-terminus
Expand All @@ -21,7 +21,7 @@ spec:
spec:
containers:
- name: http-to-grpc
image: buoyantio/bb:v0.0.5
image: buoyantio/bb:latest
args: ["terminus", "--grpc-server-port", "9090", "--response-text", "BANANA"]
ports:
- containerPort: 9090
Expand All @@ -39,7 +39,7 @@ spec:
port: 9090
targetPort: 9090
---
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: bb-readme-gateway
Expand All @@ -56,7 +56,7 @@ spec:
spec:
containers:
- name: http-to-grpc
image: buoyantio/bb:v0.0.5
image: buoyantio/bb:latest
args: ["point-to-point-channel", "--grpc-downstream-server", "bb-readme-terminus-svc:9090", "--h1-server-port", "8080"]
ports:
- containerPort: 8080
Expand All @@ -69,7 +69,6 @@ metadata:
spec:
selector:
app: bb-readme-gateway
type: LoadBalancer
ports:
- name: http
port: 8080
Expand Down
Loading

0 comments on commit 9cac781

Please sign in to comment.