From 434c9f8847291a460ea960f6264dfed8d408e92a Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Sun, 25 May 2025 03:43:21 -0400 Subject: [PATCH 01/23] adding gpg verification for gitea Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/scripts/intro_foreground.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index 58f6f8a..a54ce2a 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -1,7 +1,7 @@ #!/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 @@ -17,6 +17,22 @@ wget -O tea https://dl.gitea.com/tea/${TEA_CLI_VERSION}/tea-${TEA_CLI_VERSION}-l chmod +x tea mv tea /usr/local/bin +mkdir -p /tmp/gpg-temp +chmod 700 /tmp/gpg-temp + +# Download 'gitea' +wget -O gitea https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64 +chmod +x gitea + +wget -O gitea-${GITEA_VERSION}-linux-amd64.asc https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64.asc + +gpg --homedir /tmp/gpg-temp --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2 +gpg --homedir /tmp/gpg-temp --verify gitea-${GITEA_VERSION}-linux-amd64.asc gitea + +mv gitea /usr/local/bin + +rm -rf /tmp/gpg-temp + ################# # Install postgresql for Gitea ################### From 518383b65c0cff1358cd75e3ff9ef13fdf3a5798 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Sun, 25 May 2025 18:45:06 -0400 Subject: [PATCH 02/23] creating docker-compose to run the gitea & postgres simiplifying the script Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/docker-compose.yaml | 45 +++++++++++++++++++++++++++ flagd-demo/index.json | 4 +++ 2 files changed, 49 insertions(+) create mode 100644 flagd-demo/assets/docker-compose.yaml diff --git a/flagd-demo/assets/docker-compose.yaml b/flagd-demo/assets/docker-compose.yaml new file mode 100644 index 0000000..5bc1d8a --- /dev/null +++ b/flagd-demo/assets/docker-compose.yaml @@ -0,0 +1,45 @@ +networks: + gitea: + external: false + +services: + db: + image: postgres + restart: always + shm_size: 128mb + environment: + POSTGRES_USER: gitea + POSTGRES_PASSWORD: gitea + POSTGRES_DB: gitea + networks: + - gitea + volumes: + - gitea-db:/var/lib/postgresql/data + + server: + image: docker.gitea.com/gitea:1.23.8 + container_name: gitea + restart: always + environment: + - USER_UID=1000 + - USER_GID=1000 + - GITEA__database__DB_TYPE=postgres + - GITEA__database__HOST=db:5432 + - GITEA__database__NAME=gitea + - GITEA__database__USER=gitea + - GITEA__database__PASSWD=gitea + networks: + - gitea + volumes: + # - ~/gitea.app.ini:/data/gitea/conf/app.ini + - gitea:/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + ports: + - "3000:3000" + - "222:22" + depends_on: + - db +volumes: + gitea-db: + gitea: diff --git a/flagd-demo/index.json b/flagd-demo/index.json index 084687c..dc2a845 100644 --- a/flagd-demo/index.json +++ b/flagd-demo/index.json @@ -54,6 +54,10 @@ "file": "gitea.service", "chmod": "+x", "target": "~" + }, + { + "file": "docker-compose.yaml", + "target": "~" } ] } From a8ba4e7fca7e25b2584f71183ac2a8b365d062b3 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Sun, 25 May 2025 18:47:54 -0400 Subject: [PATCH 03/23] removing the manual gitea start up info & using the docker version to run gitea calls Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/scripts/intro_foreground.sh | 133 +++--------------- 1 file changed, 20 insertions(+), 113 deletions(-) diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index a54ce2a..39d86c6 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -12,42 +12,9 @@ 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 +rm flagd.tar.gz -mkdir -p /tmp/gpg-temp -chmod 700 /tmp/gpg-temp - -# Download 'gitea' -wget -O gitea https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64 -chmod +x gitea - -wget -O gitea-${GITEA_VERSION}-linux-amd64.asc https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64.asc - -gpg --homedir /tmp/gpg-temp --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2 -gpg --homedir /tmp/gpg-temp --verify gitea-${GITEA_VERSION}-linux-amd64.asc gitea - -mv gitea /usr/local/bin - -rm -rf /tmp/gpg-temp - -################# -# 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 +docker compose -f ~/docker-compose.yaml up -d # Add 'git' user adduser \ @@ -63,95 +30,35 @@ adduser \ 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 < /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 < /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 +# Wait for Gitea to be available +# Timeout after 2mins +timeout 120 bash -c 'while [[ "$(curl --insecure -s -o /dev/null -w "%{http_code}" http://localhost:3000)" != "200" ]]; do sleep 5; done' +# timeout 120 bash -c 'until curl -s -o /dev/null -w "%{http_code}" http://0.0.0.0:3000) # Create a user called 'openfeature' # With password 'openfeature' -sudo -u git gitea admin user create \ +# Using the gitea service started with docker +docker exec -u git gitea gitea admin user create \ --username=openfeature \ --password=openfeature \ --email=me@faas.com \ --must-change-password=false \ - -c=/etc/gitea/app.ini + -c data/gitea/conf/app.ini + +# sudo -u git gitea admin user generate-access-token \ +# --username=openfeature \ +# --scopes=repo \ +# -c=/etc/gitea/app.ini \ +# --raw > /tmp/output.log -sudo -u git gitea admin user generate-access-token \ +# ACCESS_TOKEN=$(tail -n 1 /tmp/output.log) + +ACCESS_TOKEN=$(docker exec -u git gitea gitea admin user generate-access-token \ --username=openfeature \ --scopes=repo \ - -c=/etc/gitea/app.ini \ +-c data/gitea/conf/app.ini \ --raw > /tmp/output.log - -ACCESS_TOKEN=$(tail -n 1 /tmp/output.log) +) # Wait for Gitea to be available # Timeout after 2mins From 142ae26894da51bb272c9b05dd13b9c993e259c7 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Sun, 25 May 2025 18:53:49 -0400 Subject: [PATCH 04/23] moving tea cli lower in the script to be after confirmation of gitea running Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/scripts/intro_foreground.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index 39d86c6..32c070b 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -60,9 +60,10 @@ ACCESS_TOKEN=$(docker exec -u git gitea gitea admin user generate-access-token \ --raw > /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' +# 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 # Authenticate the 'tea' CLI tea login add \ From 66ccf3105bc06522e02c98113c28d827a59fb024 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Mon, 26 May 2025 18:59:02 -0400 Subject: [PATCH 05/23] fixing killercoda docker-compose file route & change for flagd in compose with sqlite Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/docker-compose.yaml | 37 +++++++++------------------ flagd-demo/index.json | 2 +- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/flagd-demo/assets/docker-compose.yaml b/flagd-demo/assets/docker-compose.yaml index 5bc1d8a..07dae1f 100644 --- a/flagd-demo/assets/docker-compose.yaml +++ b/flagd-demo/assets/docker-compose.yaml @@ -3,19 +3,6 @@ networks: external: false services: - db: - image: postgres - restart: always - shm_size: 128mb - environment: - POSTGRES_USER: gitea - POSTGRES_PASSWORD: gitea - POSTGRES_DB: gitea - networks: - - gitea - volumes: - - gitea-db:/var/lib/postgresql/data - server: image: docker.gitea.com/gitea:1.23.8 container_name: gitea @@ -23,23 +10,23 @@ services: environment: - USER_UID=1000 - USER_GID=1000 - - GITEA__database__DB_TYPE=postgres - - GITEA__database__HOST=db:5432 - - GITEA__database__NAME=gitea - - GITEA__database__USER=gitea - - GITEA__database__PASSWD=gitea + - GITEA__security__INSTALL_LOCK=true + - GITEA__database__DB_TYPE=sqlite3 + - GITEA__server__DOMAIN=localhost + - GITEA__server__ROOT_URL=http://localhost:3000/ networks: - gitea volumes: - # - ~/gitea.app.ini:/data/gitea/conf/app.ini - - gitea:/data - - /etc/timezone:/etc/timezone:ro - - /etc/localtime:/etc/localtime:ro + - ./gitea:/data ports: - "3000:3000" - "222:22" - depends_on: - - db + + flagd: + image: ghcr.io/open-feature/flagd:v0.11.5 + command: sleep infinity + volumes: + - ./gitea:/repo + volumes: - gitea-db: gitea: diff --git a/flagd-demo/index.json b/flagd-demo/index.json index dc2a845..fb6680d 100644 --- a/flagd-demo/index.json +++ b/flagd-demo/index.json @@ -57,7 +57,7 @@ }, { "file": "docker-compose.yaml", - "target": "~" + "target": "/root/docker-compose.yaml" } ] } From 62f91183d6def7db956d0c16529829025ebdedf8 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Tue, 27 May 2025 01:26:12 -0400 Subject: [PATCH 06/23] adding gitea config to compose set up & update script to check with docker gitea/flagd Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/docker-compose.yaml | 24 ++-- flagd-demo/assets/scripts/intro_foreground.sh | 110 ++++++++---------- 2 files changed, 66 insertions(+), 68 deletions(-) diff --git a/flagd-demo/assets/docker-compose.yaml b/flagd-demo/assets/docker-compose.yaml index 07dae1f..3f69557 100644 --- a/flagd-demo/assets/docker-compose.yaml +++ b/flagd-demo/assets/docker-compose.yaml @@ -10,23 +10,33 @@ services: environment: - USER_UID=1000 - USER_GID=1000 - - GITEA__security__INSTALL_LOCK=true + - GITEA_DEFAULT__RUN_USER=git - GITEA__database__DB_TYPE=sqlite3 - - GITEA__server__DOMAIN=localhost - GITEA__server__ROOT_URL=http://localhost: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 volumes: - - ./gitea:/data + - gitea-data:/data + - gitea-config:/etc/gitea ports: - "3000:3000" - - "222:22" + # - "222:22" flagd: image: ghcr.io/open-feature/flagd:v0.11.5 - command: sleep infinity + # command: sleep infinity volumes: - - ./gitea:/repo + - gitea-repo:/repo + networks: + - gitea volumes: - gitea: + gitea-data: + gitea-config: + gitea-repo: diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index 32c070b..c044eea 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -1,88 +1,76 @@ #!/bin/bash +set -euo pipefail + DEBUG_VERSION=13 GITEA_VERSION=1.23.8 TEA_CLI_VERSION=0.9.2 FLAGD_VERSION=0.11.5 -# 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 - -rm flagd.tar.gz +# if [[ -n "${TRAFFIC_HOST1_3000:-}" ]]; then +# GITEA_URL="https://${TRAFFIC_HOST1_3000}" +# else +# GITEA_URL="http://localhost:3000" +# fi +echo "Starting Gitea & flagd docker containers..." docker compose -f ~/docker-compose.yaml up -d -# 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" - -# Wait for Gitea to be available -# Timeout after 2mins -timeout 120 bash -c 'while [[ "$(curl --insecure -s -o /dev/null -w "%{http_code}" http://localhost:3000)" != "200" ]]; do sleep 5; done' -# timeout 120 bash -c 'until curl -s -o /dev/null -w "%{http_code}" http://0.0.0.0:3000) - -# Create a user called 'openfeature' -# With password 'openfeature' +# Confirm gitea is functional before making calls +until docker exec gitea curl -s http://localhost:3000/api/v1/version | tee /tmp/version_output.txt | grep -q "version"; do + echo "Gitea not ready yet..." + sleep 2 +done + +# Create a user called 'openfeature' with password 'openfeature' # Using the gitea service started with docker +echo "Creating openfeature admin gitea user..." docker exec -u git gitea gitea admin user create \ - --username=openfeature \ - --password=openfeature \ - --email=me@faas.com \ - --must-change-password=false \ - -c data/gitea/conf/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) + --username=openfeature \ + --password=openfeature \ + --email=me@faas.com \ + --must-change-password=false || echo "User already exits." + # -c /etc/gitea -ACCESS_TOKEN=$(docker exec -u git gitea gitea admin user generate-access-token \ +# Setup access token for tea CLI set up +echo "Generating gitea access token for tea CLI..." +docker exec -u git gitea gitea admin user generate-access-token \ --username=openfeature \ - --scopes=repo \ --c data/gitea/conf/app.ini \ - --raw > /tmp/output.log -) + --scopes=all \ + --raw > /tmp/output.log + # -c /etc/gitea \ + +ACCESS_TOKEN=$(tail -n 1 /tmp/output.log) -# 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 +if ! type -P tea &> /dev/null; then + echo "Installing tea CLI..." + curl -sL https://dl.gitea.com/tea/${TEA_CLI_VERSION}/tea-${TEA_CLI_VERSION}-linux-amd64 -o /usr/local/bin/tea + chmod +x /usr/local/bin/tea +fi # 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 + --name local \ + --url=http://localhost: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 +tea repo create \ + --name=flags \ + --branch=main \ + --init=true >/dev/null + +git clone http://openfeature:openfeature@localhost: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 + +cd ~/flags git add -A -git commit -m "add flags" -git push +git commit -m "seed flags from flagd json" +git push origin main # ---------------------------------------------# # 🎉 Installation Complete 🎉 # From 3aad9a1ccc6577f8ecd530ab196a63c7bf90b4e9 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Tue, 27 May 2025 01:46:10 -0400 Subject: [PATCH 07/23] add to check if user already exists Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/scripts/intro_foreground.sh | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index c044eea..c90e50f 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -22,15 +22,20 @@ until docker exec gitea curl -s http://localhost:3000/api/v1/version | tee /tmp/ sleep 2 done -# Create a user called 'openfeature' with password 'openfeature' -# Using the gitea service started with docker -echo "Creating openfeature admin gitea user..." -docker exec -u git gitea gitea admin user create \ - --username=openfeature \ - --password=openfeature \ - --email=me@faas.com \ - --must-change-password=false || echo "User already exits." - # -c /etc/gitea +# Check if openfeature user exists +user_list=$(docker exec -u git gitea gitea admin user list 2>/dev/null) + +if ! echo "$user_list" | grep -qw "openfeature"; then + # Create a user called 'openfeature' with password 'openfeature' + # Using the gitea service started with docker + echo "Creating openfeature admin gitea user..." + docker exec -u git gitea gitea admin user create \ + --username=openfeature \ + --password=openfeature \ + --email=me@faas.com \ + --must-change-password=false + # -c /etc/gitea +fi # Setup access token for tea CLI set up echo "Generating gitea access token for tea CLI..." From f7a85c1b6922282e9a1b3fa826eb52110fc00632 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Tue, 27 May 2025 20:16:14 -0400 Subject: [PATCH 08/23] added logic to handle if script fails but user & token saved to keep moving properly Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/docker-compose.yaml | 3 ++ flagd-demo/assets/scripts/intro_foreground.sh | 32 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/flagd-demo/assets/docker-compose.yaml b/flagd-demo/assets/docker-compose.yaml index 3f69557..074017e 100644 --- a/flagd-demo/assets/docker-compose.yaml +++ b/flagd-demo/assets/docker-compose.yaml @@ -8,6 +8,9 @@ services: 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 diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index c90e50f..56076cc 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -17,16 +17,16 @@ echo "Starting Gitea & flagd docker containers..." docker compose -f ~/docker-compose.yaml up -d # Confirm gitea is functional before making calls -until docker exec gitea curl -s http://localhost:3000/api/v1/version | tee /tmp/version_output.txt | grep -q "version"; do +until docker exec gitea curl -s http://localhost:3000/api/v1/version | grep -q "version"; do echo "Gitea not ready yet..." sleep 2 done -# Check if openfeature user exists +# 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 "openfeature"; then - # Create a user called 'openfeature' with password 'openfeature' # Using the gitea service started with docker echo "Creating openfeature admin gitea user..." docker exec -u git gitea gitea admin user create \ @@ -35,12 +35,34 @@ if ! echo "$user_list" | grep -qw "openfeature"; then --email=me@faas.com \ --must-change-password=false # -c /etc/gitea +else + echo "User already exists. Continuing..." +fi + +echo "Checking for existing token ..." +user_tokens=$(docker exec gitea curl -s -H "Authorization: Basic $(echo -n "openfeature:openfeature" | base64)" \ + http://localhost:3000/api/v1/users/openfeature/tokens) + +# Output the token check into JSON array & looping to get id of tea_token +token_id=$(echo "$user_tokens" | jq -r '.[] | select(.name == "tea_token") | .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 \ + http://localhost:3000/api/v1/users/openfeature/tokens/$token_id \ + -H "Authorization: Basic $(echo -n "openfeature:openfeature" | 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 -# Setup access token for tea CLI set up -echo "Generating gitea access token for tea CLI..." +# Generate access token for tea CLI set up docker exec -u git gitea gitea admin user generate-access-token \ --username=openfeature \ + --token-name=tea_token \ --scopes=all \ --raw > /tmp/output.log # -c /etc/gitea \ From b83cc99e0c93261a36de84b18d65a3b0fc6fcf9c Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Wed, 28 May 2025 00:31:00 -0400 Subject: [PATCH 09/23] fix tea to get into gitea container, check if repo exists, and getting cloning/seeding to work Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/scripts/intro_foreground.sh | 78 ++++++++++++------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index 56076cc..e075c95 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -1,23 +1,27 @@ #!/bin/bash -set -euo pipefail - DEBUG_VERSION=13 GITEA_VERSION=1.23.8 TEA_CLI_VERSION=0.9.2 FLAGD_VERSION=0.11.5 -# if [[ -n "${TRAFFIC_HOST1_3000:-}" ]]; then -# GITEA_URL="https://${TRAFFIC_HOST1_3000}" -# else -# GITEA_URL="http://localhost:3000" -# fi +if [[ -n "${TRAFFIC_HOST1_3000:-}" ]]; then + GITEA_URL="http://${TRAFFIC_HOST1_3000}" +elif [[ -n "${GITEA_URL:-}" ]]; then + # Use passed-in GITEA_URL environment variable (e.g. host.docker.internal on Mac/Windows) + GITEA_URL="${GITEA_URL}" +else + # Fallback default + GITEA_URL="http://gitea:3000" +fi + +echo "Using Gitea URL: $GITEA_URL" echo "Starting Gitea & flagd docker containers..." docker compose -f ~/docker-compose.yaml up -d # Confirm gitea is functional before making calls -until docker exec gitea curl -s http://localhost:3000/api/v1/version | grep -q "version"; do +until docker exec gitea curl -s "$GITEA_URL/api/v1/version" | grep -q "version"; do echo "Gitea not ready yet..." sleep 2 done @@ -34,14 +38,13 @@ if ! echo "$user_list" | grep -qw "openfeature"; then --password=openfeature \ --email=me@faas.com \ --must-change-password=false - # -c /etc/gitea else echo "User already exists. Continuing..." fi echo "Checking for existing token ..." user_tokens=$(docker exec gitea curl -s -H "Authorization: Basic $(echo -n "openfeature:openfeature" | base64)" \ - http://localhost:3000/api/v1/users/openfeature/tokens) + "$GITEA_URL/api/v1/users/openfeature/tokens") # Output the token check into JSON array & looping to get id of tea_token token_id=$(echo "$user_tokens" | jq -r '.[] | select(.name == "tea_token") | .id') > /dev/null @@ -51,7 +54,7 @@ token_id=$(echo "$user_tokens" | jq -r '.[] | select(.name == "tea_token") | .id if [ -n "$token_id" ] && [ "$token_id" != "null" ]; then echo "Deleting existing token..." docker exec gitea curl -s -X DELETE \ - http://localhost:3000/api/v1/users/openfeature/tokens/$token_id \ + "$GITEA_URL/api/v1/users/openfeature/tokens/$token_id" \ -H "Authorization: Basic $(echo -n "openfeature:openfeature" | base64)" echo "Re-generating gitea access token for tea CLI..." else @@ -65,40 +68,61 @@ docker exec -u git gitea gitea admin user generate-access-token \ --token-name=tea_token \ --scopes=all \ --raw > /tmp/output.log - # -c /etc/gitea \ ACCESS_TOKEN=$(tail -n 1 /tmp/output.log) if ! type -P tea &> /dev/null; then echo "Installing tea CLI..." - curl -sL https://dl.gitea.com/tea/${TEA_CLI_VERSION}/tea-${TEA_CLI_VERSION}-linux-amd64 -o /usr/local/bin/tea - chmod +x /usr/local/bin/tea + # 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 # Authenticate the 'tea' CLI +echo "Authenticate tea CLI..." tea login add \ - --name local \ - --url=http://localhost:3000 \ - --token=$ACCESS_TOKEN > /dev/null 2>&1 + --name=local \ + --url="$GITEA_URL" \ + --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 +# Check if repo 'flags' exists +echo "Checking if repo 'flags' exists..." +repo_exists=$(tea repo list --json | jq -e '.[] | select(.name=="flags")' >/dev/null 2>&1 && echo "yes" || echo "no") -git clone http://openfeature:openfeature@localhost:3000/openfeature/flags +if [[ "$repo_exists" == "yes" ]]; then + echo "Repo 'flags' already exists. Skipping creation." +else + echo "Creating repo 'flags'..." + tea repo create --login=local --name=flags --branch=main --init=true >/dev/null +fi -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 +# Add 'git' user +adduser \ + --system \ + --shell /bin/bash \ + --gecos 'Git Version Control' \ + --group \ + --disabled-password \ + --home /home/git \ + git -git config credential.helper cache +# Configure git for 'ubuntu' and 'git' users +git config --system user.email "me@faas.com" +git config --system user.name "OpenFeature" + +git clone http://openfeature:openfeature@${GITEA_URL#http://}/openfeature/flags + +cd flags +wget -O example_flags.flagd.json https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json -cd ~/flags +git config credential.helper cache git add -A git commit -m "seed flags from flagd json" git push origin main +echo 🎉 Installation Complete 🎉 Please proceed now... + # ---------------------------------------------# # 🎉 Installation Complete 🎉 # # Please proceed now... # From b78765ba2349782b55c186a7161b400ec5c47ad9 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Wed, 28 May 2025 00:45:51 -0400 Subject: [PATCH 10/23] working on getting the flagd to depend on gitea to make sure starts Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/docker-compose.yaml | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/flagd-demo/assets/docker-compose.yaml b/flagd-demo/assets/docker-compose.yaml index 074017e..3703a37 100644 --- a/flagd-demo/assets/docker-compose.yaml +++ b/flagd-demo/assets/docker-compose.yaml @@ -1,6 +1,6 @@ networks: - gitea: - external: false + gitea-net: + driver: bridge services: server: @@ -8,38 +8,39 @@ services: 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 + # 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://localhost:3000/ + - 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 + - gitea-net volumes: - gitea-data:/data - - gitea-config:/etc/gitea + - gitea-data:/etc/gitea ports: - "3000:3000" - # - "222:22" flagd: image: ghcr.io/open-feature/flagd:v0.11.5 - # command: sleep infinity + container_name: flagd + command: start --port 8013 --uri http://gitea:3000/openfeature/flags/raw/branch/main/example_flags.flagd.json volumes: - - gitea-repo:/repo + - flagd-data:/repo networks: - - gitea + - gitea-net + depends_on: + - server volumes: gitea-data: - gitea-config: - gitea-repo: + flagd-data: From 256d9b2d202d4e9e99f30240c81be694ebbb4ecf Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Wed, 28 May 2025 00:59:34 -0400 Subject: [PATCH 11/23] adding flagd ports Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/docker-compose.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flagd-demo/assets/docker-compose.yaml b/flagd-demo/assets/docker-compose.yaml index 3703a37..1e56c4b 100644 --- a/flagd-demo/assets/docker-compose.yaml +++ b/flagd-demo/assets/docker-compose.yaml @@ -40,6 +40,8 @@ services: - gitea-net depends_on: - server + ports: + - "8013:8013" volumes: gitea-data: From a69873dbd448a5f44d1132bb6c22b7f21b9af574 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Wed, 28 May 2025 15:40:15 -0400 Subject: [PATCH 12/23] reverting to flagd binary in script for user to start and rest of setps stay consistent Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/docker-compose.yaml | 14 --------- flagd-demo/assets/scripts/intro_foreground.sh | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/flagd-demo/assets/docker-compose.yaml b/flagd-demo/assets/docker-compose.yaml index 1e56c4b..aded345 100644 --- a/flagd-demo/assets/docker-compose.yaml +++ b/flagd-demo/assets/docker-compose.yaml @@ -30,19 +30,5 @@ services: ports: - "3000:3000" - flagd: - image: ghcr.io/open-feature/flagd:v0.11.5 - container_name: flagd - command: start --port 8013 --uri http://gitea:3000/openfeature/flags/raw/branch/main/example_flags.flagd.json - volumes: - - flagd-data:/repo - networks: - - gitea-net - depends_on: - - server - ports: - - "8013:8013" - volumes: gitea-data: - flagd-data: diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index e075c95..640dd86 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -6,22 +6,23 @@ TEA_CLI_VERSION=0.9.2 FLAGD_VERSION=0.11.5 if [[ -n "${TRAFFIC_HOST1_3000:-}" ]]; then - GITEA_URL="http://${TRAFFIC_HOST1_3000}" -elif [[ -n "${GITEA_URL:-}" ]]; then - # Use passed-in GITEA_URL environment variable (e.g. host.docker.internal on Mac/Windows) - GITEA_URL="${GITEA_URL}" + 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 - GITEA_URL="http://gitea:3000" + BASE_URL="http://gitea" fi -echo "Using Gitea URL: $GITEA_URL" +echo "Using Gitea URL: $BASE_URL" -echo "Starting Gitea & flagd docker containers..." +echo "Starting Gitea docker container..." docker compose -f ~/docker-compose.yaml up -d # Confirm gitea is functional before making calls -until docker exec gitea curl -s "$GITEA_URL/api/v1/version" | grep -q "version"; do +until curl -s "$BASE_URL:3000/api/v1/version" | grep -q "version"; do echo "Gitea not ready yet..." sleep 2 done @@ -83,7 +84,7 @@ fi echo "Authenticate tea CLI..." tea login add \ --name=local \ - --url="$GITEA_URL" \ + --url="$BASE_URL:3000" \ --token="$ACCESS_TOKEN" # > /dev/null 2>&1 # Check if repo 'flags' exists @@ -111,7 +112,7 @@ adduser \ git config --system user.email "me@faas.com" git config --system user.name "OpenFeature" -git clone http://openfeature:openfeature@${GITEA_URL#http://}/openfeature/flags +git clone http://openfeature:openfeature@${BASE_URL#http://}:3000/openfeature/flags cd flags wget -O example_flags.flagd.json https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json @@ -121,6 +122,15 @@ git add -A 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... # ---------------------------------------------# From f2646ce53b2bb4001d53795de36b6e5403571e8e Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Wed, 28 May 2025 15:50:34 -0400 Subject: [PATCH 13/23] adding dockerfile mock env running the script to start flagd successfully & updating index.json to remove uneeded files Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/dockerfile | 26 ++++++++++++++++++++++++++ flagd-demo/index.json | 10 ---------- 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 flagd-demo/dockerfile diff --git a/flagd-demo/dockerfile b/flagd-demo/dockerfile new file mode 100644 index 0000000..910966d --- /dev/null +++ b/flagd-demo/dockerfile @@ -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"] \ No newline at end of file diff --git a/flagd-demo/index.json b/flagd-demo/index.json index fb6680d..4c7c370 100644 --- a/flagd-demo/index.json +++ b/flagd-demo/index.json @@ -45,16 +45,6 @@ }, "assets": { "host01": [ - { - "file": "gitea.app.ini", - "chmod": "+x", - "target": "~" - }, - { - "file": "gitea.service", - "chmod": "+x", - "target": "~" - }, { "file": "docker-compose.yaml", "target": "/root/docker-compose.yaml" From 0ddbd6772436face1f4a4adad872494ea5e639e8 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Wed, 28 May 2025 16:20:59 -0400 Subject: [PATCH 14/23] adding variables for passed info to script Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/scripts/intro_foreground.sh | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index 640dd86..c9870d3 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -4,6 +4,11 @@ DEBUG_VERSION=13 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" if [[ -n "${TRAFFIC_HOST1_3000:-}" ]]; then BASE_URL="http://${TRAFFIC_HOST1_3000}" @@ -31,32 +36,32 @@ done 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 "openfeature"; then +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=openfeature \ - --password=openfeature \ - --email=me@faas.com \ + --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 "openfeature:openfeature" | base64)" \ - "$GITEA_URL/api/v1/users/openfeature/tokens") +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 == "tea_token") | .id') > /dev/null +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 \ - "$GITEA_URL/api/v1/users/openfeature/tokens/$token_id" \ - -H "Authorization: Basic $(echo -n "openfeature:openfeature" | base64)" + "$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." @@ -65,8 +70,8 @@ fi # Generate access token for tea CLI set up docker exec -u git gitea gitea admin user generate-access-token \ - --username=openfeature \ - --token-name=tea_token \ + --username=$USER_NAME \ + --token-name=$TOKEN_NAME \ --scopes=all \ --raw > /tmp/output.log @@ -89,13 +94,13 @@ tea login add \ # Check if repo 'flags' exists echo "Checking if repo 'flags' exists..." -repo_exists=$(tea repo list --json | jq -e '.[] | select(.name=="flags")' >/dev/null 2>&1 && echo "yes" || echo "no") +repo_exists=$(tea repo list --json | jq -e '.[] | select(.name==$REPO_NAME)' >/dev/null 2>&1 && echo "yes" || echo "no") if [[ "$repo_exists" == "yes" ]]; then echo "Repo 'flags' already exists. Skipping creation." else echo "Creating repo 'flags'..." - tea repo create --login=local --name=flags --branch=main --init=true >/dev/null + tea repo create --login=local --name=$REPO_NAME --branch=main --init=true >/dev/null fi # Add 'git' user @@ -109,12 +114,12 @@ adduser \ git # Configure git for 'ubuntu' and 'git' users -git config --system user.email "me@faas.com" -git config --system user.name "OpenFeature" +git config --system user.email $USER_EMAIL +git config --system user.name $USER_NAME -git clone http://openfeature:openfeature@${BASE_URL#http://}:3000/openfeature/flags +git clone http://$USER_NAME:$USER_PASSWORD@${BASE_URL#http://}:3000/$USER_NAME/flags -cd flags +cd $REPO_NAME wget -O example_flags.flagd.json https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json git config credential.helper cache From 418856103f85d058a118a6c70ef1dcf01be3a7f7 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Thu, 29 May 2025 13:08:27 -0400 Subject: [PATCH 15/23] updating intro script to use proper docker-compse & index to expose ports Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/scripts/intro_foreground.sh | 8 +++++++- flagd-demo/index.json | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index c9870d3..84ed7e1 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -24,7 +24,13 @@ fi echo "Using Gitea URL: $BASE_URL" echo "Starting Gitea docker container..." -docker compose -f ~/docker-compose.yaml up -d +# 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 diff --git a/flagd-demo/index.json b/flagd-demo/index.json index 4c7c370..d1ff927 100644 --- a/flagd-demo/index.json +++ b/flagd-demo/index.json @@ -55,7 +55,13 @@ "environment": { "showdashboard": true, "dashboard": "Dashboard", - "uilayout": "terminal" + "uilayout": "terminal", + "ports": [ + { + "port": 3000, + "on": "host01" + } + ] }, "backend": { "imageid": "ubuntu" From 54407ec675747ddb4fa92fbde3bda2edc79d382f Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Thu, 29 May 2025 13:13:43 -0400 Subject: [PATCH 16/23] fixing index.json route for docker-compose Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/index.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flagd-demo/index.json b/flagd-demo/index.json index d1ff927..2a6bc6c 100644 --- a/flagd-demo/index.json +++ b/flagd-demo/index.json @@ -47,7 +47,7 @@ "host01": [ { "file": "docker-compose.yaml", - "target": "/root/docker-compose.yaml" + "target": "~/docker-compose.yaml" } ] } @@ -60,6 +60,10 @@ { "port": 3000, "on": "host01" + }, + { + "port": 8013, + "on": "host01" } ] }, From bf6ac8ec8aa5fd1e2b102d7630f88e411e41e3f7 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Thu, 29 May 2025 13:41:02 -0400 Subject: [PATCH 17/23] fixing docker-compose route Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/index.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flagd-demo/index.json b/flagd-demo/index.json index 2a6bc6c..8e3b9db 100644 --- a/flagd-demo/index.json +++ b/flagd-demo/index.json @@ -45,8 +45,8 @@ }, "assets": { "host01": [ - { - "file": "docker-compose.yaml", + { + "file": "assets/docker-compose.yaml", "target": "~/docker-compose.yaml" } ] From cbe6cf0e6324dd9a9bb307b64e028e5800b7be25 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Thu, 29 May 2025 14:04:46 -0400 Subject: [PATCH 18/23] trying to fix docker-compose not showing in killercoda Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- flagd-demo/assets/scripts/intro_foreground.sh | 6 ++++++ flagd-demo/index.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/flagd-demo/assets/scripts/intro_foreground.sh b/flagd-demo/assets/scripts/intro_foreground.sh index 84ed7e1..b5fb22b 100644 --- a/flagd-demo/assets/scripts/intro_foreground.sh +++ b/flagd-demo/assets/scripts/intro_foreground.sh @@ -10,6 +10,12 @@ 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 diff --git a/flagd-demo/index.json b/flagd-demo/index.json index 8e3b9db..fbd43ea 100644 --- a/flagd-demo/index.json +++ b/flagd-demo/index.json @@ -46,7 +46,7 @@ "assets": { "host01": [ { - "file": "assets/docker-compose.yaml", + "file": "flagd-demo/assets/docker-compose.yaml", "target": "~/docker-compose.yaml" } ] From d303768bbae2b26a4fa505c1d3089bce5780f17a Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Fri, 13 Jun 2025 19:02:05 -0400 Subject: [PATCH 19/23] updating to use newer script for newer node version Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- .../assets/scripts/intro_foreground.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh index e8e87a5..8cd9faa 100644 --- a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh +++ b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh @@ -21,8 +21,12 @@ 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 -o nodesource_setup.sh +sudo -E bash nodesource_setup.sh +sudo apt-get install -y nodejs +node -v # ----------------------------------- From 5d71a7ef0be2401537601fb41b3c7bd39f65a246 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Fri, 13 Jun 2025 19:10:14 -0400 Subject: [PATCH 20/23] trying to pipe install into next command so install actually works Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- .../assets/scripts/intro_foreground.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh index 8cd9faa..80a73f3 100644 --- a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh +++ b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh @@ -23,8 +23,7 @@ source ~/.bashrc # ----------------------------------- # 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 -o nodesource_setup.sh -sudo -E bash nodesource_setup.sh +curl -fsSL https://deb.nodesource.com/setup_23.x | sudo -E bash - &&\ sudo apt-get install -y nodejs node -v From 442b450224d627fe5457d5bcf3ae8f647480c44f Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Fri, 13 Jun 2025 19:20:50 -0400 Subject: [PATCH 21/23] trying to troubleshoot the git clone not being hit Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- .../assets/scripts/intro_foreground.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh index 80a73f3..e22a3bb 100644 --- a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh +++ b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh @@ -1,4 +1,6 @@ # DEBUG_VERSION=2 + +set -e # ----------------------------------- # APT Update # ----------------------------------- @@ -25,7 +27,6 @@ source ~/.bashrc # apt install -y nodejs < /dev/null curl -fsSL https://deb.nodesource.com/setup_23.x | sudo -E bash - &&\ sudo apt-get install -y nodejs -node -v # ----------------------------------- From 25a8d295f3fbfef7a3d963d2676f5bd20348781d Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Fri, 13 Jun 2025 19:27:27 -0400 Subject: [PATCH 22/23] trying different install instructions for script Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- .../assets/scripts/intro_foreground.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh index e22a3bb..1dcffa0 100644 --- a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh +++ b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh @@ -25,8 +25,10 @@ source ~/.bashrc # ----------------------------------- # 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 - &&\ -sudo apt-get install -y nodejs +curl -fsSL https://deb.nodesource.com/setup_23.x -o nodesource_setup.sh +bash nodesource_setup.sh +apt-get install -y nodejs +node -v # ----------------------------------- From f510af9ba9715e98c85d002b2b8e141ecbb7b7f7 Mon Sep 17 00:00:00 2001 From: bbland1 <104288486+bbland1@users.noreply.github.com> Date: Fri, 13 Jun 2025 19:42:16 -0400 Subject: [PATCH 23/23] making sure the script install pipes into the env to hopefully install node right after Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> --- .../assets/scripts/intro_foreground.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh index 1dcffa0..c03d986 100644 --- a/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh +++ b/five-minutes-to-feature-flags/assets/scripts/intro_foreground.sh @@ -25,9 +25,8 @@ source ~/.bashrc # ----------------------------------- # 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 -o nodesource_setup.sh -bash nodesource_setup.sh -apt-get install -y nodejs +curl -fsSL https://deb.nodesource.com/setup_23.x | sudo -E bash - &&\ +apt-get install -y nodejs < /dev/null node -v