Improve examples using go & docker stdlib packages
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
46
examples/dagger-dev/main.cue
Normal file
46
examples/dagger-dev/main.cue
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
// A dagger configuration to build and test the dagger source code.
|
||||
// This configuration can easily be adapted to build and test any go project.
|
||||
//
|
||||
//
|
||||
// Example:
|
||||
// dagger compute ./examples/dagger-dev --input-dir repository=/path/to/go/project
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/go"
|
||||
"dagger.io/docker"
|
||||
)
|
||||
|
||||
repository: dagger.#Dir
|
||||
|
||||
// Build `dagger` using Go
|
||||
build: go.#Build & {
|
||||
source: repository
|
||||
packages: "./cmd/dagger"
|
||||
output: "/usr/local/bin/dagger"
|
||||
}
|
||||
|
||||
// Run go tests
|
||||
test: go.#Test & {
|
||||
source: repository
|
||||
packages: "./..."
|
||||
}
|
||||
|
||||
// Run a command with the binary we just built
|
||||
help: docker.#Run & {
|
||||
image: build
|
||||
args: ["dagger", "-h"]
|
||||
}
|
||||
|
||||
// Build dagger using the (included) Dockerfile
|
||||
buildWithDocker: docker.#Build & {
|
||||
source: repository
|
||||
}
|
||||
|
||||
// Run a command in the docker image we just built
|
||||
helpFromDocker: docker.#Run & {
|
||||
image: buildWithDocker.image
|
||||
args: ["dagger", "-h"]
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/go"
|
||||
)
|
||||
|
||||
repository: dagger.#Dir // Use `--input-dir repository=.` from the root directory of the project
|
||||
|
||||
// Build `dagger` using Go
|
||||
build: go.#Build & {
|
||||
source: repository
|
||||
packages: "./cmd/dagger"
|
||||
output: "/usr/local/bin/dagger"
|
||||
}
|
||||
|
||||
test: go.#Test & {
|
||||
source: repository
|
||||
packages: "./..."
|
||||
}
|
||||
|
||||
// Run a command with the binary we just built
|
||||
help: #compute: [
|
||||
dagger.#Load & {from: build},
|
||||
dagger.#Exec & {args: ["dagger", "-h"]},
|
||||
]
|
||||
|
||||
// Build dagger using the (included) Dockerfile
|
||||
buildWithDocker: #compute: [
|
||||
dagger.#DockerBuild & {
|
||||
context: repository
|
||||
},
|
||||
]
|
||||
|
||||
// Run a command in the docker image we just built
|
||||
helpFromDocker: #compute: [
|
||||
dagger.#Load & {from: buildWithDocker},
|
||||
dagger.#Exec & {args: ["dagger", "-h"]},
|
||||
]
|
@@ -1,17 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/netlify"
|
||||
"dagger.io/yarn"
|
||||
"dagger.io/git"
|
||||
)
|
||||
|
||||
repository: #compute: [
|
||||
dagger.#FetchGit & {
|
||||
remote: "https://github.com/kabirbaidhya/react-todo-app.git"
|
||||
ref: "624041b17bd62292143f99bce474a0e3c2d2dd61"
|
||||
},
|
||||
]
|
||||
repository: git.#Repository & {
|
||||
remote: "https://github.com/kabirbaidhya/react-todo-app.git"
|
||||
ref: "624041b17bd62292143f99bce474a0e3c2d2dd61"
|
||||
}
|
||||
|
||||
todoApp: netlify.#Site & {
|
||||
account: {
|
||||
|
@@ -1,68 +0,0 @@
|
||||
package simple
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
let alpine = {
|
||||
digest: "sha256:3c7497bf0c7af93428242d6176e8f7905f2201d8fc5861f45be7a346b5f23436"
|
||||
package: [string]: true | false | string
|
||||
#compute: [
|
||||
{
|
||||
do: "fetch-container"
|
||||
ref: "index.docker.io/alpine@\(digest)"
|
||||
},
|
||||
for pkg, info in package {
|
||||
if (info & true) != _|_ {
|
||||
do: "exec"
|
||||
args: ["apk", "add", "-U", "--no-cache", pkg]
|
||||
}
|
||||
if (info & string) != _|_ {
|
||||
do: "exec"
|
||||
args: ["apk", "add", "-U", "--no-cache", "\(pkg)\(info)"]
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
www: {
|
||||
|
||||
source: dagger.#Dir
|
||||
|
||||
// List the contents of the source directory
|
||||
listing: {
|
||||
string
|
||||
|
||||
#compute: [
|
||||
dagger.#Load & {
|
||||
from: alpine
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["sh", "-c", "ls /src > /tmp/out"]
|
||||
mount: "/src": from: source
|
||||
},
|
||||
dagger.#Export & {
|
||||
source: "/tmp/out"
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
host: string
|
||||
|
||||
url: {
|
||||
string
|
||||
|
||||
#compute: [
|
||||
{
|
||||
do: "load"
|
||||
from: alpine
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["sh", "-c", "echo -n 'https://\(host)/foo' > /tmp/out"]
|
||||
},
|
||||
dagger.#Export & {
|
||||
source: "/tmp/out"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user