Skip to content

Instantly share code, notes, and snippets.

@gerhard
Last active April 14, 2022 10:27
Show Gist options
  • Save gerhard/df2762691d02871dd8a71ed4574c38f3 to your computer and use it in GitHub Desktop.
Save gerhard/df2762691d02871dd8a71ed4574c38f3 to your computer and use it in GitHub Desktop.
// $ dagger do -p azure_cli_with_auth_cache.cue run --log-format=plain
// 11:10AM INF actions.run.script._write | computing
// 11:10AM INF actions.auth._dag."0"._dag."0"._op | computing
// 11:10AM INF actions.auth._dag."1".script._write | computing
// 11:10AM INF actions.run.script._write | completed duration=0s
// 11:10AM INF actions.auth._dag."1".script._write | completed duration=100ms
// 11:10AM INF actions.auth._dag."0"._dag."0"._op | completed duration=100ms
// 11:10AM INF actions.auth._dag."0"._dag."1"._exec | computing
// 11:10AM INF actions.auth._dag."0"._dag."1"._exec | completed duration=0s
// 11:10AM INF actions.auth._dag."1"._exec | computing
// 11:10AM INF actions.auth._dag."1"._exec | completed duration=200ms
// 11:10AM INF actions.run._exec | computing
// 11:10AM INF actions.auth._dag."1"._exec | #6 0.136 simulate az command that will populate /azure/config
// 11:10AM INF actions.run._exec | completed duration=200ms
// 11:10AM INF actions.run._exec | #7 0.109 read what was written to /azure/config in the auth action:
// 11:10AM INF actions.run._exec | #7 0.110 az login output
// $ dagger do -p azure_cli_with_auth_cache.cue brk --log-format=plain
// 11:26AM INF actions.brk.rover._op | computing
// 11:26AM INF actions.brk.rover._op | completed duration=600ms
// 11:26AM INF actions.brk.az_login._exec | computing
// 11:26AM INF actions.brk.az_login._exec | completed duration=100ms
// 11:26AM INF actions.brk.az_account_show._exec | computing
// 11:26AM INF actions.brk.az_account_show._exec | #4 0.073 az login --service-principal -u xxx -p xxx --tenant xxx
// 11:26AM INF actions.brk.az_account_show._exec | completed duration=100ms
package azure_cli_with_auth_cache
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
"universe.dagger.io/docker"
)
dagger.#Plan & {
_azureCache: "/root/.azure": {
dest: "/root/.azure"
type: "cache"
contents: core.#CacheDir & {
id: "azureCache"
}
}
actions: {
auth: docker.#Build & {
steps: [
alpine.#Build & {
packages: {
bash: {}
}
},
bash.#Run & {
mounts: _azureCache
script: contents: #"""
echo 'simulate az command that will populate /root/.azure'
echo 'az login output' > /root/.azure/echo
"""#
},
]
}
run: bash.#Run & {
input: auth.output
mounts: _azureCache
script: contents: #"""
echo 'read what was written to /root/.azure in the auth action:'
cat /root/.azure/echo
"""#
}
brk: {
rover: docker.#Pull & {
source: "aztfmod/rover:1.1.6-2202.2503"
}
az_login: docker.#Run & {
input: rover.image
user: "root"
command: name: "/bin/bash"
command: args: ["-c", """
echo 'az login --service-principal -u xxx -p xxx --tenant xxx' > /root/.azure/az_login
"""]
mounts: _azureCache
}
az_account_show: docker.#Run & {
input: az_login.output
user: "root"
command: name: "/bin/bash"
command: args: ["-c", """
cat /root/.azure/az_login
"""]
mounts: _azureCache
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment