Skip to content

Commit f6c87d7

Browse files
authored
ci: add hello-debian example (#101)
Adds an example that runs in a `debian:bookworm` container.
1 parent 3a74c0e commit f6c87d7

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
rockspec: ${{ matrix.package }}
4343

4444

45-
examples:
45+
web-server-examples:
4646
runs-on: ubuntu-latest
4747
strategy:
4848
fail-fast: false
@@ -65,3 +65,23 @@ jobs:
6565
- name: Stop ${{ matrix.name }} container
6666
run: |
6767
docker stop ${{ matrix.name }}
68+
69+
plain-lua-examples:
70+
runs-on: ubuntu-latest
71+
strategy:
72+
fail-fast: false
73+
matrix:
74+
name: [ "hello-debian"]
75+
env:
76+
LD_SDK_KEY: foo
77+
steps:
78+
- uses: actions/checkout@v4
79+
- name: Build ${{ matrix.name }} image
80+
run: |
81+
docker build -t launchdarkly:${{ matrix.name }} -f ./examples/${{ matrix.name }}/Dockerfile .
82+
- name: Run ${{ matrix.name }} container in foreground
83+
run: |
84+
docker run --env LD_SDK_KEY="$LD_SDK_KEY" launchdarkly:${{ matrix.name }} > logs.txt
85+
- name: Verify output
86+
run: |
87+
grep -F "is false for this user" logs.txt || (echo "Expected false evaluation!" && exit 1)

examples/hello-debian/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM debian:bookworm
2+
3+
# {{ x-release-please-start-version }}
4+
ARG VERSION=2.1.0
5+
# {{ x-release-please-end }}
6+
7+
# For unknown reasons, it appears that boost.json and boost.url aren't included in the
8+
# libboost-all package.
9+
10+
RUN apt-get update && apt-get install -y \
11+
git netbase curl libssl-dev libssl3 apt-transport-https ca-certificates \
12+
software-properties-common \
13+
cmake ninja-build build-essential \
14+
libboost1.81-all-dev libboost-json1.81-dev libboost-url1.81-dev \
15+
luarocks
16+
17+
18+
RUN mkdir cpp-sdk-libs
19+
RUN git clone --branch launchdarkly-cpp-server-v3.3.3 https://github.com/launchdarkly/cpp-sdks.git && \
20+
cd cpp-sdks && \
21+
mkdir build-dynamic && \
22+
cd build-dynamic && \
23+
cmake -GNinja \
24+
-DLD_BUILD_EXAMPLES=OFF \
25+
-DBUILD_TESTING=OFF \
26+
-DLD_BUILD_SHARED_LIBS=ON \
27+
-DLD_DYNAMIC_LINK_OPENSSL=ON .. && \
28+
cmake --build . --target launchdarkly-cpp-server && \
29+
cmake --install . --prefix=../../cpp-sdk-libs
30+
31+
32+
33+
RUN mkdir hello-debian
34+
35+
# The source .c file and the rockspec are needed to compile the LuaRock.
36+
COPY launchdarkly-server-sdk-${VERSION}-0.rockspec .
37+
COPY launchdarkly-server-sdk.c .
38+
39+
# The example expects to find the env-helper script up one directory, so preserve that structure
40+
# when copying. The purpose of env-helper is to allow the flag key & SDK keys to be injected via
41+
# environment variable (LD_SDK_KEY and LD_FLAG_KEY).
42+
COPY ./examples/hello-debian/hello.lua hello-debian/
43+
COPY ./examples/env-helper env-helper
44+
45+
46+
RUN luarocks make launchdarkly-server-sdk-${VERSION}-0.rockspec LD_DIR=./cpp-sdk-libs
47+
48+
ENV LD_LIBRARY_PATH=../cpp-sdk-libs/lib
49+
ENTRYPOINT ["lua", "hello-debian/hello.lua"]

examples/hello-debian/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# LaunchDarkly Lua server-side SDK Debian Bookworm example
2+
3+
We've built a minimal dockerized example of using the Lua SDK within a Debian Bookworm Docker container.
4+
5+
## Build instructions
6+
7+
1. On the command line from the **root** of the repo, build the Docker image:
8+
`docker build -t hello-debian -f ./examples/hello-debian/Dockerfile .`.
9+
2. Run the demo with
10+
```bash
11+
docker run --rm --name hello-debian --env LD_SDK_KEY="my-sdk-key" --env LD_FLAG_KEY="my-boolean-flag" hello-debian
12+
```
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.
15+
16+
You should receive the message:
17+
> Feature flag is <true/false> for this user context

examples/hello-debian/hello.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local ld = require("launchdarkly_server_sdk")
2+
local get_from_env_or_default = dofile("../env-helper/get_from_env_or_default.lua")
3+
4+
-- Set MY_SDK_KEY to your LaunchDarkly SDK key.
5+
local MY_SDK_KEY = ""
6+
7+
-- Set MY_FLAG_KEY to the boolean-type feature flag key you want to evaluate.
8+
local MY_FLAG_KEY = "my-boolean-flag"
9+
10+
11+
local config = {}
12+
13+
local sdk_key = get_from_env_or_default("LD_SDK_KEY", MY_SDK_KEY)
14+
local client = ld.clientInit(sdk_key, 1000, config)
15+
16+
local user = ld.makeContext({
17+
user = {
18+
key = "example-user-key",
19+
name = "Sandy"
20+
}
21+
})
22+
23+
local flag_key = get_from_env_or_default("LD_FLAG_KEY", MY_FLAG_KEY)
24+
local value = client:boolVariation(user, flag_key, false)
25+
print("Feature flag ".. flag_key .." is "..tostring(value).." for this user context")

scripts/get-cpp-sdk-locally.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Locally, it's more convenient to built the C++ SDK from source - to be able to switch branches,
77
# change built options, etc.
88

9-
# Usage: ./scripts/build-cpp-server.sh <tag>
9+
# Usage: ./scripts/get-cpp-sdk-locally.sh <tag>
1010
# If no tag is supplied, it uses 'main'.
1111
#
1212
# The SDK headers/libs are installed in ./cpp-sdks/build/INSTALL.

0 commit comments

Comments
 (0)