Skip to content

Commit

Permalink
feat(launchpad): adding a launchpad to control flagd (#194)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
Co-authored-by: warber <72415058+warber@users.noreply.github.com>
  • Loading branch information
aepfli and warber authored Jan 20, 2025
1 parent fc78679 commit dbad001
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 112 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,4 @@ jobs:
target: testbed
push: false

- name: Build flagd-testbed-unstable Docker image
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6
with:
context: .
file: flagd/Dockerfile
target: unstable
push: false

- name: Build flagd-testbed-ssl Docker image
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6
with:
context: .
file: flagd/Dockerfile
target: ssl
push: false

- name: Build flagd-testbed-socket Docker image
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6
with:
context: .
file: flagd/Dockerfile
target: socket
push: false

38 changes: 1 addition & 37 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ permissions:
env:
REGISTRY: ghcr.io
FLAGD_IMAGE_NAME: flagd-testbed
SYNC_IMAGE_NAME: sync-testbed
GO_VERSION: "~1.21"

jobs:
Expand Down Expand Up @@ -62,41 +61,6 @@ jobs:
tags: |
${{ env.REGISTRY }}/open-feature/${{ env.FLAGD_IMAGE_NAME }}:${{ needs.release-please.outputs.release_tag_name }}
${{ env.REGISTRY }}/open-feature/${{ env.FLAGD_IMAGE_NAME }}:latest
${{ env.REGISTRY }}/open-feature/${{ env.SYNC_IMAGE_NAME }}:${{ needs.release-please.outputs.release_tag_name }}
${{ env.REGISTRY }}/open-feature/${{ env.SYNC_IMAGE_NAME }}:latest
- name: Build and push flagd-testbed-unstable Docker image
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6
with:
context: .
file: flagd/Dockerfile
target: unstable
push: true
tags: |
${{ env.REGISTRY }}/open-feature/${{ env.FLAGD_IMAGE_NAME }}-unstable:${{ needs.release-please.outputs.release_tag_name }}
${{ env.REGISTRY }}/open-feature/${{ env.FLAGD_IMAGE_NAME }}-unstable:latest
${{ env.REGISTRY }}/open-feature/${{ env.SYNC_IMAGE_NAME }}:${{ needs.release-please.outputs.release_tag_name }}
${{ env.REGISTRY }}/open-feature/${{ env.SYNC_IMAGE_NAME }}:latest
- name: Build and push flagd-testbed-ssl Docker image
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6
with:
context: .
file: flagd/Dockerfile
target: ssl
push: true
tags: |
${{ env.REGISTRY }}/open-feature/${{ env.FLAGD_IMAGE_NAME }}-ssl:${{ needs.release-please.outputs.release_tag_name }}
${{ env.REGISTRY }}/open-feature/${{ env.FLAGD_IMAGE_NAME }}-ssl:latest
- name: Build and push flagd-testbed-ssl Docker image
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6
with:
context: .
file: flagd/Dockerfile
target: socket
push: true
tags: |
${{ env.REGISTRY }}/open-feature/${{ env.FLAGD_IMAGE_NAME }}-socket:${{ needs.release-please.outputs.release_tag_name }}
${{ env.REGISTRY }}/open-feature/${{ env.FLAGD_IMAGE_NAME }}-socket:latest
48 changes: 20 additions & 28 deletions flagd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
FROM ghcr.io/open-feature/flagd:v0.11.7 AS flagd

FROM busybox:1.37 AS testbed
# Build stage
FROM golang:1.22 AS builder

COPY --from=flagd /flagd-build /flagd
COPY flags/* .
COPY scripts/* .
LABEL org.opencontainers.image.source="https://github.com/open-feature/flagd-testbed"
WORKDIR /app

ENTRYPOINT ["sh", "change-flag-wrapper.sh", "./flagd", "start", \
"-f", "file:testing-flags.json", \
"-f", "file:changing-flag.json", \
"-f", "file:custom-ops.json", \
"-f", "file:evaluator-refs.json", \
"-f", "file:edge-case-flags.json", \
"-f", "file:zero-flags.json"]
# Copy Go modules and dependencies
COPY launchpad/go.mod launchpad/main.go ./
RUN go mod download

FROM testbed AS unstable
# Build the Go binary
RUN go build -o launchpad main.go

ENTRYPOINT ["sh", "restart-wrapper.sh", "./flagd", "start", \
"-f", "file:testing-flags.json"]

FROM alpine/openssl AS certs

Expand All @@ -29,23 +22,22 @@ RUN openssl genpkey -algorithm RSA -out server-key.pem -pkeyopt rsa_keygen_bits:
RUN openssl req -new -key server-key.pem -out server.csr -subj "/CN=localhost" \
&& openssl x509 -req -in server.csr -CA custom-root-cert.crt -CAkey custom-ca.key -CAcreateserial -out server-cert.pem -days 365 -sha256

FROM testbed AS ssl
FROM busybox:1.37 AS testbed

COPY --from=flagd /flagd-build /flagd
COPY --from=builder /app/launchpad /launchpad
COPY flags/* .
COPY scripts/* .
COPY launchpad/configs /configs

# Copy the custom root CA certificate into the image

COPY --from=certs server-cert.pem /etc/ssl/certs/
COPY --from=certs server-key.pem /etc/ssl/private/
COPY --from=certs custom-root-cert.crt /etc/ssl/certs/
COPY --from=certs server-cert.pem /ssl/
COPY --from=certs server-key.pem /ssl/
COPY --from=certs custom-root-cert.crt /ssl/


ENTRYPOINT ["./flagd", "start",\
"-f", "file:testing-flags.json", \
"-c", "/etc/ssl/certs/server-cert.pem", \
"-k", "/etc/ssl/private/server-key.pem"]
LABEL org.opencontainers.image.source="https://github.com/open-feature/flagd-testbed"

FROM testbed AS socket
ENTRYPOINT ["./launchpad"]

USER 1000:1000
ENTRYPOINT ["./flagd", "start", "-x",\
"-f", "file:testing-flags.json", \
"-d", "/tmp/socket.sock"]
12 changes: 0 additions & 12 deletions flags/changing-flag-bar.json

This file was deleted.

12 changes: 0 additions & 12 deletions flags/changing-flag-foo.json

This file was deleted.

88 changes: 88 additions & 0 deletions launchpad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Flagd Testbed Launchpad Application

Launchpad is a lightweight HTTP server built in Go that controls a `flagd` binary and provides endpoints to manage its lifecycle and configuration. The application also allows toggling a flag's `defaultVariant` dynamically and saves the updated configuration to a file.

## Features

- **Start and Stop `flagd`:**
Use `/start` and `/stop` endpoints to manage the `flagd` process.

- **Dynamic Configuration Toggling:**
The `/change` endpoint toggles the `defaultVariant` for a specific flag and saves the change to the configuration file.

## Endpoints

### 1. `/start`
- **Method:** `POST`
- **Description:** Starts the `flagd` binary with the specified configuration.
- **Query Parameters:**
- `config` (optional): Name of the configuration to load. Defaults to `"default"`.
- **Example:**
```bash
curl -X POST http://localhost:8080/start?config=my-config
```

### 2. `/stop`
- **Method:** `POST`
- **Description:** Stops the running `flagd` binary.
- **Example:**
```bash
curl -X POST http://localhost:8080/stop
```

### 3. `/change`
- **Method:** `POST`
- **Description:** Toggles the `defaultVariant` for the flag `changing-flag` between `"foo"` and `"bar"` and saves the updated configuration to the file `changing-flag.json`.
- **Example:**
```bash
curl -X POST http://localhost:8080/change
```

## Configuration Files

The application relies on JSON configuration files to manage flags for `flagd`. The configuration files are stored locally, and the `/change` endpoint modifies the file `changing-flag.json`.

### Example Configuration (`changing-flag.json`)

```json
{
"flags": {
"changing-flag": {
"state": "ENABLED",
"variants": {
"foo": "foo",
"bar": "bar"
},
"defaultVariant": "foo"
}
}
}
```

## Running the Application

1. **Build and Run the Application:**
```bash
go run main.go
```

2. **Start the `flagd` Binary:**
```bash
curl -X POST http://localhost:8080/start?config=default
```

3. **Stop the `flagd` Binary:**
```bash
curl -X POST http://localhost:8080/stop
```

4. **Toggle the Default Variant:**
```bash
curl -X POST http://localhost:8080/change
```


## Development Notes

- Ensure that `flagd` is available in the application directory or adjust the path accordingly.
- Modify the `changing-flag.json` file if additional flags or configurations are required.
28 changes: 28 additions & 0 deletions launchpad/configs/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"sources": [
{
"uri": "testing-flags.json",
"provider": "file"
},
{
"uri": "changing-flag.json",
"provider": "file"
},
{
"uri": "custom-ops.json",
"provider": "file"
},
{
"uri": "evaluator-refs.json",
"provider": "file"
},
{
"uri": "edge-case-flags.json",
"provider": "file"
},
{
"uri": "zero-flags.json",
"provider": "file"
}
]
}
30 changes: 30 additions & 0 deletions launchpad/configs/ssl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"server-cert-path": "/ssl/server-cert.pem",
"server-key-path": "/ssl/server-key.pem",
"sources": [
{
"uri": "testing-flags.json",
"provider": "file"
},
{
"uri": "changing-flag.json",
"provider": "file"
},
{
"uri": "custom-ops.json",
"provider": "file"
},
{
"uri": "evaluator-refs.json",
"provider": "file"
},
{
"uri": "edge-case-flags.json",
"provider": "file"
},
{
"uri": "zero-flags.json",
"provider": "file"
}
]
}
3 changes: 3 additions & 0 deletions launchpad/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module openfeature.com/flagd-testbed/launchpad

go 1.22.4
Loading

0 comments on commit dbad001

Please sign in to comment.