Skip to content

Commit

Permalink
Merge pull request #374 from devopsfaith/v2.0-dev
Browse files Browse the repository at this point in the history
Release KrakenD 2.0
  • Loading branch information
kpacha authored Mar 7, 2022
2 parents 0dbee44 + 4866c87 commit 73603aa
Show file tree
Hide file tree
Showing 43 changed files with 1,217 additions and 1,863 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.17

- name: Test
run: make test
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
bench_res
krakend
krakend-alpine
cmd/krakend-integration/krakend-integration
Expand Down
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

28 changes: 18 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
FROM debian:buster-slim
ARG GOLANG_VERSION
ARG ALPINE_VERSION
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} as builder

LABEL maintainer="[email protected]"
RUN apk --no-cache add make gcc musl-dev binutils-gold

RUN apt-get update && \
apt-get install -y ca-certificates && \
update-ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY . /app
WORKDIR /app

ADD krakend /usr/bin/krakend
RUN make build

RUN useradd -r -c "KrakenD user" -U krakend

USER krakend
FROM alpine:${ALPINE_VERSION}

VOLUME [ "/etc/krakend" ]
LABEL maintainer="[email protected]"

RUN apk add --no-cache ca-certificates && \
adduser -u 1000 -S -D -H krakend && \
mkdir /etc/krakend && \
echo '{ "version": 3 }' > /etc/krakend/krakend.json

COPY --from=builder /app/krakend /usr/bin/krakend

USER 1000

WORKDIR /etc/krakend

Expand Down
89 changes: 53 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

BIN_NAME :=krakend
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
VERSION := 1.4.1
VERSION := 2.0.0
GIT_COMMIT := $(shell git rev-parse --short=7 HEAD)
PKGNAME := krakend
LICENSE := Apache 2.0
VENDOR=
Expand All @@ -15,10 +16,12 @@ RELEASE := 0
USER := krakend
ARCH := amd64
DESC := High performance API gateway. Aggregate, filter, manipulate and add middlewares
MAINTAINER := Daniel Ortiz <dortiz@devops.faith>
MAINTAINER := Daniel Ortiz <dortiz@krakend.io>
DOCKER_WDIR := /tmp/fpm
DOCKER_FPM := devopsfaith/fpm
GOLANG_VERSION := 1.16.4
GOLANG_VERSION := 1.17.8
GLIBC_VERSION := $(shell sh find_glibc.sh)
ALPINE_VERSION := 3.15

FPM_OPTS=-s dir -v $(VERSION) -n $(PKGNAME) \
--license "$(LICENSE)" \
Expand Down Expand Up @@ -47,53 +50,67 @@ RPMNAME=${PKGNAME}-${VERSION}-${RELEASE}.x86_64.rpm
all: test

update_krakend_deps:
go get github.com/luraproject/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
# go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/luraproject/lura/[email protected]
go get github.com/devopsfaith/bloomfilter/[email protected]
go get github.com/devopsfaith/krakend-amqp/[email protected]
go get github.com/devopsfaith/krakend-botdetector/[email protected]
go get github.com/devopsfaith/krakend-cel/[email protected]
go get github.com/devopsfaith/krakend-circuitbreaker/[email protected]
go get github.com/devopsfaith/krakend-cobra/[email protected]
go get github.com/devopsfaith/krakend-cors/[email protected]
go get github.com/devopsfaith/krakend-flexibleconfig/[email protected]
go get github.com/devopsfaith/krakend-gelf/[email protected]
go get github.com/devopsfaith/krakend-gologging/[email protected]
go get github.com/devopsfaith/krakend-httpcache/[email protected]
go get github.com/devopsfaith/krakend-httpsecure/[email protected]
go get github.com/devopsfaith/krakend-influx/[email protected]
go get github.com/devopsfaith/krakend-jose/[email protected]
go get github.com/devopsfaith/krakend-jsonschema/[email protected]
go get github.com/devopsfaith/krakend-lambda/[email protected]
go get github.com/devopsfaith/krakend-logstash/[email protected]
go get github.com/devopsfaith/krakend-lua/[email protected]
go get github.com/devopsfaith/krakend-martian/[email protected]
go get github.com/devopsfaith/krakend-metrics/[email protected]
go get github.com/devopsfaith/krakend-oauth2-clientcredentials/[email protected]
go get github.com/devopsfaith/krakend-opencensus/[email protected]
go get github.com/devopsfaith/krakend-pubsub/[email protected]
go get github.com/devopsfaith/krakend-ratelimit/[email protected]
go get github.com/devopsfaith/krakend-rss/[email protected]
go get github.com/devopsfaith/[email protected]
go get github.com/devopsfaith/krakend-viper@v1.4.0
go get github.com/devopsfaith/krakend-xml@v1.4.0
go get github.com/devopsfaith/krakend-viper/[email protected].0
go get github.com/devopsfaith/krakend-xml/[email protected].0
make test


build:
@echo "Building the binary..."
@go get .
@go build -ldflags="-X github.com/luraproject/lura/core.KrakendVersion=${VERSION}" -o ${BIN_NAME} ./cmd/krakend-ce
@go build -ldflags="-X github.com/luraproject/lura/v2/core.KrakendVersion=${VERSION} \
-X github.com/luraproject/lura/v2/core.GoVersion=${GOLANG_VERSION} \
-X github.com/luraproject/lura/v2/core.GlibcVersion=${GLIBC_VERSION}" \
-o ${BIN_NAME} ./cmd/krakend-ce
@echo "You can now use ./${BIN_NAME}"

test: build
go test -v ./tests

# Build KrakenD using docker (defaults to whatever the golang container uses)
build_on_docker:
docker run --rm -it -v "${PWD}:/app" -w /app golang:${GOLANG_VERSION} make build
docker run --rm -it -v "${PWD}:/app" -w /app golang:${GOLANG_VERSION} make -e build

# Build the container using the Dockerfile (alpine)
docker:
docker build --pull -t devopsfaith/krakend:${VERSION} .
docker build --no-cache --pull --build-arg GOLANG_VERSION=${GOLANG_VERSION} --build-arg ALPINE_VERSION=${ALPINE_VERSION} -t devopsfaith/krakend:${VERSION} .

benchmark:
@mkdir -p bench_res
@touch bench_res/${GIT_COMMIT}.out
@docker run --rm -d --name krakend -v "${PWD}/tests/fixtures:/etc/krakend" -p 8080:8080 devopsfaith/krakend:${VERSION} run -dc /etc/krakend/bench.json
@sleep 2
@docker run --rm -it --link krakend peterevans/vegeta sh -c \
"echo 'GET http://krakend:8080/test' | vegeta attack -rate=0 -duration=30s -max-workers=300 | tee results.bin | vegeta report" > bench_res/${GIT_COMMIT}.out
@docker stop krakend
@cat bench_res/${GIT_COMMIT}.out

builder/skel/%/etc/init.d/krakend: builder/files/krakend.init
mkdir -p "$(dir $@)"
Expand Down
100 changes: 32 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,55 @@
![Krakend logo](https://raw.githubusercontent.com/devopsfaith/krakend.io/master/images/logo.png)

# KrakenD API Gateway
Ultra-High performance API Gateway with middlewares
# KrakenD
KrakenD is an extensible, ultra-high performance API Gateway that helps you effortlessly adopt microservices and secure communications. KrakenD is easy to operate and run and scales out without a single point of failure.

**KrakenD Community Edition** (or *KrakenD-CE*) is the binary distribution of [KrakenD](https://www.krakend.io).
**KrakenD Community Edition** (or *KrakenD-CE*) is the open-source distribution of [KrakenD](https://www.krakend.io).

In this repository, you'll find the utils to build the KrakenD binary yourself. If you want to use KrakenD [download the binary](https://www.krakend.io/download/)
[KrakenD Site](https://www.krakend.io/) | [Documentation](https://www.krakend.io/docs/overview/introduction/) | [Blog](https://www.krakend.io/blog/) | [Twitter](https://twitter.com/krakend_io) | [Downloads](https://www.krakend.io/download/)

[KrakenD Site](https://www.krakend.io/) | [Documentation](https://www.krakend.io/docs/overview/introduction/) | [Blog](https://www.krakend.io/blog) | [Twitter](https://twitter.com/krakend_io)
## Benefits

## Features
Some of the features you get with KrakenD are:
- **Easy integration** of an ultra-high performance gateway.
- **Effortlessly transition to microservices** and Backend For Frontend implementations.
- **True linear scalability**: Thanks to its **stateless design**, every KrakenD node can operate independently in the cluster without any coordination or centralized persistence.
- **Low operational cost**: +70K reqs/s on a single instance of regular size. Super low memory consumption with high traffic (usually under 50MB w/ +1000 concurrent). Fewer machines. Smaller machines. Lower budget.
- **Platform-agnostic**. Whether you work in a Cloud-native environment (e.g., Kubernetes) or self-hosted on-premises.
- **No vendor lock-in**: Reuse the best existing open-source and proprietary tools rather than having everything in the gateway (telemetry, identity providers, etc.)
- **API Lifecycle**: Using **GitOps** and **declarative configuration**.
- **Decouple clients** from existing services. Create new APIs without changing your existing API contracts.

- **Ultra-High performance** API Gateway
- **Backend for Frontend**
- **Efficient**: Super low memory consumption with high traffic (usually under 50MB w/ +1000 concurrent) and even lower with low traffic (under 5MB)
- **Easy to use**: Declaration of endpoints by just writing the `/url/patterns/and/{variables}`
- **Unlimited** number of backends and endpoints associated with each endpoint. The limit is your kernel.
- **Aggregation** of all the data in the backends for a single endpoint
- **Response composition** and data manipulation (capture, groups, renames...)
- **Response filtering** (whitelist and blacklist)
- **Concurrent** API calls to the backend for the same request
- **Simple configuration**: All application configuration and behavior declared in a `krakend.json`.
- **Friendly**: No development needed to build your gateway. Use the Visual API [Designer](https://www.krakend.io/designer/) (UI to generate the `krakend.json`)
- **SSL**
- **HTTP2** ready
- **Circuit breaker** (fail fast and avoid smashing stressed backends)
- **Bursting** on High-load
- **Logging and statistics** of usage
- **API with statistics**
- **Service Discovery**: DNS SRV, ETCD or add your own
- **Multiple encodings** supported (json, XML, RSS or response as single string)
- **Injections via DSL** in the configuration (Martian)
- **Throttling**: Limits of usage in the router and proxy layers.
- **User quota**: Restrict usage of users by IP or custom headers
- **Basic Firewalling**: Restrict connections by host, drop connections on certain limits
- **Automatic load balancing**
- **HTTP Cache** headers
- **In-memory backend response cache**
- Multiple installation options (bin, docker, rpm, deb, brew)
- **Cloud native**
- **Loved by orchestrators** (Kubernetes, Mesos + Marathon, Nomad, Docker Swarm, and others)
- **Secure:**
- Support for SSL
- OAuth client grant
- JSON Web Tokens (JWT) and JSON Object Signing and Encryption (JOSE)
- HTTP Strict Transport Security (HSTS)
- Clickjacking protection
- HTTP Public Key Pinning (HPKP)
- MIME-Sniffing prevention
- Cross-site scripting (XSS) protection
- Cross-origin resource sharing (CORS)
## Technical features

- **Content aggregation**, composition, and filtering: Create views and mashups of aggregated content from your APIs.
- **Content Manipulation and format transformation**: Change responses, convert transparently from XML to JSON, and vice-versa.
- **Security:**: Zero-trust policy, CORS, OAuth, JWT, HSTS, clickjacking protection, HPKP, MIME-Sniffing prevention, XSS protection...
- **Concurrent calls**: Serve content faster than consuming backends directly.
- **SSL** and **HTTP2** ready
- **Throttling**: Limits of usage in the router and proxy layers
- **Multi-layer rate-limiting** for the end-user and between KrakenD and your services, including bursting, load balancing, and circuit breaker.
- **Telemetry** and dashboards of all sorts: Datadog, Zipkin, Jaeger, Prometheus, Grafana...
- **Extensible** with Go plugins, Lua scripts, Martian, or Google CEL spec.

For a more nice description of the features have a look in the [website](https://www.krakend.io/features/).
## Gateway documentation
See the [website](https://www.krakend.io) for more information.

Full, comprehensive documentation is viewable on the KrakenD website:
## Download
KrakenD is [packaged and distributed in several formats](https://www.krakend.io/download/). You don't need to clone this repo to use KrakenD unless you want to tweak and build the binary yourself.

https://www.krakend.io/docs/overview/introduction/
## Run
In its simplest form with Docker:

## Build Requirements
docker run -it -p "8080:8080" devopsfaith/krakend

- golang 1.11
Now see [http://localhost:8080/__health](http://localhost:8080/__health). The gateway is listening. Now *CTRL-C* and replace `/etc/krakend/krakend.json` with your [first configuration](https://designer.krakend.io).

## Build
See the required Go version in the `Makefile`, and then:
```
make build
```

## Building with docker
Or, if you don't have or don't want to install `go`, you can build it using the golang docker container:

If you don't have or don't want to install `go` you can build it using the golang docker container.
```
make docker_build
```

## FPM
You can set up your fpm docker image to run setting `DOCKER_FPM` on the `Makefile`.


## Using the generated packages
The package creates a krakend user to run the service and configures the service to run under systemd.

## Linux Distributions
* just any Linux (using the `tar.gz`)
* Ubuntu
* Debian
* CentOS/RedHat

49 changes: 27 additions & 22 deletions backend_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ package krakend

import (
"context"
"fmt"

amqp "github.com/devopsfaith/krakend-amqp"
cel "github.com/devopsfaith/krakend-cel"
cb "github.com/devopsfaith/krakend-circuitbreaker/gobreaker/proxy"
httpcache "github.com/devopsfaith/krakend-httpcache"
lambda "github.com/devopsfaith/krakend-lambda"
lua "github.com/devopsfaith/krakend-lua/proxy"
martian "github.com/devopsfaith/krakend-martian"
metrics "github.com/devopsfaith/krakend-metrics/gin"
oauth2client "github.com/devopsfaith/krakend-oauth2-clientcredentials"
opencensus "github.com/devopsfaith/krakend-opencensus"
pubsub "github.com/devopsfaith/krakend-pubsub"
juju "github.com/devopsfaith/krakend-ratelimit/juju/proxy"
"github.com/luraproject/lura/config"
"github.com/luraproject/lura/logging"
"github.com/luraproject/lura/proxy"
"github.com/luraproject/lura/transport/http/client"
httprequestexecutor "github.com/luraproject/lura/transport/http/client/plugin"
amqp "github.com/devopsfaith/krakend-amqp/v2"
cel "github.com/devopsfaith/krakend-cel/v2"
cb "github.com/devopsfaith/krakend-circuitbreaker/v2/gobreaker/proxy"
httpcache "github.com/devopsfaith/krakend-httpcache/v2"
lambda "github.com/devopsfaith/krakend-lambda/v2"
lua "github.com/devopsfaith/krakend-lua/v2/proxy"
martian "github.com/devopsfaith/krakend-martian/v2"
metrics "github.com/devopsfaith/krakend-metrics/v2/gin"
oauth2client "github.com/devopsfaith/krakend-oauth2-clientcredentials/v2"
opencensus "github.com/devopsfaith/krakend-opencensus/v2"
pubsub "github.com/devopsfaith/krakend-pubsub/v2"
juju "github.com/devopsfaith/krakend-ratelimit/v2/juju/proxy"
"github.com/luraproject/lura/v2/config"
"github.com/luraproject/lura/v2/logging"
"github.com/luraproject/lura/v2/proxy"
"github.com/luraproject/lura/v2/transport/http/client"
httprequestexecutor "github.com/luraproject/lura/v2/transport/http/client/plugin"
)

// NewBackendFactory creates a BackendFactory by stacking all the available middlewares:
Expand All @@ -41,11 +42,11 @@ func NewBackendFactory(logger logging.Logger, metricCollector *metrics.Metrics)
// NewBackendFactory creates a BackendFactory by stacking all the available middlewares and injecting the received context
func NewBackendFactoryWithContext(ctx context.Context, logger logging.Logger, metricCollector *metrics.Metrics) proxy.BackendFactory {
requestExecutorFactory := func(cfg *config.Backend) client.HTTPRequestExecutor {
var clientFactory client.HTTPClientFactory
clientFactory := client.NewHTTPClient
if _, ok := cfg.ExtraConfig[oauth2client.Namespace]; ok {
clientFactory = oauth2client.NewHTTPClient(cfg)
} else {
clientFactory = httpcache.NewHTTPClient(cfg)
clientFactory = httpcache.NewHTTPClient(cfg, clientFactory)
}
return opencensus.HTTPRequestExecutorFromConfig(clientFactory, cfg)
}
Expand All @@ -54,14 +55,18 @@ func NewBackendFactoryWithContext(ctx context.Context, logger logging.Logger, me
bf := pubsub.NewBackendFactory(ctx, logger, backendFactory)
backendFactory = bf.New
backendFactory = amqp.NewBackendFactory(ctx, logger, backendFactory)
backendFactory = lambda.BackendFactory(backendFactory)
backendFactory = lambda.BackendFactory(logger, backendFactory)
backendFactory = cel.BackendFactory(logger, backendFactory)
backendFactory = lua.BackendFactory(logger, backendFactory)
backendFactory = juju.BackendFactory(backendFactory)
backendFactory = juju.BackendFactory(logger, backendFactory)
backendFactory = cb.BackendFactory(backendFactory, logger)
backendFactory = metricCollector.BackendFactory("backend", backendFactory)
backendFactory = opencensus.BackendFactory(backendFactory)
return backendFactory

return func(remote *config.Backend) proxy.Proxy {
logger.Debug(fmt.Sprintf("[BACKEND: %s] Building the backend pipe", remote.URLPattern))
return backendFactory(remote)
}
}

type backendFactory struct{}
Expand Down
Loading

0 comments on commit 73603aa

Please sign in to comment.