Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ RUN wget https://github.com/gohugoio/hugo/releases/download/v0.45.1/hugo_0.45.1_
&& ln -s /tmp/public/ /usr/share/nginx/html \
&& cd /tmp \
&& hugo \
&& cp ./nginx/default.conf /etc/nginx/conf.d/default.conf
&& cp ./nginx/default.conf /etc/nginx/conf.d/default.conf \
&& apk update \
&& apk add nodejs npm \
&& npm install -g asyncapi-generator
CMD ["/bin/sh", "/tmp/nginx/start.sh"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ build-all: clean-all build-site build-server build-docker ## Performs clean-all
#--- Run targets ---
run-server: ## Builds the in the server directory and runs it with default settings
cd server && go generate && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ../dist/server *.go
MODE=LOCAL HUGODIR=$(CURRDIR)/webapp HUGOSTORE=$(CURRDIR)/webapp/content/apis SWAGGERSTORE=$(CURRDIR)/webapp/static/swaggerdocs EXTERNALIP=$(EXTIP) ./dist/server
MODE=LOCAL ASYNCDOCSTORE=$(CURRDIR)/webapp/static/asyncapidocs HUGODIR=$(CURRDIR)/webapp HUGOSTORE=$(CURRDIR)/webapp/content/apis SWAGGERSTORE=$(CURRDIR)/webapp/static/swaggerdocs EXTERNALIP=$(EXTIP) ./dist/server

run-docker: ## Runs a docker container with default settings
docker run -it --rm -p 80:80 -v $(HOME)/.kube:/root/.kube -v $(HOME)/.minikube:/home/$(USER)/.minikube -e MODE=LOCAL -e HUGODIR="/tmp" -e EXTERNALIP=$(EXTIP) -e HUGOCMD="sh -c \"cd /tmp && hugo\"" --name=apiscout $(DOCKERREPO)/apiscout:latest

run-hugo: ## Runs the embedded Hugo server on port 1313
cd webapp && hugo server -D --disableFastRender
cd webapp && hugo server --renderToDisk

run-docs: ## Runs the embedded Hugo server on port 1313 for the documentation
cd docs && hugo server -D --disableFastRender --themesDir ../webapp/themes
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ apiscout looks for two annotations to be able to index a service:

* `apiscout/index: 'true'` This annotation ensures that apiscout indexes the service
* `apiscout/swaggerUrl: '/swaggerspec'` This is the URL from where apiscout will read the OpenAPI document
* `apiscout/asyncApiUrl: '/asyncapispec'` This is the URL from where apiscout will read the AsyncAPI document

## Environment variables for the docker container

Expand Down
2 changes: 1 addition & 1 deletion apiscout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
spec:
containers:
- name: apiscout
image:
image:
env:
- name: MODE
value: "KUBE"
Expand Down
1 change: 1 addition & 0 deletions samples/invoiceservice-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ ENV HTTPPORT=8080 \
PAYMENTSERVICE=bla
ADD invoiceservice-go .
ADD swagger.json .
ADD asyncapi.yaml .
EXPOSE 8080
CMD ./invoiceservice-go
1 change: 1 addition & 0 deletions samples/invoiceservice-go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ build-app:
build-docker:
cp Dockerfile dist/Dockerfile
cp swagger.json dist/swagger.json
cp asyncapi.yaml dist/asyncapi.yaml
eval $$(minikube docker-env) ;\
cd dist && docker build -t $(DOCKERHUBUSER)/invoiceservice-go:$(DOCKERTAG) .

Expand Down
6 changes: 4 additions & 2 deletions samples/invoiceservice-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ This sample Flogo application is used to demonstrate some key Flogo constructs,
├── Dockerfile <-- A Dockerfile to build a container based on an Alpine base image
├── main.go <-- The Go source code for the app
├── Makefile <-- A Makefile to help build and deploy the app
├── payment-go-svc.yml <-- The Kubernetes deployment file
├── invoice-go-svc.yml <-- The Kubernetes deployment file
├── README.md <-- This file
├── asyncapi.yaml <-- The AsyncAPI specification (async spec example)
└── swagger.json <-- The OpenAPI specification for the app
```

Expand All @@ -32,6 +33,7 @@ To build and deploy the app to Kubernetes, run the make targets for _deps_, _bui
After starting the app, it will register with two endpoints:
* **/api/invoices/:id**: Get the invoice details for the invoice ID.
* **/swagger**: Get the OpenAPI specification for this app
* **/asyncapispec**: Get the AsyncAPI specification for this app

## API Scout
As you deploy the app to Kubernetes, after a few seconds the API will be found by API Scout and indexed. The lines 36 to 38 in [invoice-go-svc.yml](./invoice-go-svc.yml) are the annotations that make sure the API is found.
As you deploy the app to Kubernetes, after a few seconds the API will be found by API Scout and indexed. The lines 34 to 36 in [invoice-go-svc.yml](./invoice-go-svc.yml) are the annotations that make sure the API is found.
161 changes: 161 additions & 0 deletions samples/invoiceservice-go/asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
asyncapi: "1.2.0"
info:
title: invoiceservice
version: "1.0.0"
x-logo: https://avatars0.githubusercontent.com/u/16401334?v=4&s=200
description: |
This is a simple example of an _AsyncAPI_ document.
termsOfService: https://api.company.com/terms
baseTopic: 'hitch'

servers:
- url: api.company.com:{port}/{app-id}
description: Allows you to connect using the MQTT protocol.
scheme: mqtt
variables:
app-id:
default: demo
description: You can find your `app-id` in our control panel, under the auth tab.
port:
enum:
- '5676'
- '5677'
default: '5676'
- url: api.company.com:{port}/{app-id}
description: Allows you to connect using the AMQP protocol.
scheme: amqp
variables:
app-id:
default: demo
description: You can find your `app-id` in our control panel, under the auth tab.
port:
enum:
- '5676'
- '5677'
default: '5676'

topics:
accounts.1.0.action.user.signup:
publish:
$ref: "#/components/messages/userSignUp"
accounts.1.0.event.user.signup:
subscribe:
$ref: "#/components/messages/userSignedUp"

components:
messages:
userSignUp:
deprecated: true
summary: Action to sign a user up.
description: |
Multiline description of what this action does. **It allows Markdown.**
tags:
- name: user
- name: signup
headers:
type: object
properties:
qos:
$ref: "#/components/schemas/MQTTQoSHeader"
retainFlag:
$ref: "#/components/schemas/MQTTRetainHeader"
payload:
type: object
properties:
user:
$ref: "#/components/schemas/userCreate"
signup:
$ref: "#/components/schemas/signup"


userSignedUp:
payload:
type: object
properties:
test:
type: array
items:
type: object
properties:
key1:
type: string
key2:
type: integer
user:
$ref: "#/components/schemas/user"
signup:
$ref: "#/components/schemas/signup"
schemas:
id:
title: id
description: Resource identifier
type: string
username:
title: username
description: User handle
type: string
datetime:
title: datetime
description: Date and Time of the message
type: string
format: date-time
MQTTQoSHeader:
title: qos
description: Quality of Service
type: integer
format: int32
default: 1
enum:
- 0
- 2
MQTTRetainHeader:
title: retainFlag
description: |
This flag determines if the message will be saved by the broker for the specified
topic as last known good value. New clients that subscribe to that topic will receive
the last retained message on that topic instantly after subscribing. More on retained messages
and best practices in one of the next posts.
type: boolean
default: false
user:
type: object
required:
- id
- username
properties:
id:
description: User Id
$ref: "#/components/schemas/id"
full_name:
description: User full name
type: string
username:
$ref: "#/components/schemas/username"
userCreate:
type: object
required:
- username
properties:
full_name:
description: User full name
type: string
username:
$ref: "#/components/schemas/username"

signup:
type: object
required:
- method
- datetime
properties:
method:
description: Signup method
type: string
enum:
- email
- facebook
- twitter
- github
- google
datetime:
$ref: "#/components/schemas/datetime"
1 change: 1 addition & 0 deletions samples/invoiceservice-go/invoice-go-svc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ metadata:
namespace: default
annotations:
apiscout/index: 'true'
apiscout/asyncApiUrl: '/asyncapispec'
apiscout/swaggerUrl: '/swaggerspec'
spec:
ports:
Expand Down
27 changes: 27 additions & 0 deletions samples/invoiceservice-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/TIBCOSoftware/flogo-lib/engine"
"github.com/TIBCOSoftware/flogo-lib/flogo"
"github.com/TIBCOSoftware/flogo-lib/logger"
"github.com/ghodss/yaml"
"github.com/retgits/flogo-components/activity/randomnumber"
)

Expand Down Expand Up @@ -49,6 +50,7 @@ func appBuilder() *flogo.App {
trg := app.NewTrigger(&rt.RestTrigger{}, map[string]interface{}{"port": port})
trg.NewFuncHandler(map[string]interface{}{"method": "GET", "path": "/api/invoices/:id"}, handler)
trg.NewFuncHandler(map[string]interface{}{"method": "GET", "path": "/swaggerspec"}, SwaggerSpec)
trg.NewFuncHandler(map[string]interface{}{"method": "GET", "path": "/asyncapispec"}, YamlSpec)

return app
}
Expand Down Expand Up @@ -133,3 +135,28 @@ func getEnvKey(key string, fallback string) string {
}
return fallback
}

// YamlSpec is the function that gets executedto retrieve the AsynSpec
func YamlSpec(ctx context.Context, inputs map[string]*data.Attribute) (map[string]*data.Attribute, error) {
// The return message is a map[string]*data.Attribute which we'll have to construct
response := make(map[string]interface{})
ret := make(map[string]*data.Attribute)

fileData, err := ioutil.ReadFile("asyncapi.yaml")
if err != nil {
ret["code"], _ = data.NewAttribute("code", data.TypeInteger, 500)
response["msg"] = err.Error()
} else {
ret["code"], _ = data.NewAttribute("code", data.TypeInteger, 200)
var data map[string]interface{}
if err := yaml.Unmarshal(fileData, &data); err != nil {
panic(err)
}
response = data
}

ret["data"], _ = data.NewAttribute("data", data.TypeAny, response)

return ret, nil

}
1 change: 1 addition & 0 deletions samples/streetlightsapp-go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
7 changes: 7 additions & 0 deletions samples/streetlightsapp-go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:latest
RUN apk update && apk add ca-certificates
ENV HTTPPORT=8090
ADD streetlightsapp-go .
ADD streetlightsapi.yaml .
EXPOSE 8090
CMD ./streetlightsapp-go
39 changes: 39 additions & 0 deletions samples/streetlightsapp-go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.PHONY: deps

#--- Variables ---
DOCKERHUBUSER=naresh
DOCKERTAG=latest
IPADDR=xxx.xxx.xxx.xxx

#--- Get the dependencies ---
deps:
go get -u ./...

#--- Clean up the dist folder ---
clean:
rm -rf dist

#--- Clean up the Kubernetes deployment ---
clean-kube:
kubectl delete deployment streetlights-go-svc
kubectl delete svc streetlights-go-svc

#--- Build the Flogo app ---
build-app:
go generate
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o dist/streetlightsapp-go

#--- Build the docker container ---
build-docker:
cp Dockerfile dist/Dockerfile
cp streetlightsapi.yaml dist/streetlightsapi.yaml
eval $$(minikube docker-env) ;\
cd dist && docker build -t $(DOCKERHUBUSER)/streetlightsapp-go:$(DOCKERTAG) .

#--- Run the container ---
run-docker:
docker run --rm -it -p 9999:8090 $(DOCKERHUBUSER)/streetlightsapp-go:$(DOCKERTAG)

#--- Run the app on Kubernetes ---
run-kube:
kubectl apply -f streetlights-go-svc.yml
36 changes: 36 additions & 0 deletions samples/streetlightsapp-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Streetlights Service

This sample application is used to demonstrate AsyncAPI app and is set to be indexed by API Scout.

## Files
```bash
.
├── Dockerfile <-- A Dockerfile to build a container based on an Alpine base image
├── main.go <-- The Go source code for the app
├── Makefile <-- A Makefile to help build and deploy the app
├── streetlights-go-svc.yml <-- The Kubernetes deployment file
├── README.md <-- This file
└── streetlightsapi.yaml <-- The AsyncAPI specification for the app
```

## Make targets
The [Makefile](./Makefile) has a few targets:
* **deps**: Get all the Go dependencies for the app
* **clean**: Remove the `dist` folder for a new deployment
* **clean-kube**: Remove all the deployed artifacts from Kubernetes
* **build-app**: Build an executable (and store it in the dist folder)
* **build-docker**: Build a Docker container from the contents of the `dist` folder
* **run-docker**: Run the Docker image with default settings
* **run-kube**: Deploy the app to Kubernetes

_For more detailed information on the commands that are executed you can check out the [Makefile](./Makefile)_

## Build and deploy the app
To build and deploy the app to Kubernetes, run the make targets for _deps_, _build-app_, _build-docker_ and _run-kube_

## API
After starting the app, it will register with below endpoint:
* **/asyncapispec**: Get the AsyncAPI specification for this app

## API Scout
As you deploy the app to Kubernetes, after a few seconds the API will be found by API Scout and indexed. The lines 34 to 35 in [streetlights-go-svc.yml](./streetlights-go-svc.yml) are the annotations that make sure the API is found.
Loading