Skip to content

Commit

Permalink
fixup: add start command, docker stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert committed Aug 31, 2023
1 parent 7b35ecd commit 064b6dc
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 78 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
permissions:
contents: read

env:
GO_VERSION: 1.19.3

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -27,7 +30,22 @@ jobs:
- name: Lint Gherkin
run: npm run gherkin-lint

- name: Build Docker image
- name: Build sync binary
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
with:
go-version: ${{ env.GO_VERSION }}
- run: make build-sync

- name: Build flagd-testbed Docker image
uses: docker/build-push-action@v4
with:
context: .
file: flagd/Dockerfile
push: false

- name: Build sync-testbed Docker image
uses: docker/build-push-action@v4
with:
context: .
file: sync/Dockerfile
push: false
28 changes: 24 additions & 4 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ permissions:

env:
REGISTRY: ghcr.io
IMAGE_NAME: flagd-testbed
FLAGD_IMAGE_NAME: flagd-testbed
SYNC_IMAGE_NAME: sync-testbed
GO_VERSION: 1.19.3

jobs:
release-please:
Expand Down Expand Up @@ -43,17 +45,35 @@ jobs:
with:
ref: ${{ needs.release-please.outputs.release_tag_name }}

- name: Build sync binary
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
with:
go-version: ${{ env.GO_VERSION }}
- run: make build-sync

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
- name: Build and push flagd-testbed Docker image
uses: docker/build-push-action@v4
with:
context: .
file: flagd/Dockerfile
push: true
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
- name: Build and push sync-testbed Docker image
uses: docker/build-push-action@v4
with:
context: .
file: sync/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/open-feature/${{ env.IMAGE_NAME }}:${{ needs.release-please.outputs.release_tag_name }}
${{ env.REGISTRY }}/open-feature/${{ env.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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
node_modules
flags/changing-flag.json
flags/changing-flag.json
bin/
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: clean
clean:
rm -R bin/
.PHONY: build-sync
build-sync:
cd sync && go build -o ./bin/sync
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ This repository contains a docker image to support the [gherkin suites](https://

The _flagd-testbed_ container is a docker image built on flagd, which essentially just adds a simple set of flags for the purposes of testing OpenFeature SDKs.
`testing-flags.json` contains a set of flags consistent with the [evaluation feature](https://github.com/open-feature/spec/blob/main/specification/assets/gherkin/evaluation.feature).
`change-flag.sh` runs in the test container generates a file `changing-flag.json`, which contains a flag that changes once every seconds, allowing to easily test change events.
`change-flag.sh` runs in the test container generates a file `changing-flag.json`, which contains a flag that changes once every seconds, allowing to easily test change events.

## sync-testbed container

The _sync_-testbed_ container is a docker image built on conforming to the sync.proto - a grpc which flagd or flagd in-process providers can use as a sync-source.
It features an identical set of flags to the [flagd-testbed container](#flagd-testbed-container)
4 changes: 2 additions & 2 deletions Dockerfile → flagd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM busybox:1.36

COPY --from=flagd /flagd-build /flagd
COPY flags/* .
COPY wrapper.sh .
COPY scripts/* .
LABEL org.opencontainers.image.source = "https://github.com/open-feature/test-harness"

ENTRYPOINT ["sh", "wrapper.sh"]
ENTRYPOINT ["sh", "wrapper.sh", "./flagd", "start", "-f", "file:testing-flags.json", "-f", "file:changing-flag.json"]
13 changes: 0 additions & 13 deletions grpc-sync-server/main.go

This file was deleted.

46 changes: 0 additions & 46 deletions grpc-sync-server/pkg/config.go

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion wrapper.sh → scripts/wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trap handle_int SIGINT

# start change script and flagd
sh ./change-flag.sh &
./flagd start -f 'file:testing-flags.json' -f 'file:changing-flag.json' &
"$@" &

# wait on flagd
child=$!
Expand Down
8 changes: 8 additions & 0 deletions sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM busybox:1.36

COPY sync/bin/* .
COPY flags/* .
COPY scripts/* .
LABEL org.opencontainers.image.source = "https://github.com/open-feature/test-harness"

ENTRYPOINT ["sh", "wrapper.sh", "./sync", "start", "-f", "testing-flags.json", "-f", "changing-flag.json"]
File renamed without changes.
6 changes: 3 additions & 3 deletions grpc-sync-server/go.mod → sync/go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
module server
module github.com/open-feature/test-harness/sync

go 1.19

require (
buf.build/gen/go/open-feature/flagd/grpc/go v1.3.0-20230822184021-85780df4e019.1
buf.build/gen/go/open-feature/flagd/protocolbuffers/go v1.31.0-20230822184021-85780df4e019.1
github.com/fsnotify/fsnotify v1.6.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.43.0
go.opentelemetry.io/otel v1.17.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.17.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.17.0
go.opentelemetry.io/otel/sdk v1.17.0
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
google.golang.org/grpc v1.57.0
)

require (
cloud.google.com/go/compute v1.23.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 // indirect
go.opentelemetry.io/otel/metric v1.17.0 // indirect
go.opentelemetry.io/otel/trace v1.17.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions sync/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
sync "github.com/open-feature/test-harness/sync/pkg"
)

func main() {
server := sync.Server{
Config: sync.LoadConfig(),
}

server.Start()
}
50 changes: 50 additions & 0 deletions sync/pkg/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package sync

import (
"flag"
"fmt"
"os"
)

const hostDefault = "0.0.0.0"
const portDefault = "9090"
const cmdDefault = "start"

// arrayFlags is a custom flag implementation
type arrayFlags struct {
Array []string
}

func (i *arrayFlags) String() string {
return fmt.Sprint(i.Array)
}

func (i *arrayFlags) Set(value string) error {
i.Array = append(i.Array, value)
return nil
}

type Config struct {
Command string
Host string
Port string
Secure bool
Files arrayFlags
CertPath string
KeyPath string
}

func LoadConfig() Config {
cfg := Config{}

start := flag.NewFlagSet("start", flag.ExitOnError)
start.StringVar(&cfg.Host, "h", hostDefault, "hostDefault of the server")
start.StringVar(&cfg.Port, "p", portDefault, "portDefault of the server")
start.Var(&cfg.Files, "f", "file to watch")
start.BoolVar(&cfg.Secure, "s", false, "enable tls")
start.StringVar(&cfg.CertPath, "certPath", "", "certificate path for tls connection")
start.StringVar(&cfg.KeyPath, "keyPath", "", "certificate key for tls connection")
start.Parse(os.Args[2:])

return cfg
}
5 changes: 3 additions & 2 deletions grpc-sync-server/pkg/otel.go → sync/pkg/otel.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package Core
package sync

import (
"context"
"log"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.18.0"
"log"
)

const exporterAddress = "localhost:4317"
Expand Down
8 changes: 4 additions & 4 deletions grpc-sync-server/pkg/server.go → sync/pkg/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Core
package sync

import (
"context"
Expand Down Expand Up @@ -140,11 +140,11 @@ func (s *SyncImpl) readFlags() ([]byte, error) {

for _, path := range s.filePaths {
bytes, err := os.ReadFile(path)
if len(bytes) == 0 {
for len(bytes) == 0 {
// this is a fitly hack
// file writes are NOT atomic and often when they are changed they have transitional empty states
// file writes are NOT atomic and often when they are occur they have transitional empty states
// this "re-reads" the file in these cases a bit later
time.Sleep(100 * time.Millisecond)
time.Sleep(10 * time.Millisecond)
bytes, err = os.ReadFile(path)
}
if err != nil {
Expand Down

0 comments on commit 064b6dc

Please sign in to comment.