Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: automate client installs; update readmes #25

Merged
merged 12 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ flipt_engine.*
__pycache__/

# Node
node_modules/
node_modules/

.DS_Store
26 changes: 16 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@ HEADER = flipt_engine.h
.DEFAULT_GOAL := help
.PHONY: build go node python ruby help clean

# run cargo build if anything in engine/ changes
build: ## Build the shared engine library
cargo build --release

go: build ## Prepare the go client for building
cp target/release/$(LIB).* target/release/$(HEADER) flipt-client-go/
go: build ## Build the go client package
cp target/release/$(LIB).* target/release/$(HEADER) flipt-client-go/ext/
go install ./flipt-client-go

node: build ## Prepare the node client for building
cp target/release/$(LIB).* flipt-client-node/
node: build ## Build the node client package
cp target/release/$(LIB).* flipt-client-node/ext/
cd flipt-client-node && npm install && npm run build && npm pack

python: build ## Prepare the python client for building
cp target/release/$(LIB).* flipt-client-python/
python: build ## Build the python client package
cp target/release/$(LIB).* flipt-client-python/ext/
cd flipt-client-python && poetry build

ruby: build ## Prepare the ruby client for building
ruby: build ## Build the ruby client gem
cp target/release/$(LIB).* flipt-client-ruby/lib/ext/
cd flipt-client-ruby && rake install

clean: ## Clean up build artifacts
rm -rf target
rm -rf flipt-client-go/$(LIB).* flipt-client-go/$(HEADER)
rm -rf flipt-client-node/$(LIB).*
rm -rf flipt-client-python/$(LIB).*
rm -rf flipt-client-node/ext/$(LIB).*
rm -rf flipt-client-node/*.tgz
rm -rf flipt-client-node/dist
rm -rf flipt-client-python/ext/$(LIB).*
rm -rf flipt-client-python/dist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does python have a "dist" folder after a build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with poetry, yah it seemed to:

» ls flipt-client-python/dist/
flipt_client-0.0.1-py3-none-any.whl	flipt_client-0.0.1.tar.gz

rm -rf flipt-client-ruby/lib/ext/$(LIB).*
rm -rf flipt-client-ruby/pkg/

Expand Down
2 changes: 1 addition & 1 deletion build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In the `build/` directory we will use [Dagger](https://dagger.io/) to orchestrat

Make sure you have `dagger` installed. This module is pinned to `v0.9.3` currently.

Here are the [installation instructions](https://docs.dagger.io/quickstart/729236/cli) for `dagger`.
Here are the [Dagger Installation Instructions](https://docs.dagger.io/quickstart/729236/cli).

## Running Tests

Expand Down
12 changes: 5 additions & 7 deletions build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ func pythonTests(ctx context.Context, client *dagger.Client, flipt *dagger.Conta
WithExec([]string{"pip", "install", "poetry==1.7.0"}).
WithWorkdir("/app").
WithDirectory("/app", hostDirectory.Directory("flipt-client-python")).
WithFile("/app/libfliptengine.so", dynamicLibrary).
WithFile("/app/ext/libfliptengine.so", dynamicLibrary).
WithServiceBinding("flipt", flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithEnvVariable("FLIPT_ENGINE_LIB_PATH", "/app/libfliptengine.so").
WithExec([]string{"poetry", "install", "--without=dev"}).
WithExec([]string{"poetry", "run", "test"}).
Sync(ctx)
Expand All @@ -149,15 +148,15 @@ func goTests(ctx context.Context, client *dagger.Client, flipt *dagger.Container
WithExec([]string{"apt-get", "-y", "install", "build-essential"}).
WithWorkdir("/app").
WithDirectory("/app", hostDirectory.Directory("flipt-client-go")).
WithFile("/app/libfliptengine.so", dynamicLibrary).
WithFile("/app/flipt_engine.h", headerFile).
WithFile("/app/ext/libfliptengine.so", dynamicLibrary).
WithFile("/app/ext/flipt_engine.h", headerFile).
WithServiceBinding("flipt", flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
// Since the dynamic library is being sourced from a "non-standard location" we can
// modify the LD_LIBRARY_PATH variable to inform the linker different locations for
// dynamic libraries.
WithEnvVariable("LD_LIBRARY_PATH", "/app:$LD_LIBRARY_PATH").
WithEnvVariable("LD_LIBRARY_PATH", "/app/ext:$LD_LIBRARY_PATH").
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"go", "test", "./..."}).
Sync(ctx)
Expand All @@ -174,11 +173,10 @@ func nodeTests(ctx context.Context, client *dagger.Client, flipt *dagger.Contain
WithDirectory("/app", hostDirectory.Directory("flipt-client-node"), dagger.ContainerWithDirectoryOpts{
Exclude: []string{"./node_modules/"},
}).
WithFile("/app/libfliptengine.so", dynamicLibrary).
WithFile("/app/ext/libfliptengine.so", dynamicLibrary).
WithServiceBinding("flipt", flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithEnvVariable("FLIPT_ENGINE_LIB_PATH", "/app/libfliptengine.so").
WithExec([]string{"npm", "install"}).
WithExec([]string{"npm", "test"}).
Sync(ctx)
Expand Down
14 changes: 7 additions & 7 deletions diagrams/architecture.d2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
golang: {
go: {
shape: image
icon: https://icon.icepanel.io/Technology/svg/Go.svg
}
Expand All @@ -18,7 +18,7 @@ typescript: {
icon: https://icon.icepanel.io/Technology/svg/TypeScript.svg
}

dynamic library: {
flipt-engine: {
shape: square
rust: {
shape: image
Expand All @@ -34,12 +34,12 @@ flipt-service: {
}
}

golang -> dynamic library: FFI
ruby -> dynamic library: FFI
python -> dynamic library: FFI
typescript -> dynamic library: FFI
go <-> flipt-engine: FFI
ruby <-> flipt-engine: FFI
python <-> flipt-engine: FFI
typescript <-> flipt-engine: FFI

dynamic library <-> flipt-service: Flag state sync (default 2 mins) {
flipt-engine <-> flipt-service: Evaluation State Sync {
style: {
opacity: 0.9
stroke-dash: 3
Expand Down
Binary file modified diagrams/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 37 additions & 13 deletions flipt-client-go/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,54 @@
# Flipt Client Go

The `flipt-client-go` directory contains the Go source code for a Flipt evaluation client.
The `flipt-client-go` directory contains the Go source code for the Flipt client-side evaluation client.

## Instructions
## Installation

To use this client, you can run the following command from the root of the repository:
Currently, to use this client, you'll need to build the dynamic library and the gem locally and install it. This is a temporary solution until we can figure out a better way to package and distribute the libraries.

```bash
cargo build --release
```
The dynamic library will contain the functionality necessary for the client to make calls to the Flipt engine via FFI. See [flipt-engine](../flipt-engine) for more information on the Flipt engine and FFI.

This should generate a `target/` directory in the root of this repository, which contains the dynamic linking library built for your platform. This dynamic library will contain the functionality necessary for the Go client to make FFI calls.
### Prerequisites

You can import the module that contains the evaluation client: `go.flipt.io/flipt/flipt-client-go` and build your Go project with the `CGO_LDFLAGS` environment variable set:
- [Rust](https://www.rust-lang.org/tools/install)
- [Go](https://golang.org/doc/install)
- [Make](https://www.gnu.org/software/make/)

```bash
CGO_LDFLAGS="-L/path/to/lib -lfliptengine"
```
### Automated Build

1. Build and copy the dynamic library to the `flipt-client-go/ext` directory.

```bash
make go
```

### Manual Build

1. Build the Rust dynamic library

```bash
cargo build --release
```

This should generate a `target/` directory in the root of this repository, which contains the dynamically linked library built for your platform.

2. You'll need to copy the dynamic library to the `flipt-client-go/ext` directory. This is a temporary solution until we can figure out a better way to package the libraries with the module.

The `path/to/lib` will be the path to the dynamic library which will have the following paths depending on your platform.

- **Linux**: `{REPO_ROOT}/target/release/libfliptengine.so`
- **Windows**: `{REPO_ROOT}/target/release/libfliptengine.dll`
- **MacOS**: `{REPO_ROOT}/target/release/libfliptengine.dylib`

You can then use the client like so:
3. You can then install the module locally. You can do this by running the following command from the `flipt-client-go` directory:

```bash
go install .
```

## Usage

In your Go code you can import this client and use it as so:

```go
package main
Expand All @@ -34,7 +58,7 @@ import (
"fmt"
"log"

evaluation "go.flipt.io/flipt/flipt-client-go"
evaluation "go.flipt.io/flipt/flipt-client"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions flipt-client-go/evaluation.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package evaluation

/*
#cgo LDFLAGS: -L. -lfliptengine
#cgo LDFLAGS: -L${SRCDIR}/ext/. -lfliptengine
#include <string.h>
#include <stdlib.h>
#include "flipt_engine.h"
#include "./ext/flipt_engine.h"
*/
import "C"
import (
Expand Down
2 changes: 1 addition & 1 deletion flipt-client-go/evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
evaluation "go.flipt.io/flipt/flipt-client-go"
evaluation "go.flipt.io/flipt/flipt-client"
)

var fliptUrl string
Expand Down
Empty file added flipt-client-go/ext/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion flipt-client-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module go.flipt.io/flipt/flipt-client-go
module go.flipt.io/flipt/flipt-client

go 1.21.3

Expand Down
130 changes: 130 additions & 0 deletions flipt-client-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
Loading
Loading