From 3bf51683473d9fe6208c3f256bfc74e3d4076fda Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 30 Oct 2022 22:37:30 +0100 Subject: [PATCH] with actual revision --- gobin_default_template.yaml | 4 ++-- pkg/pipelines/golang-bin.go | 7 +++++-- pkg/tasks/container/mount.go | 9 +++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gobin_default_template.yaml b/gobin_default_template.yaml index e5b9f07..8a7e070 100644 --- a/gobin_default_template.yaml +++ b/gobin_default_template.yaml @@ -4,7 +4,7 @@ name: "drone-dagger-test" steps: - name: "build" - image: harbor.front.kjuulh.io/kjuulh/dagger-go:1667159344332 + image: harbor.front.kjuulh.io/kjuulh/dagger-go:1667165411134 volumes: - name: dockersock path: /var/run @@ -17,7 +17,7 @@ steps: from_secret: "harbor_docker_password" commands: - sleep 5 - - sh -c "/dagger-go build golangbin" + - ls /usr/bin/ services: - name: docker diff --git a/pkg/pipelines/golang-bin.go b/pkg/pipelines/golang-bin.go index 7ba8b69..1dab33f 100644 --- a/pkg/pipelines/golang-bin.go +++ b/pkg/pipelines/golang-bin.go @@ -69,14 +69,17 @@ func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline { Step( "create-production-image", byg.Step{ - Execute: func(ctx byg.Context) error { + Execute: func(_ byg.Context) error { if opts.BaseImage == "" { opts.BaseImage = "harbor.front.kjuulh.io/docker-proxy/library/busybox" } usrbin := fmt.Sprintf("/usr/bin/%s", opts.BinName) c := container.LoadImage(client, opts.BaseImage) - c = container.MountFileFromLoaded(c, bin, usrbin) + c, err := container.MountFileFromLoaded(ctx, c, bin, usrbin) + if err != nil { + return err + } finalImage = c.WithEntrypoint([]string{usrbin}) return nil diff --git a/pkg/tasks/container/mount.go b/pkg/tasks/container/mount.go index b20d909..867ad14 100644 --- a/pkg/tasks/container/mount.go +++ b/pkg/tasks/container/mount.go @@ -21,7 +21,12 @@ func MountCurrent(ctx context.Context, client *dagger.Client, container *dagger. return container.WithMountedDirectory(into, src), nil } -func MountFileFromLoaded(container *dagger.Container, bin dagger.FileID, path string) *dagger.Container { +func MountFileFromLoaded(ctx context.Context, container *dagger.Container, bin dagger.FileID, path string) (*dagger.Container, error) { log.Printf("mounting binary into container: into (path=%s)", path) - return container.WithMountedFile(path, bin) + newFs, err := container.FS().WithCopiedFile(path, bin).ID(ctx) + if err != nil { + return nil, err + } + + return container.WithFS(newFs), nil }