Skip to content

Commit

Permalink
Add License and Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alinz committed Jul 13, 2024
1 parent 900d7bf commit 47bb745
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 6 deletions.
16 changes: 10 additions & 6 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
The MIT License (MIT)
Copyright 2024, Ali Najafizadeh

Copyright (c) 2024 Ali Najafizadeh
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
http://www.apache.org/licenses/LICENSE-2.0

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
174 changes: 174 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
```
____ _
| __ ) __ _| | _____ _ __
| _ \ / _ | |/ / _ \ '__|
| |_) | (_| | < __/ |
|____/ \__,_|_|\_\___|_|
```

# Introduction

Baker is a dynamic HTTP reverse proxy with a focus on extensibility and flexibility. It is designed to adapt to a variety of orchestration engines and provides dynamic configuration capabilities, eliminating the need to restart the reverse proxy when changing configurations.

# Features

- Docker driver integration for Docker event listening.
- Exposed driver interface for easy integration with other orchestration engines.
- Dynamic configuration capabilities.
- Custom trie data structure for fast path pattern matching.
- Can be used as a library, as it implements the HTTP Handler interface.
- High extensibility due to exposed interfaces for most components.
- Middleware-like feature for modifying incoming and outgoing traffic.
- Default load balancing.
- Automatic SSL certificate updates and creation using Let's Encrypt.
- Configurable rate limiter per domain and path.

# Usage

First, we need to run Baker inside docker. The following `docker-compose.yml`

```yml
version: "3.5"

services:
baker:
image: alinz/baker:latest

environment:
# enables ACME system
- BAKER_ACME=NO
# folder location which holds all certification
- BAKER_ACME_PATH=/acme/cert
- BAKER_LOG_LEVEL=DEBUG

ports:
- "80:80"
- "443:443"

# make sure to use the right network
networks:
- baker

volumes:
# make sure it can access to main docker.sock
- /var/run/docker.sock:/var/run/docker.sock
- ./acme/cert:/acme/cert

networks:
baker:
name: baker_net
driver: bridge
```
Then for each service, the following `docker-compose` can be used. The only requirements are labels and networks. Make sure both baker and service have the same network interface

```yml
version: "3.5"
services:
service1:
image: service:latest
labels:
- "baker.enable=true"
- "baker.network=baker_net"
- "baker.service.port=8000"
- "baker.service.ping=/config"
networks:
- baker
networks:
baker:
external:
name: baker_net
```

The service should expose a REST endpoint that returns a configuration. This endpoint acts as a health check and provides real-time configuration.

```json
[
{
"domain": "example.com",
"path": "/sample1",
"ready": true
},
{
"domain": "example.com",
"path": "/sample2",
"ready": false
},
{
"domain": "example1.com",
"path": "/sample1*",
"ready": true,
"rules": [
{
"type": "ReplacePath",
"args": {
"search": "/sample1",
"replace": "",
"times": 1
}
}
]
}
]
```

# Middleware

Baker comes with several built-in middleware:

### ReplacePath

Remove a specific path from an incoming request. Service will be receiving the modified path.
to use this middleware, simply add the following rule to the rules section of the configuration

```json
{
"type": "ReplacePath",
"args": {
"search": "/sample1",
"replace": "",
"times": 1
}
}
```

### AppendPath

Add a path at the beginning and end of the path
to use this middleware, simply add the following rule to the rules section of the configuration

```json
{
"type": "AppendPath",
"args": {
"begin": "/begin",
"end": "/end"
}
}
```

### RateLimiter

Add a rate limiter for a specific domain and path
to use this middleware, simply add the following rule to the riles sections of the configuration

```json
{
"type": "RateLimiter",
"args": {
"request_limit": 100,
"window_duration": "60s"
}
}
```

the above configuration means, in one minute, 100 requests should be routed per individual IP address, if that is exceeded, a 429 HTTP status will be sent back to the client.

## License

Baker is licensed under the [Apache v2](LICENSE.md).

0 comments on commit 47bb745

Please sign in to comment.