From 60ce946950fe07cf341fb4b41f334f05928f8e98 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 19 Feb 2021 01:25:41 -0800 Subject: [PATCH 1/2] stdlib: go support Signed-off-by: Andrea Luzzardi --- stdlib/go/go.cue | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 stdlib/go/go.cue diff --git a/stdlib/go/go.cue b/stdlib/go/go.cue new file mode 100644 index 00000000..75adb256 --- /dev/null +++ b/stdlib/go/go.cue @@ -0,0 +1,102 @@ +package go + +import ( + "dagger.io/dagger" +) + +#Go: { + // Go version to use + version: *"1.16" | string + + // Arguments to the Go binary + args: [...string] + + // Source Directory to build + source: dagger.#Dir + + // Environment variables + env: [string]: string + + #dagger: compute: [ + dagger.#FetchContainer & { + ref: "docker.io/golang:\(version)-alpine" + }, + dagger.#Copy & { + from: source + dest: "/src" + }, + dagger.#Exec & { + dir: "/src" + "args": ["go"] + args + + env: env + env: CGO_ENABLED: "0" + // FIXME: this should come from the golang image. + // https://github.com/dagger/dagger/issues/130 + env: { + PATH: "/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + GOPATH: "/go" + } + + mount: "/root/.cache": "cache" + }, + ] +} + +#Build: { + // Go version to use + version: *#Go.version | string + + // Source Directory to build + source: dagger.#Dir + + // Packages to build + packages: *"." | string + + // Target architecture + arch: *"amd64" | string + + // Target OS + os: *"linux" | string + + // Build tags to use for building + tags: *"" | string + + // LDFLAGS to use for linking + ldflags: *"" | string + + // Specify the targeted binary name + output: string + + env: [string]: string + + #dagger: compute: [ + dagger.#Copy & { + from: #Go & { + "version": version + "source": source + "env": env + args: ["build", "-v", "-tags", tags, "-ldflags", ldflags, "-o", output, packages] + } + src: output + dest: output + }, + ] +} + +#Test: { + // Go version to use + version: *#Go.version | string + + // Source Directory to build + source: dagger.#Dir + + // Packages to test + packages: *"." | string + + #Go & { + "version": version + "source": source + args: ["test", "-v", packages] + } +} From 74d3bb81cb2aefa59e43d448d33881a15ee754fc Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 19 Feb 2021 01:25:53 -0800 Subject: [PATCH 2/2] examples: dogfood! Signed-off-by: Andrea Luzzardi --- examples/dogfood/main.cue | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/dogfood/main.cue diff --git a/examples/dogfood/main.cue b/examples/dogfood/main.cue new file mode 100644 index 00000000..486a3c03 --- /dev/null +++ b/examples/dogfood/main.cue @@ -0,0 +1,24 @@ +package main + +import ( + "dagger.io/dagger" + "dagger.io/go" +) + +repository: dagger.#Dir // Use `--input-dir repository=.` from the root directory of the project + +build: go.#Build & { + source: repository + packages: "./cmd/dagger" + output: "/usr/local/bin/dagger" +} + +test: go.#Test & { + source: repository + packages: "./..." +} + +help: #dagger: compute: [ + dagger.#Load & {from: build}, + dagger.#Exec & {args: ["dagger", "-h"]}, +]