Skip to content
Merged
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
19 changes: 19 additions & 0 deletions flagd-demo/assets/gitea.app.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
APP_NAME = "Gitea: Git with a cup of tea"
RUN_USER = "git"
[server]
PROTOCOL = "http"
DOMAIN = "http://0.0.0.0:3000"
ROOT_URL = "http://0.0.0.0:3000"
HTTP_ADDR = "0.0.0.0"
HTTP_PORT = "3000"
[database]
DB_TYPE = "postgres"
HOST = "0.0.0.0:5432"
NAME = "giteadb"
USER = "gitea"
PASSWD = "gitea"
[repository]
ENABLE_PUSH_CREATE_USER = true
DEFAULT_PUSH_CREATE_PRIVATE = false
[security]
INSTALL_LOCK = true
20 changes: 20 additions & 0 deletions flagd-demo/assets/gitea.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target

Wants=postgresql.service
After=postgresql.service

[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 166 additions & 0 deletions flagd-demo/assets/scripts/intro_foreground.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/bin/bash

DEBUG_VERSION=11
GITEA_VERSION=1.19
TEA_CLI_VERSION=0.9.2
FLAGD_VERSION=0.4.4

# Download and install flagd
wget -O flagd.tar.gz https://github.com/open-feature/flagd/releases/download/flagd%2Fv${FLAGD_VERSION}/flagd_${FLAGD_VERSION}_Linux_x86_64.tar.gz
tar -xf flagd.tar.gz
mv flagd_linux_x86_64 flagd
chmod +x flagd
mv flagd /usr/local/bin

# Download and install 'gitea' CLI: 'tea'
wget -O tea https://dl.gitea.com/tea/${TEA_CLI_VERSION}/tea-${TEA_CLI_VERSION}-linux-amd64
chmod +x tea
mv tea /usr/local/bin

#################
# Install postgresql for Gitea
###################
# Create the file repository configuration:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:
sudo apt-get update

# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
sudo apt-get -y install postgresql < /dev/null

# Add 'git' user
adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git

# Configure git for 'ubuntu' and 'git' users
git config --system user.email "me@faas.com"
git config --system user.name "OpenFeature"

# Download 'gitea'
wget -O gitea https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64
chmod +x gitea
mv gitea /usr/local/bin
chown git:git /usr/local/bin/gitea

# Set up directory structure for 'gitea'
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown git:git /etc/gitea
chmod 770 /etc/gitea

# Create systemd service for 'gitea'
# Ref: https://github.com/go-gitea/gitea/blob/main/contrib/systemd/gitea.service
mv ~/gitea.service /etc/systemd/system/gitea.service
# cat <<EOF > /etc/systemd/system/gitea.service
# [Unit]
# Description=Gitea (Git with a cup of tea)
# After=syslog.target
# After=network.target

# Wants=postgresql.service
# After=postgresql.service

# [Service]
# RestartSec=2s
# Type=simple
# User=git
# Group=git
# WorkingDirectory=/var/lib/gitea/
# ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
# Restart=always
# Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

# [Install]
# WantedBy=multi-user.target
# EOF

mv ~/gitea.app.ini /etc/gitea/app.ini
# cat <<EOF > /etc/gitea/app.ini
# APP_NAME = "Gitea: Git with a cup of tea"
# RUN_USER = "git"
# [server]
# PROTOCOL = "http"
# DOMAIN = "http://0.0.0.0:3000"
# ROOT_URL = "http://0.0.0.0:3000"
# HTTP_ADDR = "0.0.0.0"
# HTTP_PORT = "3000"
# [database]
# DB_TYPE = "postgres"
# HOST = "0.0.0.0:5432"
# NAME = "giteadb"
# USER = "gitea"
# PASSWD = "gitea"
# [repository]
# ENABLE_PUSH_CREATE_USER = true
# DEFAULT_PUSH_CREATE_PRIVATE = false
# [security]
# INSTALL_LOCK = true
# EOF
chown -R git:git /etc/gitea

# Set up gitea DB
sudo -u postgres -H -- psql --command "CREATE ROLE gitea WITH LOGIN PASSWORD 'gitea';" > /dev/null 2>&1
sudo -u postgres -H -- psql --command "CREATE DATABASE giteadb WITH OWNER gitea TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';" > /dev/null 2>&1

# Start gitea
systemctl start gitea
# Migrate the DB to create all required tables and config
sudo -u git gitea migrate -c=/etc/gitea/app.ini

# Create a user called 'openfeature'
# With password 'openfeature'
sudo -u git gitea admin user create \
--username=openfeature \
--password=openfeature \
--email=me@faas.com \
--must-change-password=false \
-c=/etc/gitea/app.ini

sudo -u git gitea admin user generate-access-token \
--username=openfeature \
--scopes=repo \
-c=/etc/gitea/app.ini \
--raw > /tmp/output.log

ACCESS_TOKEN=$(tail -n 1 /tmp/output.log)

# Wait for Gitea to be available
# Timeout after 2mins
timeout 120 bash -c 'while [[ "$(curl --insecure -s -o /dev/null -w ''%{http_code}'' http://0.0.0.0:3000)" != "200" ]]; do sleep 5; done'

# Authenticate the 'tea' CLI
tea login add \
--name=openfeature \
--user=openfeature \
--password=openfeature \
--url=http://0.0.0.0:3000 \
--token=$ACCESS_TOKEN > /dev/null 2>&1

# Create an empty repo called 'flags'
# Clone the template repo
tea repo create --name=flags --branch=main --init=true > /dev/null 2>&1
git clone http://openfeature:openfeature@0.0.0.0:3000/openfeature/flags
wget -O ~/flags/example_flags.flagd.json https://raw.githubusercontent.com/open-feature/flagd/main/config/samples/example_flags.flagd.json
cd ~/flags
git config credential.helper cache
git add -A
git commit -m "add flags"
git push

# ---------------------------------------------#
# 🎉 Installation Complete 🎉 #
# Please proceed now... #
# ---------------------------------------------#
42 changes: 42 additions & 0 deletions flagd-demo/finish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

## Congratulations! 🎉
In this tutorial you have built an OpenFeature compliant feature flag backend using flagd.

You now have a pure GitOps feature flagging system. You can change only a JSON file and your application will automatically leverage the changes.

This is just the beginning. flagd is capable of a lot more, such as providing multiple flag sources, local file usage or retrieval over HTTPS or gRPC.

## What's Next?

In this tutorial, interaction with the flagd API was via `curl`{{}}. In reality, you wouldn't want your application becoming reliant on flagd - that's the entire premise of OpenFeature. Your application should be able to say "getAFlag" without caring about the backend system (flagd in this case).

To achieve this, OpenFeature offers [language specific flagd providers](https://github.com/open-feature/flagd/blob/main/docs/usage/flagd_providers.md) which interact and "translate" to flagd code for you. If you are using Kubernetes - use the OpenFeature Operator which handles all of this complexity for you. Follow the [OpenFeature Operator hands-on tutorial](https://killercoda.com/open-feature/scenario/openfeature-operator-demo) or read the [OFO docs](https://github.com/open-feature/open-feature-operator/tree/main/docs).

For example, in Golang, your application code would look like this:

```
package main

import (
"github.com/open-feature/go-sdk-contrib/providers/flagd/pkg"
"github.com/open-feature/go-sdk/pkg/openfeature"
)

func main() {
openfeature.SetProvider(flagd.NewProvider(
flagd.WithHost("flagDHost"),
flagd.WithPort(8013),
))

// Get an openFeature client
client := openfeature.NewClient("myApp")

// Get flag values
value, err := client.BooleanValue(
context.Background(), "myFlagValue", false, openfeature.EvaluationContext{},
)
}
```

- [Get started with flagd](https://github.com/open-feature/flagd)
- Questions? [Join the community](https://docs.openfeature.dev/community/)
52 changes: 52 additions & 0 deletions flagd-demo/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{

"title": "OpenFeature flagd Demo",
"description": "New to feature flags? flagd provides a shortcut to a in-house feature flag solution. Follow this tutorial to see how.",
"details": {
"steps": [{
"title": "Initial Setup and Configuration",
"text": "step1.md"
}, {
"title": "What is flagd?",
"text": "step2.md"
}, {
"title": "Flag Evaluation and GitOps Changes",
"text": "step3.md"
}, {
"title": "Multiple Flag Sources",
"text": "step4.md"
}, {
"title": "Targeting Rules",
"text": "step5.md"
}, {
"title": "Fractional Evaluations",
"text": "step6.md"
}],
"intro": {
"text": "intro.md",
"foreground": "assets/scripts/intro_foreground.sh"
},
"finish": {
"text": "finish.md"
},
"assets": {
"host01": [{
"file": "gitea.app.ini",
"chmod": "+x",
"target": "~"
}, {
"file": "gitea.service",
"chmod": "+x",
"target": "~"
}]
}
},
"environment": {
"showdashboard": true,
"dashboard": "Dashboard",
"uilayout": "terminal"
},
"backend": {
"imageid": "ubuntu"
}
}
16 changes: 16 additions & 0 deletions flagd-demo/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# OpenFeature and flagd Demonstration

This demonstration will show a GitOps-based system and approach for storing, changing and evaluating feature flags.

The demo will use [flagd](https://github.com/open-feature/flagd), an OpenFeature compliant feature flag daemon & API layer but these principles apply to many open source or commercial feature flag vendors.


## The System
As you can see, things are being installed for you. When completed, the system will consist of:

- A local Git repo (using Gitea)
- `flagd`{{}} binary is downloaded
- `git`{{}} and `tea`{{}} binaries are available to interact with Git

## Be Patient...
Please wait until you see `🎉 Installation Complete 🎉` then click `Start` to begin.
10 changes: 10 additions & 0 deletions flagd-demo/step1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Gitea
Gitea is a local Git server. You can access it via these links.
- [Login to Gitea]({{TRAFFIC_HOST1_3000}}/user/login)
- [Open openfeature/flags repository]({{TRAFFIC_HOST1_3000}}/openfeature/flags)

The gitea username and password is:
- Username: `openfeature`
- Password: `openfeature`

You can use these details to log in to the browser interface and / or if prompted during command line exercises.
29 changes: 29 additions & 0 deletions flagd-demo/step2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# flagd
In this tutorial, we will use [flagd](https://github.com/open-feature/flagd). So what is flagd?

![flagd logical architecture](./assets/images/flagd-logical-architecture.png)

flagd is a open source self-contained feature flag evaluation engine which also provides an API so that you can retrieve flag values.

flagd doesn't just read a source of feature flags and present the information to you, flagd is **active**. flagd has built in ruleset capabilities and can (if you wish) **evaluate**. This tutorial will explore these capabilities later.

flagd is a fully featured reference implementation of OpenFeature. Use it to run your feature flag system at scale or as a stepping stone to a paid-for vendor.

> If you are familiar with OpenTelemetry, flagd is Prometheus or Jaeger.

flagd is OpenFeature compliant and can read flag configurations from many sources including `files`{{}}, `http(s)`{{}} endpoints and `kubernetes Custom Resource Definitions (CRDs)`{{}}.

# How does flagd work?
flagd reads one or more feature flag source(s), interprets them and presents an OpenFeature compliant API endpoint that can be queried.

flagd is compatible with `gRPC`{{}} and `HTTP`{{}} and has native support for metrics using Prometheus. In this demo we will read flags directly from a local Git repo using `HTTPS`{{}}.

## Start flagd

Start flagd and ask it to read files from a JSON source hosted online:

```
flagd start \
--port 8013 \
Comment thread
beeme1mr marked this conversation as resolved.
--uri {{TRAFFIC_HOST1_3000}}/openfeature/flags/raw/branch/main/example_flags.flagd.json
```{{exec}}
Loading