Last active
November 8, 2022 13:17
-
-
Save hongchaodeng/6e23d3f69b4674065ed1a4a41a4209ac to your computer and use it in GitHub Desktop.
dagger read/write
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"dagger.io/dagger" | |
"universe.dagger.io/alpine" | |
"universe.dagger.io/bash" | |
"universe.dagger.io/docker" | |
) | |
dagger.#Plan & { | |
client: { | |
commands: kubeconfig: { | |
name: "cat" | |
args: ["\(env.KUBECONFIG)"] | |
stdout: dagger.#Secret | |
} | |
env: KUBECONFIG: string | |
filesystem: { | |
"a.txt": write: contents: actions.up.res.contents | |
} | |
} | |
actions: { | |
up: { | |
deps: docker.#Build & { | |
steps: [ | |
alpine.#Build & { | |
packages: { | |
bash: {} | |
} | |
}, | |
] | |
} | |
run: bash.#Run & { | |
input: deps.output | |
mounts: kubeconfig: { | |
dest: "/run/secrets/kubeconfig" | |
contents: client.commands.kubeconfig.stdout | |
} | |
script: contents: #""" | |
mkdir /output | |
cat run/secrets/kubeconfig >> /output/a.txt | |
"""# | |
} | |
res: dagger.#ReadFile & { | |
input: run.output.rootfs | |
path: "/output/a.txt" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"dagger.io/dagger" | |
"universe.dagger.io/bash" | |
"universe.dagger.io/docker" | |
) | |
let GoVersion = "1.17" | |
// base image to build go binaries | |
goBuilder: _goBuilder.output | |
_goBuilder: docker.#Build & { | |
_packages: ["bash"] | |
steps: [ | |
docker.#Pull & { | |
source: "index.docker.io/golang:\(GoVersion)-alpine" | |
}, | |
for pkg in _packages { | |
docker.#Run & { | |
command: { | |
name: "apk" | |
args: ["add", pkg] | |
flags: { | |
"-U": true | |
"--no-cache": true | |
} | |
} | |
} | |
}, | |
] | |
} | |
dagger.#Plan & { | |
// You can also write to stdout: | |
// client: filesystem: "/dev/stdout": write: contents: actions.up.export.files["/output"] | |
client: filesystem: "tmp.out": write: contents: actions.up.export.files["/output"] | |
actions: up: bash.#Run & { | |
input: goBuilder | |
script: contents: #""" | |
echo haha > /output | |
"""# | |
export: files: "/output": _ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"dagger.io/dagger" | |
"universe.dagger.io/alpine" | |
"universe.dagger.io/bash" | |
"universe.dagger.io/docker" | |
) | |
dagger.#Plan & { | |
client: { | |
filesystem: { | |
output: write: contents: actions.up.deploy.res.status.contents | |
} | |
env: { | |
KUBE_CONFIG: dagger.#Secret | |
} | |
} | |
actions: { | |
deps: docker.#Build & { | |
steps: [ | |
alpine.#Build & { | |
packages: { | |
bash: {} | |
} | |
}, | |
] | |
} | |
up: { | |
init: #InitFunc & { | |
args: { | |
kubeConfig: client.env.KUBE_CONFIG | |
} | |
run: input: deps.output | |
} | |
deploy: #DeployFunc & { | |
args: { | |
account: init.res.account.contents | |
} | |
run: input: deps.output | |
} | |
} | |
} | |
} | |
#Func: { | |
args: { | |
... | |
} | |
run: { | |
... | |
} | |
res: { | |
... | |
} | |
} | |
#InitFunc: #Func & { | |
args: { | |
kubeConfig: dagger.#Secret | |
} | |
run: bash.#Run & { | |
env: KUBE_CONFIG: args.kubeConfig | |
script: contents: #""" | |
# Load input values | |
mkdir ~/.kube | |
echo $KUBE_CONFIG > ~/.kube/config | |
# Execute | |
echo install Nocalhost | |
# Output result | |
echo { "admin": "123456"} > account.json | |
mkdir /results | |
echo foo: bar > /results/res1.yaml | |
echo bar: foo > /results/res2.yaml | |
"""# | |
} | |
res: { | |
account: dagger.#ReadFile & { | |
input: run.output.rootfs | |
path: "/account.json" | |
} | |
res2: dagger.#Subdir & { | |
input: run.output.rootfs | |
path: "/results" | |
} | |
} | |
} | |
#DeployFunc: #Func & { | |
args: { | |
account: string | |
} | |
run: bash.#Run & { | |
env: ACCOUNT: args.account | |
script: contents: #""" | |
echo Do something with $ACCOUNT | |
echo success! > /res.json | |
"""# | |
} | |
res: { | |
status: dagger.#ReadFile & { | |
input: run.output.rootfs | |
path: "/res.json" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment