14 Commits

Author SHA1 Message Date
45d63c2f90 disable with entrypoint 2022-10-31 00:26:44 +01:00
d90cbb8ff4 with actual name 2022-10-31 00:21:58 +01:00
b06ed52413 with mkdir 2022-10-31 00:13:07 +01:00
3bf5168347 with actual revision 2022-10-30 22:37:30 +01:00
050c50f6c7 dagger go instead 2022-10-30 22:29:22 +01:00
0376578c61 trying to just mount instead 2022-10-30 22:27:04 +01:00
98a08fc3ef just cp 2022-10-30 22:12:09 +01:00
a83a28f40d just ls 2022-10-30 22:08:30 +01:00
20298898fb just ls 2022-10-30 22:06:14 +01:00
064cec5742 without comma 2022-10-30 22:03:56 +01:00
33b60cea3b more debugging 2022-10-30 22:01:48 +01:00
9ffb6b71bd remove file 2022-10-30 21:55:09 +01:00
d37a6bbc85 with mkdir 2022-10-30 21:52:40 +01:00
ade5768001 with mkdir 2022-10-30 21:52:31 +01:00
8 changed files with 62 additions and 26 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
main

View File

@@ -2,7 +2,7 @@ module ci
go 1.19 go 1.19
require git.front.kjuulh.io/kjuulh/dagger-go v0.0.11 require git.front.kjuulh.io/kjuulh/dagger-go v0.0.22
require ( require (
dagger.io/dagger v0.3.1 // indirect dagger.io/dagger v0.3.1 // indirect

View File

@@ -45,6 +45,24 @@ git.front.kjuulh.io/kjuulh/dagger-go v0.0.10 h1:d9VNhI6OsiR/W4/1iJvchuHwTq2C3AHw
git.front.kjuulh.io/kjuulh/dagger-go v0.0.10/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8= git.front.kjuulh.io/kjuulh/dagger-go v0.0.10/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.11 h1:j3ylHiGmhcFomggJcrNJghbYBK/nuuvw0naFBIWqEqo= git.front.kjuulh.io/kjuulh/dagger-go v0.0.11 h1:j3ylHiGmhcFomggJcrNJghbYBK/nuuvw0naFBIWqEqo=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.11/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8= git.front.kjuulh.io/kjuulh/dagger-go v0.0.11/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.12 h1:c75Ac8joaOMfaOSPf+ZcvNdBcytx0hzIJMYXexKGXJ0=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.12/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.15 h1:jYFyZo2S3KPPo+eGd9TqRSqP3U5lqXXguP56STyklLA=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.15/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.16 h1:JP+K+4B3APG/bxKjAV3SHEkm2GSRgsDSeS3vT9fIqnU=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.16/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.17 h1:lo4bvPLwO3AhlMPJOoZnetLY66HSlw2rfCc2Mi1QV38=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.17/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.18 h1:asW/jEmf3HORb6nqgUldoLge/UjEFFnII0YjPYQ+Qg0=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.18/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.19 h1:IgpZ1X5ZDYl/byBSife1wXTBmFHNvHwf1MLw8AZ29R4=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.19/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.20 h1:iw/gnsaGe4SzqbRT6i14LPvu/Cpbe7XiCpnqFfkTLA8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.20/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.21 h1:r6OuEyxx7yhgD+lrIMDhal4fDuVS5anWrXO5lyPMXPg=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.21/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.22 h1:ajOhF6B7M43dPE1BAFoi55yOCSBwCxZYHH0CgFIm0bk=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.22/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
github.com/99designs/gqlgen v0.17.2/go.mod h1:K5fzLKwtph+FFgh9j7nFbRUdBKvTcGnsta51fsMTn3o= github.com/99designs/gqlgen v0.17.2/go.mod h1:K5fzLKwtph+FFgh9j7nFbRUdBKvTcGnsta51fsMTn3o=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=

View File

@@ -4,7 +4,7 @@ name: "drone-dagger-test"
steps: steps:
- name: "build" - name: "build"
image: harbor.front.kjuulh.io/kjuulh/dagger-go:1667159344332 image: harbor.front.kjuulh.io/kjuulh/dagger-go:1667171629427
volumes: volumes:
- name: dockersock - name: dockersock
path: /var/run path: /var/run
@@ -17,7 +17,12 @@ steps:
from_secret: "harbor_docker_password" from_secret: "harbor_docker_password"
commands: commands:
- sleep 5 - sleep 5
- sh -c "/dagger-go build golangbin" - >
echo "$${HARBOR_DOCKER_PASSWORD}" | docker login
--password-stdin
--username="$${HARBOR_DOCKER_USERNAME}"
"$${HARBOR_DOCKER_HOST}"
- dagger-go build golangbin
services: services:
- name: docker - name: docker

BIN
main

Binary file not shown.

View File

@@ -2,7 +2,6 @@ package cli
import ( import (
"errors" "errors"
"fmt"
"os" "os"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder" "git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
@@ -18,7 +17,6 @@ func BuildGolangBin() *cobra.Command {
if repoName == "" { if repoName == "" {
return errors.New("could not find DRONE_REPO_NAME") return errors.New("could not find DRONE_REPO_NAME")
} }
imageTag := fmt.Sprintf("harbor.front.kjuulh.io/library/%s", repoName)
ctx := cmd.Context() ctx := cmd.Context()
@@ -32,10 +30,11 @@ func BuildGolangBin() *cobra.Command {
New(builder). New(builder).
WithGolangBin(&pipelines.GolangBinOpts{ WithGolangBin(&pipelines.GolangBinOpts{
DockerImageOpt: &pipelines.DockerImageOpt{ DockerImageOpt: &pipelines.DockerImageOpt{
ImageName: imageTag, ImageName: repoName,
}, },
BuildPath: "main.go", BuildPath: "main.go",
BinName: "main", BinName: "main",
ExecuteOnEntrypoint: true,
}). }).
Execute(ctx) Execute(ctx)
}, },

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"log" "log"
"path"
"strconv" "strconv"
"time" "time"
@@ -24,6 +25,7 @@ type GolangBinOpts struct {
BuildPath string BuildPath string
BinName string BinName string
BaseImage string BaseImage string
ExecuteOnEntrypoint bool
} }
func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline { func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
@@ -69,29 +71,35 @@ func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
Step( Step(
"create-production-image", "create-production-image",
byg.Step{ byg.Step{
Execute: func(ctx byg.Context) error { Execute: func(_ byg.Context) error {
if opts.BaseImage == "" { if opts.BaseImage == "" {
opts.BaseImage = "harbor.front.kjuulh.io/docker-proxy/library/busybox" opts.BaseImage = "harbor.front.kjuulh.io/docker-proxy/library/busybox"
} }
c := container.LoadImage(client, opts.BaseImage)
tempmount := fmt.Sprintf("/tmp/%s", opts.BinName) binpath := "/usr/bin"
usrbin := fmt.Sprintf("/bin/%s", opts.BinName) usrbin := path.Join(binpath, opts.BinName)
log.Printf("binname: %s", bin) c := container.LoadImage(client, opts.BaseImage)
c = container.MountFileFromLoaded(c, bin, tempmount)
c = c.Exec(dagger.ContainerExecOpts{ c = c.Exec(dagger.ContainerExecOpts{
Args: []string{"cp", tempmount, usrbin}, Args: []string{"mkdir", "-p", binpath},
}) })
c, err := container.MountFileFromLoaded(ctx, c, bin, usrbin)
if err != nil {
return err
}
if opts.ExecuteOnEntrypoint {
finalImage = c.WithEntrypoint([]string{usrbin}) finalImage = c.WithEntrypoint([]string{usrbin})
} else {
finalImage = c
}
return nil return nil
}, },
}, },
//byg.Step{ byg.Step{
// Execute: func(_ byg.Context) error { Execute: func(_ byg.Context) error {
// return golang.Test(ctx, build) return golang.Test(ctx, build)
// }, },
//}, },
). ).
Step( Step(
"upload-image", "upload-image",

View File

@@ -21,7 +21,12 @@ func MountCurrent(ctx context.Context, client *dagger.Client, container *dagger.
return container.WithMountedDirectory(into, src), nil 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) 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
} }