with more generic way, but still wonky

This commit is contained in:
Kasper Juul Hermansen 2022-10-29 23:33:46 +02:00
parent 0838bc5a56
commit a872bad97d
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
4 changed files with 14 additions and 16 deletions

View File

@ -1,5 +1,3 @@
{{ $imageTag := "harbor.front.kjuulh.io/library/${DRONE_REPO_NAME}" }}
type: docker
kind: pipeline
name: "drone-dagger-test"
@ -18,7 +16,7 @@ steps:
- mkdir -p tmp/dagger-go
- git clone "https://git.front.kjuulh.io/kjuulh/dagger-go.git" tmp/dagger-go
- docker build -t dagger-go-builder:${DRONE_COMMIT} -f tmp/dagger-go/Dockerfile .
- 'docker run -v "$PWD/:/src/" -v /var/run/docker.sock:/var/run/docker.sock dagger-go-builder:${DRONE_COMMIT} dagger-go build --image-tag "{{ or .input.imageTag $imageTag }}"'
- 'docker run -v "$PWD/:/src/" -v /var/run/docker.sock:/var/run/docker.sock dagger-go-builder:${DRONE_COMMIT} dagger-go build'
services:
- name: docker

View File

@ -23,5 +23,5 @@ func run(ctx context.Context) error {
}
defer builder.CleanUp()
return tasks.Build(builder, "some-image")
return tasks.Build(builder, "some-image", "example/main.go")
}

View File

@ -1,19 +1,17 @@
package cli
import (
"errors"
"fmt"
"log"
"os"
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks"
"github.com/spf13/cobra"
)
func Build() *cobra.Command {
var (
imageTag string
mainGoPath string
)
func Build(mainGoPath string, imageTag string) *cobra.Command {
cmd := &cobra.Command{
Use: "build",
RunE: func(cmd *cobra.Command, args []string) error {
@ -21,6 +19,14 @@ func Build() *cobra.Command {
return err
}
if imageTag == "" {
repoName := os.Getenv("DRONE_REPO_NAME")
if repoName == "" {
return errors.New("could not find DRONE_REPO_NAME")
}
imageTag = fmt.Sprintf("harbor.front.kjuulh.io/library/%s", repoName)
}
ctx := cmd.Context()
log.Printf("Building image: %s\n", imageTag)
@ -35,10 +41,5 @@ func Build() *cobra.Command {
},
}
cmd.PersistentFlags().StringVar(&imageTag, "image-tag", "", "the url for which to tag the docker image, defaults to private url, with repo as image name")
cmd.MarkPersistentFlagRequired("image-tag")
cmd.PersistentFlags().StringVar(&mainGoPath, "main-path", "main.go", "main.go path")
return cmd
}

View File

@ -3,7 +3,6 @@ package tasks
import (
"context"
"log"
"os"
"dagger.io/dagger"
"git.front.kjuulh.io/kjuulh/byg"