Skip to content

Commit

Permalink
feat(build): add ./build.sh hack:fliptcup target
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMac committed Aug 2, 2023
1 parent b3375a6 commit e4f7ce3
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 1 deletion.
14 changes: 14 additions & 0 deletions build/hack/config/api-binding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"apiVersion": "cup.flipt.io/v1alpha1",
"kind": "Binding",
"metadata": {
"name": "flipt"
},
"spec": {
"controller": "flipt",
"resources": [
"flipt.io/v1alpha1/flags",
"flipt.io/v1alpha1/segments"
]
}
}
54 changes: 54 additions & 0 deletions build/hack/config/flags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"apiVersion": "cup.flipt.io/v1alpha1",
"kind": "ResourceDefinition",
"metadata": {
"name": "flags.flipt.io"
},
"names": {
"kind": "Flag",
"singular": "flag",
"plural": "flags"
},
"spec": {
"group": "flipt.io",
"versions": {
"v1alpha1": {
"type": "object",
"properties": {
"key": { "type": "string" },
"name": { "type": "string" },
"type": { "enum": ["", "FLAG_TYPE_VARIANT", "FLAG_TYPE_BOOLEAN"] },
"enabled": { "type": "boolean" },
"description": { "type": "string" },
"variants": {
"type": ["array", "null"],
"items": {
"type": "object",
"properties": {
"key": { "type": "string" },
"description": { "type": "string" },
"attachment": {
"type": "object",
"additionalProperties": true
}
}
}
},
"rules": {
"type": ["array", "null"],
"items": {
"type": "object"
}
},
"rollouts": {
"type": ["array", "null"],
"items": {
"type": "object"
}
}
},
"additionalProperties": false
}
}
}
}
13 changes: 13 additions & 0 deletions build/hack/config/flipt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"apiVersion": "cup.flipt.io/v1alpha1",
"kind": "Controller",
"metadata": {
"name": "flipt"
},
"spec": {
"type": "wasm",
"spec": {
"path": "flipt.wasm"
}
}
}
24 changes: 24 additions & 0 deletions build/hack/config/segments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"apiVersion": "cup.flipt.io/v1alpha1",
"kind": "ResourceDefinition",
"metadata": {
"name": "segments.flipt.io"
},
"names": {
"kind": "Segment",
"singular": "segment",
"plural": "segments"
},
"spec": {
"group": "flipt.io",
"versions": {
"v1alpha1": {
"type": "object",
"properties": {
"enabled": { "type": "boolean" }
},
"additionalProperties": false
}
}
}
}
30 changes: 30 additions & 0 deletions build/hack/flipt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hack

import (
"context"

"dagger.io/dagger"
)

func FliptCup(ctx context.Context, client *dagger.Client, base *dagger.Container) (*dagger.Container, error) {
flipt := base.WithEnvVariable("GOOS", "wasip1").
WithEnvVariable("GOARCH", "wasm").
WithExec([]string{
"go", "build", "-o", "flipt.wasm", "./ext/controllers/flipt.io/v1alpha1/cmd/flipt/...",
}).
File("flipt.wasm")

return client.
Container().
From("alpine:3.18").
WithExec([]string{"mkdir", "-p", "/var/run/cupd"}).
WithWorkdir("/var/run/cupd").
WithDirectory("/etc/cupd/config", client.Host().Directory("build/hack/config")).
WithFile("/etc/cupd/config/flipt.wasm", flipt).
WithFile("/usr/local/bin/cupd", base.File("/usr/local/bin/cupd")).
WithFile("/usr/local/bin/cup", base.File("/usr/local/bin/cup")).
WithDefaultArgs(dagger.ContainerWithDefaultArgsOpts{
Args: []string{"/usr/local/bin/cupd", "serve", "-api-resources", "/etc/cupd/config"},
}).
Sync(ctx)
}
22 changes: 21 additions & 1 deletion build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"dagger.io/dagger"
"github.com/urfave/cli/v2"
"go.flipt.io/cup/build/hack"
)

const (
Expand All @@ -24,6 +25,22 @@ func main() {
Action: func(ctx *cli.Context) error {
return build(ctx.Context)
},
Subcommands: []*cli.Command{
{
Name: "hack:fliptcup",
Action: func(ctx *cli.Context) error {
return withBase(ctx.Context, func(ctx context.Context, client *dagger.Client, base *dagger.Container) error {
cup, err := hack.FliptCup(ctx, client, base)
if err != nil {
return err
}

_, err = cup.Export(ctx, "fliptcup.tar")
return err
})
},
},
},
},
{
Name: "test",
Expand Down Expand Up @@ -87,7 +104,10 @@ func withBase(ctx context.Context, fn func(ctx context.Context, client *dagger.C

return fn(ctx, client, base.
WithMountedCache(goBuildCachePath, cacheGoBuild).
WithMountedCache(goModCachePath, cacheGoMod))
WithMountedCache(goModCachePath, cacheGoMod).
WithExec([]string{"go", "build", "-o", "/usr/local/bin/cupd", "./cmd/cupd/..."}).
WithExec([]string{"go", "build", "-o", "/usr/local/bin/cup", "./cmd/cup/..."}),
)
})
}

Expand Down

0 comments on commit e4f7ce3

Please sign in to comment.