Skip to content

Commit

Permalink
ci: use zenith generated code with mage
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Oct 15, 2023
1 parent 556ad09 commit 41c6169
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 39 deletions.
3 changes: 3 additions & 0 deletions ci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dagger.gen.go
/internal/querybuilder/
/querybuilder/
5 changes: 5 additions & 0 deletions ci/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "ci",
"sdk": "go",
"sdkRuntime": "vito/dagger-sdk-go:no-ptrs@sha256:2bb26bae3f30b920a4530b7495127fe4986102b06a99ff170500e83c25739b27"
}
13 changes: 6 additions & 7 deletions ci/go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module github.com/portward/cerbos/ci
module ci

go 1.21.1
go 1.21.3

require (
dagger.io/dagger v0.8.7
dagger.io/dagger v0.8.8
github.com/99designs/gqlgen v0.17.31
github.com/Khan/genqlient v0.6.0
github.com/magefile/mage v1.15.0
golang.org/x/sync v0.3.0
)

require (
github.com/99designs/gqlgen v0.17.31 // indirect
github.com/Khan/genqlient v0.6.0 // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)
11 changes: 4 additions & 7 deletions ci/go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
dagger.io/dagger v0.8.7 h1:3wGzK9RKjLcNk5AnIYqkO7TzIJyftb8fT+h0WM9chAM=
dagger.io/dagger v0.8.7/go.mod h1:DbJi6aSXaRLuio0lHlnpNxfuAL5uMJvRy4UIytmbtLo=
dagger.io/dagger v0.8.8 h1:vzQVbRJ2xg+uKmcg3Y/FHn1Ry513JVOACn0gDBFFEVA=
dagger.io/dagger v0.8.8/go.mod h1:d6yRd1k37fs5fCOlLKAkSB//qB26+z23UiikIb0z+uU=
github.com/99designs/gqlgen v0.17.31 h1:VncSQ82VxieHkea8tz11p7h/zSbvHSxSDZfywqWt158=
github.com/99designs/gqlgen v0.17.31/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4=
github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk=
github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
Expand All @@ -15,8 +14,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand All @@ -31,8 +28,8 @@ github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NF
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq8cRU=
github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
Expand Down
24 changes: 9 additions & 15 deletions ci/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ package main
import (
"context"
"fmt"
"os"

"dagger.io/dagger"
_ "github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
)

Expand All @@ -18,15 +16,11 @@ const (
)

func Test(ctx context.Context) error {
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
return err
}
defer client.Close()
client := dag

var cerbos *dagger.Container
var cerbos *Container

var test *dagger.Container
var test *Container

// Prepare
{
Expand Down Expand Up @@ -58,7 +52,7 @@ func Test(ctx context.Context) error {
}

dir := client.Host().
Directory(".", dagger.HostDirectoryOpts{
Directory(".", HostDirectoryOpts{
Exclude: []string{
".devenv/",
".direnv/",
Expand All @@ -72,7 +66,7 @@ func Test(ctx context.Context) error {
})

_, err = client.Pipeline("Test").
Container(dagger.ContainerOpts{
Container(ContainerOpts{
ID: testContainerID,
}).
WithMountedDirectory("/src", dir).
Expand All @@ -87,19 +81,19 @@ func Test(ctx context.Context) error {
}

// TODO: add go cache
func testContainer(client *dagger.Client) *dagger.Container {
func testContainer(client *Client) *Container {
return client.Container().
From(fmt.Sprintf("%s:%s", goImageRepo, goVersion)).
WithEntrypoint(nil).
WithWorkdir("/src")
}

func cerbosContainer(client *dagger.Client) *dagger.Container {
func cerbosContainer(client *Client) *Container {
config := client.Host().Directory("./etc/cerbos/policies")

return client.Container().From("ghcr.io/cerbos/cerbos:0.30.0").
WithExposedPort(3592, dagger.ContainerWithExposedPortOpts{Protocol: dagger.Tcp}).
WithExposedPort(3593, dagger.ContainerWithExposedPortOpts{Protocol: dagger.Tcp}).
WithExposedPort(3592, ContainerWithExposedPortOpts{Protocol: Tcp}).
WithExposedPort(3593, ContainerWithExposedPortOpts{Protocol: Tcp}).
WithMountedDirectory("/policies", config).
WithExec(nil)
}
13 changes: 8 additions & 5 deletions ci/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//go:build mage
// +build mage

package main

import (
"os"

"github.com/magefile/mage/mage"
"context"
)

func main() {
os.Exit(mage.Main())
type Ci struct{}

func (m *Ci) MyFunction(ctx context.Context, stringArg string) (*Container, error) {
return dag.Container().From("alpine:latest").WithExec([]string{"echo", stringArg}).Sync(ctx)
}
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/master";
flake-parts.url = "github:hercules-ci/flake-parts";
devenv.url = "github:cachix/devenv";
};
Expand Down

0 comments on commit 41c6169

Please sign in to comment.