mirror of
https://github.com/dagger/dagger-for-github.git
synced 2026-01-01 05:00:21 +11:00
update action to dagger 0.2
- Remove AGE key setup - Update README to use `dagger do` - Update tests to dagger 0.2 Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
64f8bd95de
commit
24d6bfd692
96 changed files with 15028 additions and 70 deletions
78
test/cue.mod/pkg/universe.dagger.io/docker/build.cue
vendored
Executable file
78
test/cue.mod/pkg/universe.dagger.io/docker/build.cue
vendored
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
// Modular build API for Docker containers
|
||||
#Build: {
|
||||
steps: [#Step, ...#Step]
|
||||
output: #Image
|
||||
|
||||
// Generate build DAG from linear steps
|
||||
_dag: {
|
||||
for idx, step in steps {
|
||||
"\(idx)": step & {
|
||||
// connect input to previous output
|
||||
if idx > 0 {
|
||||
// FIXME: the intermediary `output` is needed because of a possible CUE bug.
|
||||
// `._dag."0".output: 1 errors in empty disjunction::`
|
||||
// See: https://github.com/cue-lang/cue/issues/1446
|
||||
// input: _dag["\(idx-1)"].output
|
||||
_output: _dag["\(idx-1)"].output
|
||||
input: _output
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(_dag) > 0 {
|
||||
output: _dag["\(len(_dag)-1)"].output
|
||||
}
|
||||
}
|
||||
|
||||
// A build step is anything that produces a docker image
|
||||
#Step: {
|
||||
input?: #Image
|
||||
output: #Image
|
||||
...
|
||||
}
|
||||
|
||||
// Build step that copies files into the container image
|
||||
#Copy: {
|
||||
input: #Image
|
||||
contents: dagger.#FS
|
||||
source: string | *"/"
|
||||
dest: string | *"/"
|
||||
|
||||
// Execute copy operation
|
||||
_copy: dagger.#Copy & {
|
||||
"input": input.rootfs
|
||||
"contents": contents
|
||||
"source": source
|
||||
"dest": dest
|
||||
}
|
||||
|
||||
output: #Image & {
|
||||
config: input.config
|
||||
rootfs: _copy.output
|
||||
}
|
||||
}
|
||||
|
||||
// Build step that executes a Dockerfile
|
||||
#Dockerfile: {
|
||||
// Source directory
|
||||
source: dagger.#FS
|
||||
|
||||
// FIXME: not yet implemented
|
||||
*{
|
||||
// Look for Dockerfile in source at default path
|
||||
path: "Dockerfile"
|
||||
} | {
|
||||
// Look for Dockerfile in source at a custom path
|
||||
path: string
|
||||
} | {
|
||||
// Custom dockerfile contents
|
||||
contents: string
|
||||
}
|
||||
}
|
||||
23
test/cue.mod/pkg/universe.dagger.io/docker/image.cue
vendored
Executable file
23
test/cue.mod/pkg/universe.dagger.io/docker/image.cue
vendored
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
// A container image
|
||||
#Image: {
|
||||
// Root filesystem of the image.
|
||||
rootfs: dagger.#FS
|
||||
|
||||
// Image config
|
||||
config: dagger.#ImageConfig
|
||||
}
|
||||
|
||||
// A ref is an address for a remote container image
|
||||
// Examples:
|
||||
// - "index.docker.io/dagger"
|
||||
// - "dagger"
|
||||
// - "index.docker.io/dagger:latest"
|
||||
// - "index.docker.io/dagger:latest@sha256:a89cb097693dd354de598d279c304a1c73ee550fbfff6d9ee515568e0c749cfe"
|
||||
// FIXME: add formatting constraints
|
||||
#Ref: dagger.#Ref
|
||||
34
test/cue.mod/pkg/universe.dagger.io/docker/pull.cue
vendored
Executable file
34
test/cue.mod/pkg/universe.dagger.io/docker/pull.cue
vendored
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
// Build, ship and run Docker containers in Dagger
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
// Download an image from a remote registry
|
||||
#Pull: {
|
||||
// Source ref.
|
||||
source: #Ref
|
||||
|
||||
// Registry authentication
|
||||
auth?: {
|
||||
username: string
|
||||
secret: dagger.#Secret
|
||||
}
|
||||
|
||||
_op: dagger.#Pull & {
|
||||
"source": source
|
||||
if auth != _|_ {
|
||||
"auth": auth
|
||||
}
|
||||
}
|
||||
|
||||
// Downloaded image
|
||||
image: #Image & {
|
||||
rootfs: _op.output
|
||||
config: _op.config
|
||||
}
|
||||
|
||||
// FIXME: compat with Build API
|
||||
output: image
|
||||
}
|
||||
32
test/cue.mod/pkg/universe.dagger.io/docker/push.cue
vendored
Executable file
32
test/cue.mod/pkg/universe.dagger.io/docker/push.cue
vendored
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
// Upload an image to a remote repository
|
||||
#Push: {
|
||||
// Destination ref
|
||||
dest: #Ref
|
||||
|
||||
// Complete ref after pushing (including digest)
|
||||
result: #Ref & _push.result
|
||||
|
||||
// Registry authentication
|
||||
auth?: {
|
||||
username: string
|
||||
secret: dagger.#Secret
|
||||
}
|
||||
|
||||
// Image to push
|
||||
image: #Image
|
||||
|
||||
_push: dagger.#Push & {
|
||||
"dest": dest
|
||||
if auth != _|_ {
|
||||
"auth": auth
|
||||
}
|
||||
input: image.rootfs
|
||||
config: image.config
|
||||
}
|
||||
}
|
||||
166
test/cue.mod/pkg/universe.dagger.io/docker/run.cue
vendored
Executable file
166
test/cue.mod/pkg/universe.dagger.io/docker/run.cue
vendored
Executable file
|
|
@ -0,0 +1,166 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"list"
|
||||
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
// Run a command in a container
|
||||
#Run: {
|
||||
// Docker image to execute
|
||||
input: #Image
|
||||
|
||||
always: bool | *false
|
||||
|
||||
// Filesystem mounts
|
||||
mounts: [name=string]: dagger.#Mount
|
||||
|
||||
// Expose network ports
|
||||
// FIXME: investigate feasibility
|
||||
ports: [name=string]: {
|
||||
frontend: dagger.#Service
|
||||
backend: {
|
||||
protocol: *"tcp" | "udp"
|
||||
address: string
|
||||
}
|
||||
}
|
||||
|
||||
// Command to execute
|
||||
command?: {
|
||||
// Name of the command to execute
|
||||
// Examples: "ls", "/bin/bash"
|
||||
name: string
|
||||
|
||||
// Positional arguments to the command
|
||||
// Examples: ["/tmp"]
|
||||
args: [...string]
|
||||
|
||||
// Command-line flags represented in a civilized form
|
||||
// Example: {"-l": true, "-c": "echo hello world"}
|
||||
flags: [string]: (string | true)
|
||||
|
||||
_flatFlags: list.FlattenN([
|
||||
for k, v in flags {
|
||||
if (v & bool) != _|_ {
|
||||
[k]
|
||||
}
|
||||
if (v & string) != _|_ {
|
||||
[k, v]
|
||||
}
|
||||
},
|
||||
], 1)
|
||||
}
|
||||
|
||||
// Environment variables
|
||||
// Example: {"DEBUG": "1"}
|
||||
env: [string]: string | dagger.#Secret
|
||||
|
||||
// Working directory for the command
|
||||
// Example: "/src"
|
||||
workdir: string
|
||||
|
||||
// Username or UID to ad
|
||||
// User identity for this command
|
||||
// Examples: "root", "0", "1002"
|
||||
user: string
|
||||
|
||||
// Output fields
|
||||
{
|
||||
// Has the command completed?
|
||||
completed: bool & (_exec.exit != _|_)
|
||||
|
||||
// Was completion successful?
|
||||
success: bool & (_exec.exit == 0)
|
||||
|
||||
// Details on error, if any
|
||||
error: {
|
||||
// Error code
|
||||
code: _exec.exit
|
||||
|
||||
// Error message
|
||||
message: string | *null
|
||||
}
|
||||
|
||||
export: {
|
||||
rootfs: dagger.#FS & _exec.output
|
||||
files: [path=string]: string
|
||||
_files: {
|
||||
for path, _ in files {
|
||||
"\(path)": {
|
||||
contents: string & _read.contents
|
||||
_read: dagger.#ReadFile & {
|
||||
input: _exec.output
|
||||
"path": path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for path, output in _files {
|
||||
files: "\(path)": output.contents
|
||||
}
|
||||
|
||||
directories: [path=string]: dagger.#FS
|
||||
_directories: {
|
||||
for path, _ in directories {
|
||||
"\(path)": {
|
||||
contents: dagger.#FS & _subdir.output
|
||||
_subdir: dagger.#Subdir & {
|
||||
input: _exec.output
|
||||
"path": path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for path, output in _directories {
|
||||
directories: "\(path)": output.contents
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For compatibility with #Build
|
||||
output: #Image & {
|
||||
rootfs: _exec.output
|
||||
config: input.config
|
||||
}
|
||||
|
||||
// Actually execute the command
|
||||
_exec: dagger.#Exec & {
|
||||
"input": input.rootfs
|
||||
"always": always
|
||||
"mounts": mounts
|
||||
|
||||
if command != _|_ {
|
||||
args: [command.name] + command._flatFlags + command.args
|
||||
}
|
||||
if command == _|_ {
|
||||
args: list.Concat([
|
||||
if input.config.entrypoint != _|_ {
|
||||
input.config.entrypoint
|
||||
},
|
||||
if input.config.cmd != _|_ {
|
||||
input.config.cmd
|
||||
},
|
||||
])
|
||||
}
|
||||
"env": env
|
||||
if input.config.env != _|_ {
|
||||
for key, val in input.config.env {
|
||||
if env[key] == _|_ {
|
||||
env: "\(key)": val
|
||||
}
|
||||
}
|
||||
}
|
||||
"workdir": workdir
|
||||
if workdir == _|_ && input.config.workdir != _|_ {
|
||||
workdir: input.config.workdir
|
||||
}
|
||||
"user": user
|
||||
if user == _|_ && input.config.user != _|_ {
|
||||
user: input.config.user
|
||||
}
|
||||
}
|
||||
|
||||
// Command exit code
|
||||
exit: _exec.exit
|
||||
}
|
||||
25
test/cue.mod/pkg/universe.dagger.io/docker/set.cue
vendored
Executable file
25
test/cue.mod/pkg/universe.dagger.io/docker/set.cue
vendored
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
// Change image config
|
||||
#Set: {
|
||||
// The source image
|
||||
input: #Image
|
||||
|
||||
// The image config to change
|
||||
config: dagger.#ImageConfig
|
||||
|
||||
_set: dagger.#Set & {
|
||||
"input": input.config
|
||||
"config": config
|
||||
}
|
||||
|
||||
// Resulting image with the config changes
|
||||
output: #Image & {
|
||||
rootfs: input.rootfs
|
||||
config: _set.output
|
||||
}
|
||||
}
|
||||
119
test/cue.mod/pkg/universe.dagger.io/docker/test/build.cue
vendored
Executable file
119
test/cue.mod/pkg/universe.dagger.io/docker/test/build.cue
vendored
Executable file
|
|
@ -0,0 +1,119 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
|
||||
"universe.dagger.io/alpine"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
actions: tests: build: {
|
||||
// Test: simple docker.#Build
|
||||
simple: {
|
||||
#testValue: "hello world"
|
||||
|
||||
image: docker.#Build & {
|
||||
steps: [
|
||||
alpine.#Build,
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n $TEST >> /test.txt"
|
||||
}
|
||||
env: TEST: #testValue
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: dagger.#ReadFile & {
|
||||
input: image.output.rootfs
|
||||
path: "/test.txt"
|
||||
}
|
||||
verify: contents: #testValue
|
||||
}
|
||||
|
||||
// Test: docker.#Build with multiple steps
|
||||
multiSteps: {
|
||||
image: docker.#Build & {
|
||||
steps: [
|
||||
alpine.#Build,
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n hello > /bar.txt"
|
||||
}
|
||||
},
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n $(cat /bar.txt) world > /foo.txt"
|
||||
}
|
||||
},
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n $(cat /foo.txt) >> /test.txt"
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: dagger.#ReadFile & {
|
||||
input: image.output.rootfs
|
||||
path: "/test.txt"
|
||||
}
|
||||
verify: contents: "hello world"
|
||||
}
|
||||
|
||||
// Test: simple nesting of docker.#Build
|
||||
nested: {
|
||||
build: docker.#Build & {
|
||||
steps: [
|
||||
docker.#Build & {
|
||||
steps: [
|
||||
docker.#Pull & {
|
||||
source: "alpine"
|
||||
},
|
||||
docker.#Run & {
|
||||
command: name: "ls"
|
||||
},
|
||||
]
|
||||
},
|
||||
docker.#Run & {
|
||||
command: name: "ls"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Test: nested docker.#Build with 3+ levels of depth
|
||||
// FIXME: this test currently fails.
|
||||
nestedDeep: {
|
||||
// build: docker.#Build & {
|
||||
// steps: [
|
||||
// docker.#Build & {
|
||||
// steps: [
|
||||
// docker.#Build & {
|
||||
// steps: [
|
||||
// docker.#Pull & {
|
||||
// source: "alpine"
|
||||
// },
|
||||
// docker.#Run & {
|
||||
// command: name: "ls"
|
||||
// },
|
||||
// ]
|
||||
// },
|
||||
// docker.#Run & {
|
||||
// command: name: "ls"
|
||||
// },
|
||||
// ]
|
||||
// },
|
||||
// docker.#Run & {
|
||||
// command: name: "ls"
|
||||
// },
|
||||
// ]
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
120
test/cue.mod/pkg/universe.dagger.io/docker/test/image.cue
vendored
Executable file
120
test/cue.mod/pkg/universe.dagger.io/docker/test/image.cue
vendored
Executable file
|
|
@ -0,0 +1,120 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
|
||||
actions: tests: image: {
|
||||
|
||||
// Test: change image config with docker.#Set
|
||||
set: {
|
||||
image: output: docker.#Image & {
|
||||
rootfs: dagger.#Scratch
|
||||
config: {
|
||||
cmd: ["/bin/sh"]
|
||||
env: PATH: "/sbin:/bin"
|
||||
onbuild: ["COPY . /app"]
|
||||
}
|
||||
}
|
||||
set: docker.#Set & {
|
||||
input: image.output
|
||||
config: {
|
||||
env: FOO: "bar"
|
||||
workdir: "/root"
|
||||
onbuild: ["RUN /app/build.sh"]
|
||||
}
|
||||
}
|
||||
verify: set.output.config & {
|
||||
env: {
|
||||
PATH: "/sbin:/bin"
|
||||
FOO: "bar"
|
||||
}
|
||||
cmd: ["/bin/sh"]
|
||||
workdir: "/root"
|
||||
onbuild: [
|
||||
"COPY . /app",
|
||||
"RUN /app/build.sh",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Test: image config behavior is correct
|
||||
config: {
|
||||
build: dagger.#Dockerfile & {
|
||||
source: dagger.#Scratch
|
||||
dockerfile: contents: """
|
||||
FROM alpine:3.15.0
|
||||
RUN echo -n 'not hello from dagger' > /dagger.txt
|
||||
RUN echo '#!/bin/sh' > /bin/dagger
|
||||
ENV HELLO_FROM=dagger
|
||||
RUN echo 'echo -n "hello from $HELLO_FROM" > /dagger.txt' >> /bin/dagger
|
||||
RUN chmod +x /bin/dagger
|
||||
WORKDIR /bin
|
||||
CMD /bin/dagger
|
||||
"""
|
||||
}
|
||||
myimage: docker.#Image & {
|
||||
rootfs: build.output
|
||||
config: build.config
|
||||
}
|
||||
run: docker.#Run & {
|
||||
input: myimage
|
||||
command: name: "ls"
|
||||
export: files: {
|
||||
"/dagger.txt": _ & {
|
||||
contents: "not hello from dagger"
|
||||
}
|
||||
"/bin/dagger": _ & {
|
||||
contents: """
|
||||
#!/bin/sh
|
||||
echo -n "hello from $HELLO_FROM" > /dagger.txt
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
verify_cmd_is_run: docker.#Run & {
|
||||
input: myimage
|
||||
export: files: "/dagger.txt": _ & {
|
||||
contents: "hello from dagger"
|
||||
}
|
||||
}
|
||||
verify_env_is_overridden: docker.#Run & {
|
||||
input: myimage
|
||||
export: files: "/dagger.txt": _ & {
|
||||
contents: "hello from europa"
|
||||
}
|
||||
env: HELLO_FROM: "europa"
|
||||
}
|
||||
|
||||
verify_working_directory: docker.#Run & {
|
||||
input: myimage
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": #"""
|
||||
pwd > dir.txt
|
||||
"""#
|
||||
}
|
||||
export: files: "/bin/dir.txt": _ & {
|
||||
contents: "/bin\n"
|
||||
}
|
||||
}
|
||||
verify_working_directory_is_overridden: docker.#Run & {
|
||||
input: myimage
|
||||
workdir: "/"
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": #"""
|
||||
pwd > dir.txt
|
||||
"""#
|
||||
}
|
||||
export: files: "/dir.txt": _ & {
|
||||
contents: "/\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
test/cue.mod/pkg/universe.dagger.io/docker/test/run.cue
vendored
Executable file
69
test/cue.mod/pkg/universe.dagger.io/docker/test/run.cue
vendored
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
|
||||
"universe.dagger.io/docker"
|
||||
"universe.dagger.io/alpine"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
actions: tests: run: {
|
||||
_build: alpine.#Build
|
||||
_image: _build.output
|
||||
|
||||
// Test: run a simple shell command
|
||||
simpleShell: {
|
||||
image: alpine.#Build
|
||||
|
||||
run: docker.#Run & {
|
||||
input: _image
|
||||
command: {
|
||||
name: "/bin/sh"
|
||||
args: ["-c", "echo -n hello world >> /output.txt"]
|
||||
}
|
||||
}
|
||||
|
||||
verify: dagger.#ReadFile & {
|
||||
input: run.output.rootfs
|
||||
path: "/output.txt"
|
||||
}
|
||||
verify: contents: "hello world"
|
||||
}
|
||||
|
||||
// Test: export a file
|
||||
exportFile: {
|
||||
run: docker.#Run & {
|
||||
input: _image
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": #"""
|
||||
echo -n hello world >> /output.txt
|
||||
"""#
|
||||
}
|
||||
export: files: "/output.txt": string & "hello world"
|
||||
}
|
||||
}
|
||||
|
||||
// Test: export a directory
|
||||
exportDirectory: {
|
||||
run: docker.#Run & {
|
||||
input: _image
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": #"""
|
||||
mkdir -p /test
|
||||
echo -n hello world >> /test/output.txt
|
||||
"""#
|
||||
}
|
||||
export: directories: "/test": _
|
||||
}
|
||||
|
||||
verify: dagger.#ReadFile & {
|
||||
input: run.export.directories."/test"
|
||||
path: "/output.txt"
|
||||
}
|
||||
verify: contents: "hello world"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
test/cue.mod/pkg/universe.dagger.io/docker/test/test.bats
vendored
Executable file
9
test/cue.mod/pkg/universe.dagger.io/docker/test/test.bats
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
setup() {
|
||||
load '../../bats_helpers'
|
||||
|
||||
common_setup
|
||||
}
|
||||
|
||||
@test "docker" {
|
||||
dagger up
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue