Skip to content

Commit

Permalink
Prep emojivoto for move to buoyantio/emojivoto repo (datawire#54)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Lingerfelt <kl@buoyant.io>
  • Loading branch information
klingerf authored Jul 27, 2018
1 parent 08972b9 commit 42dff97
Show file tree
Hide file tree
Showing 56 changed files with 156 additions and 787 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
145 changes: 132 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,142 @@
![Conduit][conduit-logo]
# Emoji.voto

# conduit-examples
A microservice application that allows users to vote for their favorite emoji,
and tracks votes received on a leaderboard. May the best emoji win.

🎈 Welcome to conduit-examples! 👋
The application is composed of the following 3 services:

This repo contains subdirectories with examples of how to use the
[Conduit service mesh](https://conduit.io).
* [emojivoto-web](emojivoto-web/): Web frontend and REST API
* [emojivoto-emoji-svc](emojivoto-emoji-svc/): gRPC API for finding and listing emoji
* [emojivoto-voting-svc](emojivoto-voting-svc/): gRPC API for voting and leaderboard

## Emoji.voto
![Emojivoto Topology](assets/emojivoto-topology.png "Emojivoto Topology")

* [`emojivoto/`](emojivoto/)
## Running

A microservice application that allows users to vote for their favorite emoji,
and tracks votes received on a leaderboard. May the best emoji win.
### In Minikube

Deploy the application to Minikube using the Linkerd2 service mesh.

1. Install the `linkerd` CLI

```
curl https://run.conduit.io/install | sh
```

2. Install Linkerd2

```
linkerd install | kubectl apply -f -
```

3. View the dashboard!

```
linkerd dashboard
```

4. Inject, Deploy, and Enjoy

```
linkerd inject emojivoto.yml | kubectl apply -f -
```

5. Use the app!

```
minikube -n emojivoto service web-svc
```

### In docker-compose

It's also possible to run the app with docker-compose (without Linkerd2).

Build and run:

```
make deploy-to-docker-compose
```

The web app will be running on port 8080 of your docker host.

### Generating some traffic

The `VoteBot` service can generate some traffic for you. It votes on emoji
"randomly" as follows:
- It votes for :doughnut: 15% of the time.
- It votes for :poop: 20% of the time.
- When not voting for :doughnut: or :poop:, it picks an emoji at random

If you're running the app using the instructions above, the VoteBot will have
been deployed and will start sending traffic to the vote endpoint.

If you'd like to run the bot manually:
```
export WEB_HOST=localhost:8080 # replace with your web location
go run emojivoto-web/cmd/vote-bot/main.go
```

## Releasing a new version

To update the docker images:
1. Update the tag name in `common.mk`
2. Update the base image tags in `Makefile` and `Dockerfile`
3. Build base docker image `make build-base-docker-image`
4. Build docker images `make build`
5. Push the docker images to hub.docker.com
```bash
docker login
docker push buoyantio/emojivoto-svc-base:v4
docker push buoyantio/emojivoto-emoji-svc:v4
docker push buoyantio/emojivoto-voting-svc:v4
docker push buoyantio/emojivoto-web:v4
```
6. Update `emojivoto.yml`, `docker-compose.yml`


## Local Development

### Emojivoto webapp

This app is written with React and bundled with webpack.
Use the following to run the emojivoto go services and develop on the frontend.

Start the voting service
```
GRPC_PORT=8081 go run emojivoto-voting-svc/cmd/server.go
```

[In a separate teminal window] Start the emoji service
```
GRPC_PORT=8082 go run emojivoto-emoji-svc/cmd/server.go
```

[In a separate teminal window] Bundle the frontend assets
```
cd emojivoto-web/webapp
yarn install
yarn webpack # one time asset-bundling OR
yarn webpack-dev-server --port 8083 # bundle/serve reloading assets
```

[In a separate teminal window] Start the web service
```
export WEB_PORT=8080
export VOTINGSVC_HOST=localhost:8081
export EMOJISVC_HOST=localhost:8082
## Lifecycle
# if you ran yarn webpack
export INDEX_BUNDLE=emojivoto-web/webapp/dist/index_bundle.js
* [`lifecycle/`](lifecycle/)
# if you ran yarn webpack-dev-server
export WEBPACK_DEV_SERVER=http://localhost:8083
Production testing the proxy's discovery & caching.
# start the webserver
go run emojivoto-web/cmd/server.go
```

[conduit-logo]: https://user-images.githubusercontent.com/9226/33585569-c620a100-d919-11e7-83b6-a78f6e2683ec.png
[Optional] Start the vote bot for automatic traffic generation.
```
export WEB_HOST=localhost:8080
go run emojivoto-web/cmd/vote-bot/main.go
```
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package api

import (
"context"

"github.com/buoyantio/emojivoto/emojivoto-emoji-svc/emoji"
pb "github.com/buoyantio/emojivoto/emojivoto-emoji-svc/gen/proto"
"google.golang.org/grpc"
pb "github.com/runconduit/conduit-examples/emojivoto/emojivoto-emoji-svc/gen/proto"
"github.com/runconduit/conduit-examples/emojivoto/emojivoto-emoji-svc/emoji"
)

type EmojiServiceServer struct {
Expand All @@ -27,7 +28,7 @@ func (svc *EmojiServiceServer) ListAll(ctx context.Context, req *pb.ListAllEmoji
return &pb.ListAllEmojiResponse{List: list}, nil
}

func (svc *EmojiServiceServer) FindByShortcode(ctx context.Context, req *pb.FindByShortcodeRequest) (*pb.FindByShortcodeResponse, error){
func (svc *EmojiServiceServer) FindByShortcode(ctx context.Context, req *pb.FindByShortcodeRequest) (*pb.FindByShortcodeResponse, error) {
var pbE *pb.Emoji
foundEmoji := svc.allEmoji.WithShortcode(req.Shortcode)
if foundEmoji != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"testing"

"github.com/runconduit/conduit-examples/emojivoto/emojivoto-emoji-svc/emoji"
pb "github.com/runconduit/conduit-examples/emojivoto/emojivoto-emoji-svc/gen/proto"
"github.com/buoyantio/emojivoto/emojivoto-emoji-svc/emoji"
pb "github.com/buoyantio/emojivoto/emojivoto-emoji-svc/gen/proto"
)

func TestListAll(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main

import (
"os"
"log"
"fmt"
"log"
"net"
"os"

"github.com/buoyantio/emojivoto/emojivoto-emoji-svc/api"
"github.com/buoyantio/emojivoto/emojivoto-emoji-svc/emoji"
"google.golang.org/grpc"
"github.com/runconduit/conduit-examples/emojivoto/emojivoto-emoji-svc/api"
"github.com/runconduit/conduit-examples/emojivoto/emojivoto-emoji-svc/emoji"
)

var (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

pb "github.com/runconduit/conduit-examples/emojivoto/emojivoto-voting-svc/gen/proto"
"github.com/runconduit/conduit-examples/emojivoto/emojivoto-voting-svc/voting"
pb "github.com/buoyantio/emojivoto/emojivoto-voting-svc/gen/proto"
"github.com/buoyantio/emojivoto/emojivoto-voting-svc/voting"
"google.golang.org/grpc"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"testing"

pb "github.com/runconduit/conduit-examples/emojivoto/emojivoto-voting-svc/gen/proto"
"github.com/runconduit/conduit-examples/emojivoto/emojivoto-voting-svc/voting"
pb "github.com/buoyantio/emojivoto/emojivoto-voting-svc/gen/proto"
"github.com/buoyantio/emojivoto/emojivoto-voting-svc/voting"
)

func TestVoteJoy(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main

import (
"os"
"log"
"github.com/runconduit/conduit-examples/emojivoto/emojivoto-voting-svc/voting"
"fmt"
"log"
"net"
"os"

"github.com/buoyantio/emojivoto/emojivoto-voting-svc/api"
"github.com/buoyantio/emojivoto/emojivoto-voting-svc/voting"
"google.golang.org/grpc"
"github.com/runconduit/conduit-examples/emojivoto/emojivoto-voting-svc/api"
)

var (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"log"
"os"

pb "github.com/runconduit/conduit-examples/emojivoto/emojivoto-web/gen/proto"
"github.com/runconduit/conduit-examples/emojivoto/emojivoto-web/web"
pb "github.com/buoyantio/emojivoto/emojivoto-web/gen/proto"
"github.com/buoyantio/emojivoto/emojivoto-web/web"
"google.golang.org/grpc"
)

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"strconv"

pb "github.com/runconduit/conduit-examples/emojivoto/emojivoto-web/gen/proto"
pb "github.com/buoyantio/emojivoto/emojivoto-web/gen/proto"
)

type WebApp struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/url"
"testing"

pb "github.com/runconduit/conduit-examples/emojivoto/emojivoto-web/gen/proto"
pb "github.com/buoyantio/emojivoto/emojivoto-web/gen/proto"
"google.golang.org/grpc"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 42dff97

Please sign in to comment.