Skip to content

Commit

Permalink
feat: add optional remote fib service (#85)
Browse files Browse the repository at this point in the history
- Adds an additional fib service that can be optional enabled via a
feature flag
- Fib service requires basic auth
- Removed unused scripts

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
  • Loading branch information
beeme1mr authored Oct 11, 2022
1 parent f00b2df commit d5c9120
Show file tree
Hide file tree
Showing 30 changed files with 402 additions and 149 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ LD_KEY=

# Split IO server-side API key
SPLIT_KEY=

###############################################
##
## Remote Fibonacci Service
##
###############################################
FIB_SERVICE_USER=
FIB_SERVICE_PASS=
25 changes: 21 additions & 4 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,34 @@ jobs:
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"

- name: Build
- name: Build App Container
uses: docker/build-push-action@v2
with:
# builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
file: ./packages/app/Dockerfile
# platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.release-please.outputs.release_tag_name }}
${{ env.REGISTRY }}/app:latest
${{ env.REGISTRY }}/app:${{ needs.release-please.outputs.release_tag_name }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.meta.outputs.tags }}
COMMIT=${{ github.sha }}
DATE=${{ steps.date.outputs.date }}
- name: Build Fibonacci Service Container
uses: docker/build-push-action@v2
with:
# builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./packages/fibonacci-service/Dockerfile
# platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/fib-service:latest
${{ env.REGISTRY }}/fib-service:${{ needs.release-please.outputs.release_tag_name }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.meta.outputs.tags }}
Expand Down
Binary file removed assets/images/zipkin-fibonacci.png
Binary file not shown.
8 changes: 8 additions & 0 deletions config/flagd/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
},
"defaultVariant": "blue"
},
"use-remote-fib-service": {
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "on"
},
"fib-algo": {
"state": "ENABLED",
"variants": {
Expand Down
21 changes: 20 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: '3.8'
services:
demo:
image: ghcr.io/open-feature/playground:openfeature-v0.0.7 # x-release-please-version
# image: ghcr.io/open-feature/playground:app-v0.0.7 # x-release-please-version
build:
dockerfile: ./packages/app/Dockerfile
ports:
- '30000:30000'
command:
Expand All @@ -10,13 +12,17 @@ services:
depends_on:
- flagd
- jaeger
- fib-service
volumes:
- ${PWD}/config/flagd/flags.json:/opt/playground/config/flagd/flags.json
environment:
- FLAGD_HOST=flagd
- OTEL_EXPORTER_JAEGER_AGENT_HOST=jaeger
- OTEL_EXPORTER_JAEGER_AGENT_PORT=6832
- GO_FEATURE_FLAG_URL=http://go-feature-flag:1031
- FIB_SERVICE_URL=http://fib-service:30001
- FIB_SERVICE_USER
- FIB_SERVICE_PASS
# Provider values come from the .env
- NEW_WELCOME_MESSAGE
- FIB_ALGO
Expand All @@ -28,6 +34,19 @@ services:
- FLAGSMITH_ENV_KEY
- CLOUDBEES_APP_KEY

fib-service:
# image: ghcr.io/open-feature/playground:fib-service-v0.0.7 # x-release-please-version
build:
dockerfile: ./packages/fibonacci-service/Dockerfile
expose:
- "30001"
environment:
- OTEL_EXPORTER_JAEGER_AGENT_HOST=jaeger
- OTEL_EXPORTER_JAEGER_AGENT_PORT=6832
- OTEL_SERVICE_NAME=fibonacci-service
- FIB_SERVICE_USER
- FIB_SERVICE_PASS

jaeger:
image: jaegertracing/all-in-one:1.38
expose:
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 5 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
"version": "0.0.7",
"license": "MIT",
"scripts": {
"no-op-demo": "nx serve app",
"cloudbees-demo": "nx run app:cloudbees-demo",
"env-var-demo": "nx run app:env-var-demo",
"split-demo": "nx run app:split-demo",
"launchdarkly-demo": "nx run app:launchdarkly-demo",
"flagsmith-demo": "nx run app:flagsmith-demo",
"go-feature-flag-demo": "nx run app:go-feature-flag-demo",
"flagd-demo": "nx run app:flagd-demo",
"ui": "nx run ui:serve",
"app": "nx run app:serve",
"fib-service": "nx run fibonacci-service:serve",
"temp": "nx build",
"build": "nx build app && nx build ui && cp -R dist/packages/ui/* dist/packages/app/assets/public/",
"docker-build": "docker buildx build --platform=\"linux/ppc64le,linux/s390x,linux/amd64,linux/arm64\" . -t ghcr.io/open-feature/open-feature-demo:latest",
"docker-build-push": "docker buildx build --push --platform=\"linux/ppc64le,linux/s390x,linux/amd64,linux/arm64\" . -t ghcr.io/open-feature/open-feature-demo:latest",
"build:app": "nx build app && nx build ui",
"build:fib-service": "nx build fibonacci-service",
"lint": "nx run-many --all --target=lint",
"test": "nx run-many --all --target=test",
"markdown-toc": "markdown-toc --bullets='-' --no-first-h1 --no-stripHeadingTags --maxdepth 4 -i README.md"
Expand All @@ -26,6 +19,7 @@
"@emotion/styled": "^11.10.4",
"@harnessio/ff-nodejs-server-sdk": "^1.2.8",
"@mui/material": "^5.10.7",
"@nestjs/axios": "^0.1.0",
"@nestjs/common": "9.1.2",
"@nestjs/core": "9.1.2",
"@nestjs/platform-express": "9.1.2",
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile → packages/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY package*.json workspace.json tsconfig*.json nx.json babel.config.json ./
COPY schemas/ ./schemas/
RUN npm install
COPY packages/ ./packages/
RUN npm run build
RUN npm run build:app

FROM node:16-bullseye as app

Expand All @@ -17,7 +17,7 @@ COPY --from=builder /tmp/playground/dist ./dist
COPY scripts ./scripts
COPY schemas ./schemas

LABEL org.opencontainers.image.source=https://github.com/open-feature/open-feature-demo
LABEL org.opencontainers.image.source=https://github.com/open-feature/playground

EXPOSE 30000

Expand Down
117 changes: 14 additions & 103 deletions packages/app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
"targets": {
"build": {
"executor": "@nrwl/webpack:webpack",
"outputs": ["{options.outputPath}"],
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/packages/app",
"main": "packages/app/src/main.ts",
"tsConfig": "packages/app/tsconfig.app.json",
"assets": ["packages/app/src/assets"],
"assets": [
"packages/app/src/assets"
],
"target": "node",
"compiler": "tsc"
},
Expand All @@ -32,115 +36,22 @@
"executor": "@nrwl/node:node",
"options": {
"buildTarget": "app:build",
"runtimeArgs": ["-r", "./scripts/tracing.js"]
}
},
"env-var-demo": {
"executor": "@nrwl/node:node",
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"options": {
"buildTarget": "app:build",
"runtimeArgs": ["-r", "./scripts/tracing.js"],
"args": ["env"]
}
},
"cloudbees-demo": {
"executor": "@nrwl/node:node",
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"options": {
"buildTarget": "app:build",
"runtimeArgs": ["-r", "./scripts/tracing.js"],
"args": ["cloudbees"]
}
},
"split-demo": {
"executor": "@nrwl/node:node",
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"options": {
"buildTarget": "app:build",
"runtimeArgs": ["-r", "./scripts/tracing.js"],
"args": ["split"]
}
},
"launchdarkly-demo": {
"executor": "@nrwl/node:node",
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"options": {
"buildTarget": "app:build",
"runtimeArgs": ["-r", "./scripts/tracing.js"],
"args": ["launchdarkly"]
}
},
"flagsmith-demo": {
"executor": "@nrwl/node:node",
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"options": {
"buildTarget": "app:build",
"runtimeArgs": ["-r", "./scripts/tracing.js"],
"args": ["flagsmith"]
}
},
"flagd-demo": {
"executor": "@nrwl/node:node",
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"options": {
"buildTarget": "app:build",
"runtimeArgs": ["-r", "./scripts/tracing.js"],
"args": ["flagd"]
}
},
"go-feature-flag-demo": {
"executor": "@nrwl/node:node",
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"options": {
"buildTarget": "app:build",
"runtimeArgs": ["-r", "./scripts/tracing.js"],
"args": ["go"]
"runtimeArgs": [
"-r",
"./scripts/tracing.js"
]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/packages/app"],
"outputs": [
"coverage/packages/app"
],
"options": {
"jestConfig": "packages/app/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
}
8 changes: 7 additions & 1 deletion packages/app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { ProvidersController } from './providers.controller';
import { ProviderService } from './provider.service';
import { HttpModule } from '@nestjs/axios';
import { FibonacciService } from './fibonacci/fibonacci.service';

/**
* Adding hooks to at the global level will ensure they always run
Expand All @@ -32,13 +34,15 @@ OpenFeature.setTransactionContextPropagator(new AsyncLocalStorageTransactionCont
@Module({
imports: [
ServeStaticModule.forRoot({
rootPath: join(__dirname, '.', 'assets', 'public'),
rootPath: join(__dirname, '..', 'ui'),
}),
HttpModule,
],
controllers: [FibonacciAsAServiceController, UtilsController, ProvidersController],
providers: [
MessageService,
HexColorService,
FibonacciService,
ProviderService,
{
provide: OPENFEATURE_CLIENT,
Expand All @@ -51,11 +55,13 @@ OpenFeature.setTransactionContextPropagator(new AsyncLocalStorageTransactionCont
provide: REQUEST_DATA,
useFactory: (req: Request): RequestData => {
const authHeaderValue = req.header('Authorization') || 'anonymous';
const userAgent = req.header('user-agent');
return {
ip: (req.headers['x-forwarded-for'] as string) || (req.socket.remoteAddress as string),
email: authHeaderValue,
method: req.method,
path: req.path,
...(userAgent && { userAgent }),
targetingKey: authHeaderValue,
};
},
Expand Down
Loading

0 comments on commit d5c9120

Please sign in to comment.