Skip to content

Commit

Permalink
adding github build workflow and release
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmvdl committed Oct 7, 2024
1 parent d25a8cf commit 87aa444
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 38 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Build and Release

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch: # Allows manual trigger

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install cross for cross-compiling
run: cargo install cross

- name: Extract version from Cargo.toml
id: get_version
run: |
VERSION=$(grep -m 1 '^version' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
if [ -z "$VERSION" ]; then
echo "Error: Version not found in Cargo.toml" >&2
exit 1
fi
echo "Extracted VERSION: $VERSION"
echo "$VERSION" > version.txt
echo "VERSION=$VERSION" >> $GITHUB_ENV # Set it as an environment variable for future steps
- name: Upload version as artifact
uses: actions/upload-artifact@v4
with:
name: version
path: version.txt

- name: Run trigger.sh to build app
run: ./trigger.sh

- name: Build binary for Linux x86-64 using cross
run: |
cross build --release --target x86_64-unknown-linux-gnu
env:
CARGO_TERM_COLOR: always

- name: Build binary for Linux aarch64 using cross
run: |
cross build --release --target aarch64-unknown-linux-gnu
env:
CARGO_TERM_COLOR: always

- name: Rename binaries before uploading
run: |
mv ./target/x86_64-unknown-linux-gnu/release/sidelb ./sidelb-x86_64
mv ./target/aarch64-unknown-linux-gnu/release/sidelb ./sidelb-aarch64
- name: Upload renamed built artifacts
uses: actions/upload-artifact@v4
with:
name: SideLB-binaries
path: |
sidelb-x86_64
sidelb-aarch64
release:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Only release from the main branch

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download version artifact
uses: actions/download-artifact@v4
with:
name: version

- name: Read version from file and set environment variable
id: read_version
run: |
VERSION=$(cat version.txt)
echo "VERSION=$VERSION" >> $GITHUB_ENV # Set it as an environment variable for later steps
- name: Download renamed built artifacts
uses: actions/download-artifact@v4
with:
name: SideLB-binaries

- name: Create GitHub tag with force-push
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git tag -f v$VERSION # Overwrite local tag if it exists
git push -f origin v$VERSION # Force-push to overwrite remote tag
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.VERSION }}
name: "Release v${{ env.VERSION }}"
files: |
sidelb-x86_64
sidelb-aarch64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77 changes: 39 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,38 @@ SideLB is written in Rust and primarily based on the tokio library.
## Setup structure example

```
+----------------------+
| Request |
+----------------------+
|
v
+----------------------+
| Backend Application |
+----------------------+
|
v
+----------------------+
| SideLB |
| 127.0.0.1:5432 |
+-----------------------------------------------------------------------------------------------------+ -> db.example.com
| | | | |
v v v v v
+-----------------+ +-----------------+ +-----------------+ +-----------------+ +-----------------+
| PostgreSQL 1 | | PostgreSQL 2 | | PostgreSQL 3 | | PostgreSQL 4 | | PostgreSQL 5 |
| 203.0.113.1:5432| | 203.0.113.2:5432| | 203.0.113.3:5432| | 203.0.113.4:5432| | 203.0.113.5:5432|
| 2001:db8::1:5432| | 2001:db8::2:5432| | 2001:db8::3:5432| | 2001:db8::4:5432| | 2001:db8::5:5432|
+-----------------+ +-----------------+ +-----------------+ +-----------------+ +-----------------+
+----------------------+
| Request |
+----------------------+
|
v
+----------------------+
| Backend Application |
+----------------------+
|
v
+----------------------+
| SideLB |
| 127.0.0.1:5432 |
+----------------------------------------------------------------------------------------------------------------------------+ -> db.example.com
| | | | |
v v v v v
+------------------------+------------------------+------------------------+------------------------+------------------------+
| CockroachDB 1 | CockroachDB 2 | CockroachDB 3 | CockroachDB 4 | CockroachDB 5 |
| 100.100.100.101:5432 | 100.100.100.102:5432 | 100.100.100.103:5432 | 100.100.100.104:5432 | 100.100.100.105:5432 |
| 2001:db8::1:5432 | 2001:db8::2:5432 | 2001:db8::3:5432 | 2001:db8::4:5432 | 2001:db8::5:5432 |
+------------------------+------------------------+------------------------+------------------------+------------------------+
```

# Usage

Your backend connects to SideLB, which then forwards the traffic to the appropriate backend services.
You can specify either static IP addresses for backend services or a ring domain (ring_domain) for dynamic DNS resolution.

Example Command:
Using a ring domain:

```bash
sidelb 127.0.0.1:5432 ring_domain=db.example.com:5432 mode=round-robin
Expand All @@ -57,9 +60,9 @@ In this example:
- `127.0.0.1:5432` is the address where SideLB listens for incoming connections from your backend.
- `ring_domain=db.example.com` allows SideLB to dynamically resolve backend IPs using DNS, e.g. your CockroachDB cluster.
- `mode=round-robin` ensures that traffic is evenly distributed across all resolved backend service members.
- `proto=tcp/udp` Set the desired protocol to use, you can select between TCP and UDP
- `proto=tcp/udp` Optional, sets the desired protocol to use, you can select between TCP and UDP, TCP is the default if not set.

Command with static IP addresses:
Using static IP addresses:

```bash
sidelb 127.0.0.1:5432 100.100.100.103:5432 100.100.100.104:5432 mode=least-connections
Expand All @@ -79,8 +82,6 @@ sidelb 127.0.0.1:5432 ring_domain=db.example.com:5432 mode=round-robin proto=tcp
and so on


This will

## Known Limitations

- **Load balancing is only relative with SideLB, as most likely many containers or servers consuming a service like a Database and SideLB instances don't communicate with each other at all ...
Expand Down Expand Up @@ -171,18 +172,18 @@ as the application itself is now able to load balance connections by itself with

If you set up a decentralized service like a CockRoachDB or similar, consider to split them up into Geo-Zones on DNS side, like:

- us.database.com (100.100.100.103, 100.100.100.104, 100.100.100.105)
- -> node01.us.my-service.com - 100.100.100.103
- -> node02.us.my-service.com - 100.100.100.104
- -> node03.us.my-service.com - 100.100.100.105
- de.database.com (101.100.100.103, 101.100.100.104, 101.100.100.105)
- -> node01.de.my-service.com - 101.100.100.103
- -> node02.de.my-service.com - 101.100.100.104
- -> node03.de.my-service.com - 101.100.100.105
- fr.database.com (102.100.100.103, 102.100.100.104, 102.100.100.105)
- -> node01.fr.my-service.com - 102.100.100.103
- -> node02.fr.my-service.com - 102.100.100.104
- -> node03.fr.my-service.com - 102.100.100.105
- us.database.com (100.100.100.101, 100.100.100.102, 100.100.100.103)
- -> node01.us.my-service.com - 100.100.100.101
- -> node02.us.my-service.com - 100.100.100.102
- -> node03.us.my-service.com - 100.100.100.103
- de.database.com (101.100.100.101, 101.100.100.102, 101.100.100.103)
- -> node01.de.my-service.com - 101.100.100.101
- -> node02.de.my-service.com - 101.100.100.102
- -> node03.de.my-service.com - 101.100.100.103
- fr.database.com (102.100.100.101, 102.100.100.102, 102.100.100.103)
- -> node01.fr.my-service.com - 102.100.100.101
- -> node02.fr.my-service.com - 102.100.100.102
- -> node03.fr.my-service.com - 102.100.100.103

Ensure that each node’s IP points to its corresponding geographic subdomain like us.database.com ...
This way you can make sure that your application always communicates with a group of servers that are geographically near to each other.

0 comments on commit 87aa444

Please sign in to comment.