Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
434c9f8
adding gpg verification for gitea
bbland1 May 25, 2025
518383b
creating docker-compose to run the gitea & postgres simiplifying the …
bbland1 May 25, 2025
a8ba4e7
removing the manual gitea start up info & using the docker version to…
bbland1 May 25, 2025
142ae26
moving tea cli lower in the script to be after confirmation of gitea …
bbland1 May 25, 2025
66ccf31
fixing killercoda docker-compose file route & change for flagd in com…
bbland1 May 26, 2025
62f9118
adding gitea config to compose set up & update script to check with d…
bbland1 May 27, 2025
3aad9a1
add to check if user already exists
bbland1 May 27, 2025
f7a85c1
added logic to handle if script fails but user & token saved to keep …
bbland1 May 28, 2025
b83cc99
fix tea to get into gitea container, check if repo exists, and gettin…
bbland1 May 28, 2025
b78765b
working on getting the flagd to depend on gitea to make sure starts
bbland1 May 28, 2025
256d9b2
adding flagd ports
bbland1 May 28, 2025
a69873d
reverting to flagd binary in script for user to start and rest of set…
bbland1 May 28, 2025
f2646ce
adding dockerfile mock env running the script to start flagd successf…
bbland1 May 28, 2025
0ddbd67
adding variables for passed info to script
bbland1 May 28, 2025
fed35b0
Merge pull request #1 from bbland1/fix/flagd-demo-failure
bbland1 May 29, 2025
4188561
updating intro script to use proper docker-compse & index to expose p…
bbland1 May 29, 2025
8984d0b
Merge pull request #2 from bbland1/fix/flagd-demo-failure
bbland1 May 29, 2025
54407ec
fixing index.json route for docker-compose
bbland1 May 29, 2025
75da057
Merge pull request #3 from bbland1/fix/flagd-demo-failure
bbland1 May 29, 2025
bf6ac8e
fixing docker-compose route
bbland1 May 29, 2025
6276458
Merge pull request #4 from bbland1/fix/flagd-demo-failure
bbland1 May 29, 2025
cbe6cf0
trying to fix docker-compose not showing in killercoda
bbland1 May 29, 2025
0c030de
Merge pull request #5 from bbland1/fix/flagd-demo-failure
bbland1 May 29, 2025
d303768
updating to use newer script for newer node version
bbland1 Jun 13, 2025
5d71a7e
trying to pipe install into next command so install actually works
bbland1 Jun 13, 2025
442b450
trying to troubleshoot the git clone not being hit
bbland1 Jun 13, 2025
25a8d29
trying different install instructions for script
bbland1 Jun 13, 2025
f510af9
making sure the script install pipes into the env to hopefully instal…
bbland1 Jun 13, 2025
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# DEBUG_VERSION=2

set -e
# -----------------------------------
# APT Update
# -----------------------------------
Expand All @@ -21,8 +23,11 @@ source ~/.bashrc
# -----------------------------------
# Installing Node
# -----------------------------------
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
apt install -y nodejs < /dev/null
# curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
# apt install -y nodejs < /dev/null
curl -fsSL https://deb.nodesource.com/setup_23.x | sudo -E bash - &&\
apt-get install -y nodejs < /dev/null
node -v


# -----------------------------------
Expand Down
34 changes: 34 additions & 0 deletions flagd-demo/assets/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
networks:
gitea-net:
driver: bridge

services:
server:
image: docker.gitea.com/gitea:1.23.8
container_name: gitea
restart: always
environment:
# configuration of the app.ini, the proper GITEA__group__VALUE keyword can be found:
# https://docs.gitea.com/administration/config-cheat-sheet
# the group is the value in () for no app.ini configuration
- USER_UID=1000
- USER_GID=1000
- GITEA_DEFAULT__RUN_USER=git
- GITEA__database__DB_TYPE=sqlite3
- GITEA__server__ROOT_URL=http://0.0.0.0:3000/
- GITEA__server__START_SSH_SERVER=false
- GITEA__server__DISABLE_SSH=true
- GITEA__security__INSTALL_LOCK=true
- GITEA__repository__ENABLE_PUSH_CREATE_USE=true
- GITEA__repository__DEFAULT_PUSH_CREATE_PRIVATE=true

networks:
- gitea-net
volumes:
- gitea-data:/data
- gitea-data:/etc/gitea
ports:
- "3000:3000"

volumes:
gitea-data:
258 changes: 124 additions & 134 deletions flagd-demo/assets/scripts/intro_foreground.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,119 @@
#!/bin/bash

DEBUG_VERSION=13
GITEA_VERSION=1.19
GITEA_VERSION=1.23.8
TEA_CLI_VERSION=0.9.2
FLAGD_VERSION=0.11.5
USER_NAME="openfeature"
PASSWORD="openfeature"
USER_EMAIL=me@faas.com
TOKEN_NAME="tea_token"
REPO_NAME="flags"

# Wait for Killercoda to set TRAFFIC_HOST1_3000
while [[ -z "${TRAFFIC_HOST1_3000:-}" ]]; do
echo "Waiting for TRAFFIC_HOST1_3000 to be set by Killercoda..."
sleep 1
done

if [[ -n "${TRAFFIC_HOST1_3000:-}" ]]; then
BASE_URL="http://${TRAFFIC_HOST1_3000}"
elif [[ -n "${BASE_URL:-}" ]]; then
# Use passed-in BASE_URL environment variable (e.g. host.docker.internal on Mac/Windows)
# Makes it easier to run locally with mock killercoda env dockerfile
BASE_URL="${BASE_URL}"
else
# Fallback default
BASE_URL="http://gitea"
fi

echo "Using Gitea URL: $BASE_URL"

echo "Starting Gitea docker container..."
# Killercoda doesn't use the `docker compose` syntax as of now
if type -P docker-compose &>/dev/null; then
docker-compose -f ~/docker-compose.yaml up -d
else
docker compose -f ~/docker-compose.yaml up -d
fi
# docker compose -f ~/docker-compose.yaml up -d

# Confirm gitea is functional before making calls
until curl -s "$BASE_URL:3000/api/v1/version" | grep -q "version"; do
echo "Gitea not ready yet..."
sleep 2
done

# First gitea is the container and the next is the call
user_list=$(docker exec -u git gitea gitea admin user list 2>/dev/null)

# Check if openfeature user exists
if ! echo "$user_list" | grep -qw "$USER_NAME"; then
# Using the gitea service started with docker
echo "Creating openfeature admin gitea user..."
docker exec -u git gitea gitea admin user create \
--username=$USER_NAME \
--password=$PASSWORD \
--email=$USER_EMAIL \
--must-change-password=false
else
echo "User already exists. Continuing..."
fi

echo "Checking for existing token ..."
user_tokens=$(docker exec gitea curl -s -H "Authorization: Basic $(echo -n "$USER_NAME:$USER_PASSWORD" | base64)" \
"$BASE_URL/api/v1/users/$USER_NAME/tokens")

# Output the token check into JSON array & looping to get id of tea_token
token_id=$(echo "$user_tokens" | jq -r '.[] | select(.name == $TOKEN_NAME) | .id') > /dev/null

# When the token ID exists delete to regenerate to adhere to gitea usage
# non-empty && not null
if [ -n "$token_id" ] && [ "$token_id" != "null" ]; then
echo "Deleting existing token..."
docker exec gitea curl -s -X DELETE \
"$BASE_URL/api/v1/users/$USER_NAME/tokens/$token_id" \
-H "Authorization: Basic $(echo -n "$USER_NAME:$USER_PASSWORD" | base64)"
echo "Re-generating gitea access token for tea CLI..."
else
echo "No existing tea_token."
echo "Generating gitea access token for tea CLI..."
fi

# Generate access token for tea CLI set up
docker exec -u git gitea gitea admin user generate-access-token \
--username=$USER_NAME \
--token-name=$TOKEN_NAME \
--scopes=all \
--raw > /tmp/output.log

# 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
ACCESS_TOKEN=$(tail -n 1 /tmp/output.log)

#################
# 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'
if ! type -P tea &> /dev/null; then
echo "Installing tea CLI..."
# 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
fi

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Authenticate the 'tea' CLI
echo "Authenticate tea CLI..."
tea login add \
--name=local \
--url="$BASE_URL:3000" \
--token="$ACCESS_TOKEN" # > /dev/null 2>&1

# Update the package lists:
sudo apt-get update
# Check if repo 'flags' exists
echo "Checking if repo 'flags' exists..."
repo_exists=$(tea repo list --json | jq -e '.[] | select(.name==$REPO_NAME)' >/dev/null 2>&1 && echo "yes" || echo "no")

# 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
if [[ "$repo_exists" == "yes" ]]; then
echo "Repo 'flags' already exists. Skipping creation."
else
echo "Creating repo 'flags'..."
tea repo create --login=local --name=$REPO_NAME --branch=main --init=true >/dev/null
fi

# Add 'git' user
adduser \
Expand All @@ -44,121 +126,29 @@ adduser \
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
git config --system user.email $USER_EMAIL
git config --system user.name $USER_NAME

ACCESS_TOKEN=$(tail -n 1 /tmp/output.log)
git clone http://$USER_NAME:$USER_PASSWORD@${BASE_URL#http://}:3000/$USER_NAME/flags

# 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'
cd $REPO_NAME
wget -O example_flags.flagd.json https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json

# 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/refs/tags/flagd/v${FLAGD_VERSION}/samples/example_flags.flagd.json
cd ~/flags
git config credential.helper cache
git add -A
git commit -m "add flags"
git push
git commit -m "seed flags from flagd json"
git push origin main

if ! type -P flagd &> /dev/null; then
echo "Installing 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
fi

echo 🎉 Installation Complete 🎉 Please proceed now...

# ---------------------------------------------#
# 🎉 Installation Complete 🎉 #
Expand Down
26 changes: 26 additions & 0 deletions flagd-demo/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:noble

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install -y wget git vim sudo ca-certificates curl gnupg lsb-release coreutils jq \
&& rm -rf /var/lib/apt/lists/*

# Install docker in docker to mock killercoda's ability to use docker
RUN mkdir -p /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && \
apt-get install -y docker-ce-cli docker-compose-plugin

# Add the necessary files needed to run
COPY assets/scripts/intro_foreground.sh /usr/local/bin/intro_foreground.sh
COPY assets/docker-compose.yaml /root/docker-compose.yaml

# Add executable permission
RUN chmod +x /usr/local/bin/intro_foreground.sh

# Run the script file
# CMD ["/usr/local/bin/intro_foreground.sh"]
Loading