Skip to content

Commit

Permalink
feat(minio): add minio module
Browse files Browse the repository at this point in the history
Signed-off-by: Vasek - Tom C <[email protected]>
  • Loading branch information
TomChv committed Nov 11, 2023
1 parent 891e322 commit c800596
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ci/minioIntegration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import "context"

func (i *IntegrationTest) Minio(ctx context.Context) error {
// password := dag.SetSecret("minio_password", "XxXSecretPwd")
// user := dag.SetSecret("minio_user", "daggerverse-test")

return nil
}
3 changes: 3 additions & 0 deletions minio/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dagger.gen.go
/internal/querybuilder/
/querybuilder/
97 changes: 97 additions & 0 deletions minio/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package main

import (
"context"
"fmt"
)

type MC struct {
Ctr *Container
}

// MC returns a Minio Client.
func (m *Minio) MC() *MC {
ctr := dag.
Container().
From(fmt.Sprintf("minio/mc:%s", m.Version))

return &MC{
Ctr: ctr,
}
}

// MCFromContainer use the given container as Minio client.
//
// This is useful to configure your own minio client or execute special
// operation.
func (m *Minio) MCFromContainer(ctr *Container) *MC {
return &MC{
Ctr: ctr,
}
}

// Container returns the Minio Container.
func (c *MC) Container() *Container {
return c.Ctr
}

// AliasSet adds an alias to the minio client.
func (c *MC) AliasSet(alias string, host string, username *Secret, password *Secret) *MC {
c.Ctr = c.Ctr.
WithSecretVariable("MINIO_ACCESS_KEY", username).
WithSecretVariable("MINIO_SECRET_KEY", password).
WithExec(
[]string{"/bin/sh", "-c", "mc", "alias", "set", alias, host, "$MINIO_ACCESS_KEY", "$MINIO_SECRET_KEY"},
ContainerWithExecOpts{SkipEntrypoint: true},
)

return c
}

// AliasRemove deletes an alias from the minio client.
func (c *MC) AliasRemove(alias string) *MC {
c.Ctr = c.Ctr.
WithExec([]string{"remove", alias})

return c
}

// List returns a list of all object gave at the target.
func (c *MC) List(ctx context.Context, target Optional[string]) (string, error) {
return c.Ctr.
WithExec([]string{"ls", target.GetOr("")}).
Stdout(ctx)
}

// MakeBucket creates a bucket in the given target at the given path.
func (c *MC) MakeBucket(target string, path string) *MC {
c.Ctr = c.Ctr.
WithExec([]string{"mb", fmt.Sprintf("%s/%s", target, path)})

return c
}

// CopyFile adds the given file to the path given in the target.
func (c *MC) CopyFile(file *File, target string, path string) *MC {
c.Ctr = c.Ctr.
WithMountedFile("/file.txt", file).
WithExec([]string{"cp", "/file.txt", fmt.Sprintf("%s/%s", target, path)})

return c
}

// CopyDir adds the given directory to the path given in the target.
func (c *MC) CopyDir(dir *Directory, target string, path string) *MC {
c.Ctr = c.Ctr.
WithMountedDirectory("/dir", dir).
WithExec([]string{"cp", "/dir", fmt.Sprintf("%s/%s", target, path)})

return c
}

// Exec returns the result of the given command.
func (c *MC) Exec(ctx context.Context, command ...string) (string, error) {
return c.Ctr.
WithExec(command).
Stdout(ctx)
}
4 changes: 4 additions & 0 deletions minio/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "minio",
"sdk": "go"
}
15 changes: 15 additions & 0 deletions minio/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module main

go 1.21.3

require (
github.com/99designs/gqlgen v0.17.31
github.com/Khan/genqlient v0.6.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.4.0
)

require (
github.com/stretchr/testify v1.8.3 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
)
35 changes: 35 additions & 0 deletions minio/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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/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=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/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=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
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.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/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
46 changes: 46 additions & 0 deletions minio/minio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

type Minio struct {
Version string
ServerPort int
ConsolePort int
Username *Secret
Password *Secret
Cache bool
}

// WithVersion sets a version for Minio.
func (m *Minio) WithVersion(version string) *Minio {
m.Version = version

return m
}

// WithConsolePort sets a port to listen to the console.
func (m *Minio) WithConsolePort(port int) *Minio {
m.ConsolePort = port

return m
}

// WithServerPort sets a port to listen to the server.
func (m *Minio) WithServerPort(port int) *Minio {
m.ServerPort = port

return m
}

// WithCredential sets access and secret key in the CLI.
func (m *Minio) WithCredential(username *Secret, password *Secret) *Minio {
m.Username = username
m.Password = password

return m
}

// WithCache enables long living storage on the server.
func (m *Minio) WithCache(cache bool) *Minio {
m.Cache = cache

return m
}
42 changes: 42 additions & 0 deletions minio/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import "fmt"

// Server returns a Container with a Minio server ready to be started.
// If set, the server adds authentication with username/password
// (access/secret keys).
//
// By default, the server listens on port 9000 and console on port
// 9001, but it can be sets to another value with methods.
func (m *Minio) Server() *Container {
ctr := dag.
Container().
From(fmt.Sprintf("quay.io/minio/minio:%s", m.Version))

// Setup port with given or default values
if m.ServerPort == 0 {
m.ServerPort = 9000
}

if m.ConsolePort == 0 {
m.ConsolePort = 9001
}

ctr = ctr.
WithExposedPort(m.ServerPort).
WithExposedPort(m.ConsolePort)

// Setup credential
if m.Username != nil && m.Password != nil {
ctr = ctr.
WithSecretVariable("MINIO_ROOT_USER", m.Username).
WithSecretVariable("MINIO_ROOT_PASSWORD", m.Password)
}

// Set cache if set to true
if m.Cache {
ctr = ctr.WithMountedCache("/data", dag.CacheVolume("minio-data"))
}

return ctr
}

0 comments on commit c800596

Please sign in to comment.