-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add LiteFS example for Flipt in the examples directory (#2297)
* feat: add LiteFS example for Flipt in the examples directory * chore: add details section * chore: add newline to end of README file * chore: make changes to address comments on exposing ports
- Loading branch information
Showing
6 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM alpine | ||
|
||
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs | ||
COPY --from=flipt/flipt:latest /flipt /usr/local/bin/flipt | ||
|
||
RUN mkdir -p /etc/flipt/config && \ | ||
mkdir -p /var/opt/flipt | ||
|
||
COPY --from=flipt/flipt:latest /etc/flipt/config/default.yml /etc/flipt/config/default.yml | ||
RUN chown -R root:root /var/opt/flipt /etc/flipt | ||
|
||
ADD litefs.yml /etc/litefs.yml | ||
|
||
RUN apk add bash fuse3 sqlite ca-certificates | ||
|
||
ENTRYPOINT litefs mount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# LiteFS | ||
|
||
LiteFS is a distributed file system that replicates SQLite databases to other nodes at the file system level. It works by using [FUSE](https://www.kernel.org/doc/html/next/filesystems/fuse.html) to detect writes to the file system and determines how and if those should be replicated. | ||
|
||
This example will demonstrate how to run Flipt over LiteFS. | ||
|
||
## Requirements | ||
|
||
- [Docker](https://www.docker.com/) | ||
- [docker-compose](https://docs.docker.com/compose/install/) | ||
|
||
## Running the Example | ||
|
||
1. Run `docker-compose up` from this directory | ||
1. Open the Flipt UI (default: [http://localhost:8080](http://localhost:8080)) | ||
|
||
## Details | ||
|
||
`docker compose` will spin up two instances of Flipt with embedded SQLite databases. On top of these instances is an nginx proxy that will forward "write" requests, anything but `GET`, to the primary. `GET` requests will be served from the instance's embedded SQLite database. | ||
|
||
LiteFS describes a few [caveats](https://fly.io/docs/litefs/proxy/#how-it-works) that must be kept in mind. | ||
|
||
## Data | ||
|
||
You can view the data on any one of the instances located at [primary](http://localhost:8081) or the [replica](http://localhost:8082), but remember that writes will only happen on the primary or the nginx proxy, the replica instance will not be able to accpet writes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: '3' | ||
services: | ||
nginx: | ||
build: ./nginx | ||
ports: | ||
- "8080:80" | ||
primary: | ||
build: . | ||
privileged: true | ||
ports: | ||
- "8081:8080" | ||
environment: | ||
IS_PRIMARY: "true" | ||
replica: | ||
build: . | ||
ports: | ||
- "8082:8080" | ||
restart: on-failure | ||
privileged: true | ||
environment: | ||
IS_PRIMARY: "false" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
log: | ||
debug: true | ||
|
||
fuse: | ||
dir: "/var/opt/flipt" | ||
|
||
data: | ||
dir: "/var/lib/litefs" | ||
|
||
lease: | ||
type: "static" | ||
|
||
advertise-url: "http://primary:20202" | ||
|
||
candidate: $IS_PRIMARY | ||
|
||
exec: | ||
- cmd: "flipt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM nginx:alpine | ||
|
||
COPY ./nginx.conf /etc/nginx/nginx.conf | ||
EXPOSE 80 | ||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
http { | ||
upstream primary { | ||
server primary:8080; | ||
} | ||
upstream all { | ||
server primary:8080; | ||
server replica:8080; | ||
} | ||
server { | ||
listen 80; | ||
location / { | ||
# Basically all writes should go to this primary, | ||
# while reads go to everything else. | ||
if ($request_method ~ "(PUT|POST|PATCH|DELETE)") { | ||
proxy_pass http://primary; | ||
} | ||
proxy_pass http://all; | ||
} | ||
} | ||
} | ||
|
||
events { } |