Skip to content

Commit 29447f8

Browse files
authored
ci: update examples to latest spec (#104)
Updates all Lua examples to use the verify-hello-app action, and the correct environment variable names. This allows the flag key/SDK key to be changed as necessary without any hardcoding.
1 parent 35bb4f4 commit 29447f8

File tree

13 files changed

+82
-67
lines changed

13 files changed

+82
-67
lines changed

.github/actions/ci/action.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
rockspec:
1212
description: 'The rockspec file for the server-side SDK.'
1313
required: true
14+
aws-arn:
15+
description: 'The AWS role ARN to use for verifying the example output'
16+
required: true
1417

1518
runs:
1619
using: composite
@@ -54,16 +57,18 @@ runs:
5457
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib;./cpp-sdk/build-dynamic/release/lib
5558
LUA_INTERPRETER: ${{ contains(inputs.lua-version, 'jit') && 'luajit' || 'lua' }}
5659

57-
- name: Run hello-lua-server example
58-
if: ${{ !contains(inputs.lua-version, 'jit') }}
60+
- name: Copy get_from_env to directory above this
5961
shell: bash
6062
run: |
61-
cd ./examples/hello-lua-server
62-
lua hello.lua | tee output.txt
63-
grep -F "is false for this user" output.txt || (echo "Expected false evaluation!" && exit 1)
63+
cp -r ./examples/env-helper ../env-helper
64+
- uses: launchdarkly/gh-actions/actions/verify-hello-app@verify-hello-app-v2.0.0
65+
if: ${{ !contains(inputs.lua-version, 'jit') }}
66+
name: 'Verify hello-lua-server example'
6467
env:
65-
LD_SDK_KEY: "fake-sdk-key"
6668
# Needed because boost isn't installed in default system paths, which is
6769
# what the C++ Server-side SDK shared object expects.
6870
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib
69-
LUA_INTERPRETER: ${{ contains(inputs.lua-version, 'jit') && 'luajit' || 'lua' }}
71+
with:
72+
use_server_key: true
73+
role_arn: ${{ inputs.aws-arn }}
74+
command: lua ./examples/hello-lua-server/hello.lua

.github/workflows/ci.yml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jobs:
2727
linux-build:
2828
needs: rockspecs
2929
runs-on: ubuntu-latest
30-
30+
permissions:
31+
id-token: write
32+
contents: read
3133
strategy:
3234
fail-fast: false
3335
matrix:
@@ -40,16 +42,18 @@ jobs:
4042
with:
4143
lua-version: ${{ matrix.version }}
4244
rockspec: ${{ matrix.package }}
45+
aws-arn: ${{ vars.AWS_ROLE_ARN_EXAMPLES }}
4346

4447

4548
web-server-examples:
4649
runs-on: ubuntu-latest
50+
permissions:
51+
id-token: write
52+
contents: read
4753
strategy:
4854
fail-fast: false
4955
matrix:
5056
name: ["hello-haproxy", "hello-nginx"]
51-
env:
52-
LD_SDK_KEY: foo
5357
steps:
5458
- uses: actions/checkout@v4
5559
- name: Get C++ Versions
@@ -60,25 +64,33 @@ jobs:
6064
docker build \
6165
--build-arg="CPP_SDK_VERSION=${{ steps.cpp-versions.outputs.sdk }}" \
6266
-t launchdarkly:${{ matrix.name }} -f ./examples/${{ matrix.name }}/Dockerfile .
63-
- name: Run ${{ matrix.name }} container in background
64-
run: |
65-
docker run -dit --rm --name ${{ matrix.name }} -p 8123:80 --env LD_SDK_KEY="$LD_SDK_KEY" launchdarkly:${{ matrix.name }}
66-
- name: Evaluate feature flag
67-
run: |
68-
curl --retry 5 --retry-all-errors --retry-delay 1 -s -v http://localhost:8123 | tee response.txt
69-
grep -F "is false for this user" response.txt || (echo "Expected false evaluation!" && exit 1)
67+
68+
- uses: launchdarkly/gh-actions/actions/verify-hello-app@verify-hello-app-v2.0.0
69+
name: 'Verify ${{ matrix.name}} example output'
70+
with:
71+
use_server_key: true
72+
role_arn: ${{ vars.AWS_ROLE_ARN_EXAMPLES }}
73+
command: |
74+
docker run -dit --rm --name ${{ matrix.name }} -p 8123:80 \
75+
--env LAUNCHDARKLY_SDK_KEY="$LAUNCHDARKLY_SDK_KEY" \
76+
--env LAUNCHDARKLY_FLAG_KEY="$LAUNCHDARKLY_FLAG_KEY" \
77+
launchdarkly:${{ matrix.name }}
78+
curl --retry 5 --retry-all-errors --retry-delay 1 -s -v http://localhost:8123
79+
7080
- name: Stop ${{ matrix.name }} container
7181
run: |
7282
docker stop ${{ matrix.name }}
7383
84+
7485
plain-lua-examples:
7586
runs-on: ubuntu-latest
87+
permissions:
88+
id-token: write
89+
contents: read
7690
strategy:
7791
fail-fast: false
7892
matrix:
7993
name: [ "hello-debian"]
80-
env:
81-
LD_SDK_KEY: foo
8294
steps:
8395
- uses: actions/checkout@v4
8496
- name: Get C++ Versions
@@ -89,9 +101,13 @@ jobs:
89101
docker build \
90102
--build-arg="CPP_SDK_VERSION=${{ steps.cpp-versions.outputs.sdk }}" \
91103
-t launchdarkly:${{ matrix.name }} -f ./examples/${{ matrix.name }}/Dockerfile .
92-
- name: Run ${{ matrix.name }} container in foreground
93-
run: |
94-
docker run --env LD_SDK_KEY="$LD_SDK_KEY" launchdarkly:${{ matrix.name }} > logs.txt
95-
- name: Verify output
96-
run: |
97-
grep -F "is false for this user" logs.txt || (echo "Expected false evaluation!" && exit 1)
104+
- uses: launchdarkly/gh-actions/actions/verify-hello-app@verify-hello-app-v2.0.0
105+
name: 'Verify ${{ matrix.name}} example output'
106+
with:
107+
use_server_key: true
108+
role_arn: ${{ vars.AWS_ROLE_ARN_EXAMPLES }}
109+
command: |
110+
docker run \
111+
--env LAUNCHDARKLY_SDK_KEY="$LAUNCHDARKLY_SDK_KEY" \
112+
--env LAUNCHDARKLY_FLAG_KEY="$LAUNCHDARKLY_FLAG_KEY" \
113+
launchdarkly:${{ matrix.name }}

.github/workflows/cpp-versions.yml

Whitespace-only changes.

examples/hello-debian/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ COPY launchdarkly-server-sdk.c .
4040

4141
# The example expects to find the env-helper script up one directory, so preserve that structure
4242
# when copying. The purpose of env-helper is to allow the flag key & SDK keys to be injected via
43-
# environment variable (LD_SDK_KEY and LD_FLAG_KEY).
43+
# environment variable (LAUNCHDARKLY_SDK_KEY and LAUNCHDARKLY_FLAG_KEY).
4444
COPY ./examples/hello-debian/hello.lua hello-debian/
4545
COPY ./examples/env-helper env-helper
4646

examples/hello-debian/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ We've built a minimal dockerized example of using the Lua SDK within a Debian Bo
88
`docker build -t hello-debian -f ./examples/hello-debian/Dockerfile .`.
99
2. Run the demo with
1010
```bash
11-
docker run --rm --name hello-debian --env LD_SDK_KEY="my-sdk-key" --env LD_FLAG_KEY="my-boolean-flag" hello-debian
11+
docker run --rm --name hello-debian --env LAUNCHDARKLY_SDK_KEY="my-sdk-key" --env LAUNCHDARKLY_FLAG_KEY="my-boolean-flag" hello-debian
1212
```
13-
3. **Note:** the SDK key and flag key are passed with environment variables into the container. The `LD_FLAG_KEY` should be a boolean-type flag in your environment. If you don't pass
14-
`LD_FLAG_KEY`, then the default flag key `my-boolean-flag` will be used.
13+
3. **Note:** the SDK key and flag key are passed with environment variables into the container. The `LAUNCHDARKLY_FLAG_KEY` should be a boolean-type flag in your environment. If you don't pass
14+
`LAUNCHDARKLY_FLAG_KEY`, then the default flag key `my-boolean-flag` will be used.
1515
1616
You should receive the message:
17-
> Feature flag is <true/false> for this user context
17+
> The (flag key) feature flag evaluates to (true/false).

examples/hello-debian/hello.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ local get_from_env_or_default = dofile("../env-helper/get_from_env_or_default.lu
55
local MY_SDK_KEY = ""
66

77
-- Set MY_FLAG_KEY to the boolean-type feature flag key you want to evaluate.
8-
local MY_FLAG_KEY = "my-boolean-flag"
8+
local MY_FLAG_KEY = ""
99

1010

1111
local config = {}
1212

13-
local sdk_key = get_from_env_or_default("LD_SDK_KEY", MY_SDK_KEY)
13+
local sdk_key = get_from_env_or_default("LAUNCHDARKLY_SDK_KEY", MY_SDK_KEY)
1414
local client = ld.clientInit(sdk_key, 1000, config)
1515

1616
local user = ld.makeContext({
@@ -20,6 +20,6 @@ local user = ld.makeContext({
2020
}
2121
})
2222

23-
local flag_key = get_from_env_or_default("LD_FLAG_KEY", MY_FLAG_KEY)
23+
local flag_key = get_from_env_or_default("LAUNCHDARKLY_FLAG_KEY", MY_FLAG_KEY)
2424
local value = client:boolVariation(user, flag_key, false)
25-
print("Feature flag ".. flag_key .." is "..tostring(value).." for this user context")
25+
print("The ".. flag_key .." feature flag evaluates to "..tostring(value)..".")

examples/hello-haproxy/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ We've built a minimal dockerized example of using the Lua SDK with [HAProxy](htt
77
1. On the command line from the **root** of the repo, build the image from this directory with `docker build -t hello-haproxy -f ./examples/hello-haproxy/Dockerfile .`.
88
2. Run the demo with:
99
```bash
10-
docker run -it --rm --name hello-haproxy -p 8123:8123 --env LD_SDK_KEY="my-sdk-key" --env LD_FLAG_KEY="my-boolean-flag" hello-haproxy
10+
docker run -it --rm --name hello-haproxy -p 8123:8123 --env LAUNCHDARKLY_SDK_KEY="my-sdk-key" --env LAUNCHDARKLY_FLAG_KEY="my-boolean-flag" hello-haproxy
1111
```
12-
3. **Note:** the SDK key and flag key are passed with environment variables into the container. The `LD_FLAG_KEY` should be a boolean-type flag in your environment.
12+
3. **Note:** the SDK key and flag key are passed with environment variables into the container. The `LAUNCHDARKLY_FLAG_KEY` should be a boolean-type flag in your environment.
1313
4. Open `localhost:8123` in your browser. Toggle the flag on to see a change in the page (refresh the page.)
1414

1515
You should receive the message:
16-
> Feature flag is <true/false> for this user context
16+
> The (flag key) feature flag evaluates to (true/false).

examples/hello-haproxy/service.lua

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ local get_from_env_or_default = require("get_from_env_or_default")
88
local MY_SDK_KEY = ""
99

1010
-- Set MY_FLAG_KEY to the boolean-type feature flag key you want to evaluate.
11-
local MY_FLAG_KEY = "my-boolean-flag"
11+
local MY_FLAG_KEY = ""
1212

1313
local config = {}
14-
local sdk_key = get_from_env_or_default("LD_SDK_KEY", MY_SDK_KEY)
14+
local sdk_key = get_from_env_or_default("LAUNCHDARKLY_SDK_KEY", MY_SDK_KEY)
1515
local client = ld.clientInit(sdk_key, 1000, config)
1616

17-
local flag_key = get_from_env_or_default("LD_FLAG_KEY", MY_FLAG_KEY)
17+
local flag_key = get_from_env_or_default("LAUNCHDARKLY_FLAG_KEY", MY_FLAG_KEY)
1818

1919
core.register_service("launchdarkly", "http", function(applet)
2020
applet:start_response()
@@ -26,9 +26,6 @@ core.register_service("launchdarkly", "http", function(applet)
2626
}
2727
})
2828

29-
if client:boolVariation(user, flag_key, false) then
30-
applet:send("<p>Feature flag " .. flag_key .. " is true for this user context</p>")
31-
else
32-
applet:send("<p>Feature flag " .. flag_key .. " is false for this user context</p>")
33-
end
29+
local flag_value = client:boolVariation(user, flag_key, false)
30+
applet:send("<p>The " .. flag_key .. " feature flag evaluates to " .. tostring(flag_value) .. ".</p>")
3431
end)

examples/hello-lua-server/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Then, use the Lua interpreter to run `hello.lua`:
77
lua hello.lua
88
```
99

10-
If you'd rather use environment variables to specify the SDK key or flag key, set `LD_SDK_KEY` or `LD_FLAG_KEY`.
10+
If you'd rather use environment variables to specify the SDK key or flag key, set `LAUNCHDARKLY_SDK_KEY` or `LAUNCHDARKLY_FLAG_KEY`.
1111
```bash
12-
LD_SDK_KEY=my-sdk-key LD_FLAG_KEY=my-boolean-flag lua hello.lua
12+
LAUNCHDARKLY_SDK_KEY=my-sdk-key LAUNCHDARKLY_FLAG_KEY=my-boolean-flag lua hello.lua
1313
```
1414

1515
The program should output:
16-
> Feature flag is <true/false> for this user context
16+
> The (flag key) feature flag evaluates to (true/false).

examples/hello-lua-server/hello.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ local get_from_env_or_default = dofile("../env-helper/get_from_env_or_default.lu
55
local MY_SDK_KEY = ""
66

77
-- Set MY_FLAG_KEY to the boolean-type feature flag key you want to evaluate.
8-
local MY_FLAG_KEY = "my-boolean-flag"
8+
local MY_FLAG_KEY = ""
99

1010

1111
local config = {}
1212

13-
local sdk_key = get_from_env_or_default("LD_SDK_KEY", MY_SDK_KEY)
13+
local sdk_key = get_from_env_or_default("LAUNCHDARKLY_SDK_KEY", MY_SDK_KEY)
1414
local client = ld.clientInit(sdk_key, 1000, config)
1515

1616
local user = ld.makeContext({
@@ -20,6 +20,6 @@ local user = ld.makeContext({
2020
}
2121
})
2222

23-
local flag_key = get_from_env_or_default("LD_FLAG_KEY", MY_FLAG_KEY)
23+
local flag_key = get_from_env_or_default("LAUNCHDARKLY_FLAG_KEY", MY_FLAG_KEY)
2424
local value = client:boolVariation(user, flag_key, false)
25-
print("Feature flag ".. flag_key .." is "..tostring(value).." for this user context")
25+
print("The ".. flag_key .." feature flag evaluates to "..tostring(value)..".")

0 commit comments

Comments
 (0)