#Hi dagger people! I am facing an issue
1 messages · Page 1 of 1 (latest)
My setup is as follows
- An application with the following dagger.json that installs the workflow module
go-serviceunder an aliasworkflow:
{
"name": "test-repo",
"engineVersion": "v0.18.12",
"dependencies": [
{
"name": "workflow",
"source": "../workflows/go-service"
}
]
}
- A workflow module called
go-servicewith this dagger json:
{
"name": "go-service",
"engineVersion": "v0.18.12",
"sdk": {
"source": "go"
}
}
The workflow module defines an interface which it accepts over the constructor:
type OpenBao interface {
DaggerObject
GetSecretValue(mountPath, secret, key string) *dagger.Secret
}
type GoService struct {
// +private
Bao OpenBao
}
func New(
bao OpenBao,
) *GoService {
return &GoService{
Bao: bao,
}
}
- a "dependency" module called
openbaothat exposes a single function:
{
"name": "openbao",
"engineVersion": "v0.18.12",
"sdk": {
"source": "go"
}
}
// GetSecretValue - retrieve a secret value from the specified mountPath, secret and key
func (m *Openbao) GetSecretValue(ctx context.Context, mountPath, secret, key string) (*dagger.Secret, error) {
s, err := m.MountPath(mountPath).Secret(ctx, secret)
if err != nil {
return nil, fmt.Errorf("error retrieving the secret: %w", err)
}
v, err := s.Value(ctx, key)
if err != nil {
return nil, fmt.Errorf("error retrieving the secret value: %w", err)
}
return v, nil
}
- The following dagger shell script - which is run when cd'd into the application directory:
#!/usr/bin/bash dagger
bao_token=$(host | set-secret-file "bao-token" ~/.vault-token)
bao=$(github.com/nine-digital/library-ci-workflows/modules/openbao ${BAO_ADDR} ${bao_token})
workflow $bao
This issue is resolved if I change the application's dependency json to this:
{
"name": "test-repo",
"engineVersion": "v0.18.12",
"dependencies": [
{
"name": "go-service",
"source": "../workflows/go-service"
}
]
}
and then change the dagger shell script to this:
#!/usr/bin/bash dagger
bao_token=$(host | set-secret-file "bao-token" ~/.vault-token)
bao=$(github.com/nine-digital/library-ci-workflows/modules/openbao ${BAO_ADDR} ${bao_token})
go-service $bao
Looking a bit further into this... I can see this is probably because the codegen for the go-service module bakes its module name into the graphql query
// go-service/dagger.gen.go
func LoadOpenBaoFromID(r *dagger.Client, id OpenBaoID) OpenBao {
q := querybuilder.Query().Client(r.GraphQLClient())
q = q.Select("loadGoServiceOpenBaoFromID")
q = q.Arg("id", id)
return &openBaoImpl{query: q}
}
To tell the truth, blueprint modules would probably solve the underlying concern for us here because the reason why we were aliasing the workflow module name is so we could supply -m workflow everywhere where we wanted to invoke the workflow module
But blueprint modules would allow us to simply do . <constructor params> | <module-function> in dagger shell or dagger call <constructor-params> <module-function>... so its a minor issue for us