Skip to content

Commit

Permalink
chore: try to fix issue with dagger and host platform (#654)
Browse files Browse the repository at this point in the history
* chore: try to fix issue with dagger and host platform

Signed-off-by: Mark Phelps <[email protected]>

* fix: Use dagger to detect the arch and platform in stead of go runtime (#655)

Signed-off-by: Ben Mask <[email protected]>

---------

Signed-off-by: Mark Phelps <[email protected]>
Signed-off-by: Ben Mask <[email protected]>
Co-authored-by: Ben Mask <[email protected]>
  • Loading branch information
markphelps and atmask authored Jan 27, 2025
1 parent 59bf1d8 commit a515f80
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package-ffi-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
GO_VERSION: "1.23"
DAGGER_VERSION: "0.12.3"
DAGGER_VERSION: "0.14.0"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package-wasm-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
env:
NPM_API_KEY: ${{ secrets.NPM_API_KEY }}
GO_VERSION: "1.22"
DAGGER_VERSION: "0.12.3"
DAGGER_VERSION: "0.14.0"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
GO_VERSION: "1.22"
DAGGER_VERSION: "0.12.3"
DAGGER_VERSION: "0.14.0"

jobs:
test:
Expand Down
10 changes: 8 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ You don't have to build the engine from scratch in order to develop a new client

### 4. Setup Tests (optional)

Prerequisites:

- [Dagger](https://docs.dagger.io/install/#stable-release)
- [Go](https://go.dev/dl/)
- [Docker](https://docs.docker.com/get-docker/)

See the [test/README.md](./test/README.md) for more information on how to setup tests for the new client.

If you'd like to add tests using Dagger, you can follow the steps below. If you are not familiar with Dagger, you can skip this step and simply provide instructions for running the tests locally.

Feel free to ask the team for help with this step.
Expand All @@ -76,8 +84,6 @@ Feel free to ask the team for help with this step.
2. Update `test/main.go` to run the tests for the new client using Dagger. See the existing clients for examples.
3. Ensure the tests pass locally by running `dagger run go run ./test/... -sdks {comma separated list of languages}` from the root of the repository. Note: You will need to have Docker, Go, and Dagger installed locally to run the tests.

> **Note:** If you are working on an ARM-based cpu then you may encounter an OSError `cannot open shared object file: No such file or directory`. This could be due to the `getFFITestContainer()` step of the dagger pipeline building the dynamic library for an ARM target which cannot be used by the tests. A workaround until this is resolved is downloading the x86 `.so` from the [releases page](https://github.com/flipt-io/flipt-client-sdks/releases/latest), moving the `.so` to the expected folder (which will get mounted to the container for tests), and removing any `WithFile` directives from `test/main.go` which might override your local copy with the ARM-based copy compiled in `getFFITestContainer()`
### 5. Update README

Update the [README.md](./README.md) to include the new client in the list of clients. Follow the existing clients for examples.
Expand Down
26 changes: 1 addition & 25 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,8 @@ Releasing the engine is a three-step process:

#### SDKs

Releasing each SDK is a two to three-step process:

<p align="center">
<img src=".github/images/release-engine-ffi-sdk.png" width=600 />
</p>

1. Update the SDK to the new version that you want to release (i.e. update the version in `package.json` for Node, `pyproject.toml` for Python, `flipt_client.gemspec` for Ruby).
1. Commit and tag the SDK with the new version using the naming convention `flipt-client-{language}-{version}` (i.e. `flipt-client-node-v0.1.0`).
1. Push the tag to `origin`. This will trigger the appropriate GitHub Action to build, package, and publish the SDK.

Note: In the future we can potentially automate the tagging/pushing of the SDKs via a GitHub Action or script.

#### Checklist

- [ ] Update the `flipt-client-node` version in `flipt-client-node/package.json` and run `npm install`
- [ ] Update the `flipt-client-python` version in `flipt-client-python/pyproject.toml`
- [ ] Update the `flipt-client-ruby` version in `flipt-client-ruby/lib/flipt_client/version.rb`
- [ ] Update the `flipt-client-java` version in `flipt-client-java/build.gradle`
- [ ] Update the `flipt-client-dart` version in `flipt-client-dart/pubspec.yaml`
- [ ] Tag each SDK with the new version and push the tags to `origin`

### WASM

Releasing the `flipt-client-browser` SDK is a three to four-step process:

1. Update the `flipt-engine-wasm` dependency in `flipt-client-browser/src` (if necessary).
1. Update the `flipt-client-browser` version in `flipt-client-browser/package.json` and run `npm install`
1. Commit and tag the SDK with the new version using the naming convention `flipt-client-browser-v{version}` (i.e. `flipt-client-browser-v0.1.0`).
1. Push the tag to `origin`. This will trigger the appropriate GitHub Action to build, package, and publish the SDK.
We use a Python script to release the SDKs. The script is located in the [release](./release) directory. See the [README](./release/README.md) for more information.
59 changes: 5 additions & 54 deletions release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,70 +43,21 @@ python release.py

1. **SDK Selection**: The script presents a list of available SDKs and allows the user to select which ones to update.

2. **Action Selection**: The user chooses whether to update versions, tag and push, or both.
2. **Version Bump Selection**: The user selects the type of version bump (patch, minor, or major).

3. **Version Bump Selection**: If updating versions, the user selects the type of version bump (patch, minor, or major).

4. **Version Update**: For each selected SDK, the script:
3. **Version Update**: For each selected SDK, the script:

- Reads the current version
- Calculates the new version based on the bump type
- Updates the version in the SDK-specific file (e.g., package.json, build.gradle)

5. **Tagging and Pushing**: If selected, the script creates Git tags for the new versions and pushes them to the remote repository.

## SDK-Specific Handling

The script uses separate classes for each SDK type to handle version reading and updating:

```12:23:release/release.py
def get_sdk(name: str, path: str) -> SDK:
sdk_classes = {
"flipt-client-go": GoSDK,
"flipt-client-java": JavaSDK,
"flipt-client-node": JavaScriptSDK,
"flipt-client-browser": JavaScriptSDK,
"flipt-client-react": JavaScriptSDK,
"flipt-client-dart": DartSDK,
"flipt-client-python": PythonSDK,
"flipt-client-ruby": RubySDK,
}
return sdk_classes[name](name, path)
```

Each SDK class implements methods for getting the current version, updating the version, and handling MUSL versions if applicable.

## MUSL Support

Some SDKs (like Java and Go) have MUSL versions. The script handles these separately:

```69:73:release/release.py
if isinstance(sdk, MuslSupportSDK):
current_musl_version = sdk.get_current_musl_version()
new_musl_version = bump_version(current_musl_version, bump_type)
sdk.update_musl_version(new_musl_version)
updated_versions[f"{sdk_dir}-musl"] = new_musl_version
```

## Error Handling

The script includes error handling to manage issues such as:

- Missing SDK directories
- Failures in reading or writing version files
- Git tagging or pushing errors

## Customization

To add support for a new SDK:
4. **Tagging and Pushing**: The script creates Git tags for the new versions and pushes them to the remote repository.

1. Create a new SDK class in the `sdks` directory
2. Implement the required methods (`get_current_version`, `update_version`)
3. Add the new SDK to the `sdk_classes` dictionary in the `get_sdk` function
5. **Pull Request**: The script optionally creates a pull request with the versioning changes.

## Notes

- The script assumes it's run from the `release` directory within the project structure.
- It interacts with Git, so make sure you have the necessary permissions to create and push tags.

For more detailed information on each SDK's specific implementation, refer to the individual SDK class files in the `sdks` directory.
For more detailed information on each SDK's specific implementation, refer to the individual SDK class files in the `sdks` directory.
5 changes: 3 additions & 2 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ In the `test/` directory we will use [Dagger](https://dagger.io/) to orchestrate

## Requirements

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

Here are the [Dagger Installation Instructions](https://docs.dagger.io/quickstart/729236/cli).
> [!IMPORTANT]
> We recommend installing the same version of Dagger as is used in CI. Follow the [Dagger Installation Instructions](https://docs.dagger.io/install/#stable-release) to install the correct version (v0.14.0).
## Running Tests

Expand Down
34 changes: 21 additions & 13 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"maps"
"os"
"runtime"
"strings"

"dagger.io/dagger"
Expand All @@ -16,6 +15,7 @@ import (

var (
architecture string
platform string
sdks string
sdkToFn = map[string]integrationTestFn{
"python": pythonTests,
Expand All @@ -40,11 +40,6 @@ func init() {
func main() {
flag.Parse()

architecture = "x86_64"
if strings.Contains(runtime.GOARCH, "arm64") || strings.Contains(runtime.GOARCH, "aarch64") {
architecture = "arm64"
}

if err := run(); err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -81,6 +76,20 @@ func run() error {
Exclude: []string{".github/", "build/", "tmp/", ".git/"},
})

// Detect the architecture and platform of the host machine
architecture = "x86_64"
platform = "linux/amd64"
daggerPlatform, err := client.DefaultPlatform(ctx)
if err != nil {
fmt.Println("Error detecting host platform from Dagger: ", err)
fmt.Println("Defaulting to platform: linux/amd64, architecture: x86_64")
}
platform = string(daggerPlatform)
if strings.Contains(platform, "arm64") || strings.Contains(platform, "aarch64") {
architecture = "arm64"
platform = "linux/arm64"
}

flipt := client.Container().From("flipt/flipt:latest").
WithUser("root").
WithExec([]string{"mkdir", "-p", "/var/data/flipt"}).
Expand All @@ -96,11 +105,6 @@ func run() error {

var g errgroup.Group

platform := "linux/amd64"
if architecture == "arm64" {
platform = "linux/arm64"
}

container := client.Container(dagger.ContainerOpts{
Platform: dagger.Platform(platform),
})
Expand Down Expand Up @@ -157,7 +161,9 @@ type testCase struct {
// getFFITestContainer builds the dynamic library for the Rust core, and the Flipt container for the client libraries to run
// their tests against.
func getFFITestContainer(_ context.Context, client *dagger.Client, hostDirectory *dagger.Directory) *dagger.Container {
return client.Container().From("rust:1.83.0-bookworm").
return client.Container(dagger.ContainerOpts{
Platform: dagger.Platform(platform),
}).From("rust:1.83.0-bookworm").
WithWorkdir("/src").
WithDirectory("/src/flipt-engine-ffi", hostDirectory.Directory("flipt-engine-ffi")).
WithDirectory("/src/flipt-engine-wasm", hostDirectory.Directory("flipt-engine-wasm"), dagger.ContainerWithDirectoryOpts{
Expand All @@ -171,7 +177,9 @@ func getFFITestContainer(_ context.Context, client *dagger.Client, hostDirectory
// getWasmTestContainer builds the wasm module for the Rust core, and the Flipt container for the client libraries to run
// their tests against.
func getWasmTestContainer(_ context.Context, client *dagger.Client, hostDirectory *dagger.Directory, target string) *dagger.Container {
container := client.Container().From("rust:1.83.0-bookworm").
container := client.Container(dagger.ContainerOpts{
Platform: dagger.Platform(platform),
}).From("rust:1.83.0-bookworm").
WithWorkdir("/src").
WithDirectory("/src/flipt-engine-ffi", hostDirectory.Directory("flipt-engine-ffi")).
WithDirectory("/src/flipt-engine-wasm", hostDirectory.Directory("flipt-engine-wasm"), dagger.ContainerWithDirectoryOpts{
Expand Down

0 comments on commit a515f80

Please sign in to comment.