#would this be considred a good dagger
1 messages · Page 1 of 1 (latest)
Do you actually need the resulting container? Based on the description, it looks like you only care about publishing the result and the container is just an implementation detail. If that's the case, I wouln't bother to return it
// Copy an image from one registry to another using skopeo
func (m *Mes) CopyWithAuthfile(
ctx context.Context,
srcRef string,
dstRef string,
authFile *dagger.Secret,
) error {
const mountPath = "/run/secrets/auth.json"
return dag.
Container().
From("quay.io/skopeo/stable:latest").
WithMountedSecret(mountPath, authFile).
WithExec([]string{
"skopeo", "copy",
"--src-authfile=" + mountPath,
"--dest-authfile=" + mountPath,
srcRef, dstRef,
}).
Sync(ctx) // force execution
}
Another cosmetic change: I would rename arguments to something easier to type in the CLI, like src, dst and auth. But that's just cosmetic 🙂
// Copy an image from one registry to another using skopeo
func (m *Mes) CopyWithAuthfile(
ctx context.Context,
// Address of source image
src string,
// Address of destination image
dst string,
// Skopeo authentication file
auth *dagger.Secret,
) error {
const mountPath = "/run/secrets/auth.json"
return dag.
Container().
From("quay.io/skopeo/stable:latest").
WithMountedSecret(mountPath, authFile).
WithExec([]string{
"skopeo", "copy",
"--src-authfile=" + mountPath,
"--dest-authfile=" + mountPath,
src, dst,
}).
Sync(ctx) // force execution
}
Lastly, I wonder if you can skip skopeo altogether, and just use the core Dagger API?
func (m *Mes) Copy(ctx context.Context, src, dst string) error {
return dag.Container()
From(src).
Publish(dst).
Sync(ctx)
}
Note: when using native Container.publish(), the caller's docker auth is used automatically.
Thanks for the reply.
Yeah, using just the core Dagger API makes way more sense, didn’t even think of that 🙂