2021-08-13 16:43:06 +02:00
|
|
|
// ArgoCD client operations
|
|
|
|
package argocd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"alpha.dagger.io/alpine"
|
|
|
|
"alpha.dagger.io/dagger"
|
|
|
|
"alpha.dagger.io/dagger/op"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ArgoCD configuration
|
|
|
|
#Config: {
|
|
|
|
// ArgoCD CLI binary version
|
|
|
|
version: *"v2.0.5" | dagger.#Input & {string}
|
|
|
|
|
|
|
|
// ArgoCD server
|
|
|
|
server: dagger.#Input & {string}
|
|
|
|
|
|
|
|
// ArgoCD project
|
|
|
|
project: *"default" | dagger.#Input & {string}
|
|
|
|
|
2022-02-07 19:53:49 +01:00
|
|
|
// Basic authentication to login
|
2021-09-10 11:13:10 +02:00
|
|
|
basicAuth: {
|
|
|
|
// Username
|
|
|
|
username: dagger.#Input & {string}
|
2021-09-09 15:14:49 +02:00
|
|
|
|
2021-09-10 11:13:10 +02:00
|
|
|
// Password
|
|
|
|
password: dagger.#Input & {dagger.#Secret}
|
|
|
|
} | *null
|
|
|
|
|
|
|
|
// ArgoCD authentication token
|
|
|
|
token: dagger.#Input & {*null | dagger.#Secret}
|
2021-08-13 16:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Re-usable CLI component
|
|
|
|
#CLI: {
|
|
|
|
config: #Config
|
|
|
|
|
|
|
|
#up: [
|
|
|
|
op.#Load & {
|
|
|
|
from: alpine.#Image & {
|
2022-01-04 15:27:33 +01:00
|
|
|
package: bash: true
|
|
|
|
package: jq: true
|
2021-08-13 16:43:06 +02:00
|
|
|
package: curl: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Install the ArgoCD CLI
|
|
|
|
op.#Exec & {
|
|
|
|
args: ["sh", "-c",
|
|
|
|
#"""
|
|
|
|
curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64 &&
|
|
|
|
chmod +x /usr/local/bin/argocd
|
|
|
|
"""#,
|
|
|
|
]
|
|
|
|
env: VERSION: config.version
|
|
|
|
},
|
|
|
|
|
2021-09-10 11:13:10 +02:00
|
|
|
if config.basicAuth != null && config.token == null {
|
|
|
|
// Login to ArgoCD server
|
|
|
|
op.#Exec & {
|
|
|
|
args: ["sh", "-c", #"""
|
|
|
|
argocd login "$ARGO_SERVER" --username "$ARGO_USERNAME" --password $(cat /run/secrets/password) --insecure
|
|
|
|
"""#,
|
|
|
|
]
|
|
|
|
env: {
|
|
|
|
ARGO_SERVER: config.server
|
|
|
|
ARGO_USERNAME: config.basicAuth.username
|
|
|
|
}
|
|
|
|
mount: "/run/secrets/password": secret: config.basicAuth.password
|
2021-09-09 15:14:49 +02:00
|
|
|
}
|
2021-08-13 16:43:06 +02:00
|
|
|
},
|
2021-09-10 11:13:10 +02:00
|
|
|
|
|
|
|
if config.token != null && config.basicAuth == null {
|
|
|
|
// Write config file
|
|
|
|
op.#Exec & {
|
|
|
|
args: ["sh", "-c",
|
|
|
|
#"""
|
|
|
|
mkdir -p ~/.argocd && cat > ~/.argocd/config << EOF
|
|
|
|
contexts:
|
|
|
|
- name: "$SERVER"
|
|
|
|
server: "$SERVER"
|
|
|
|
user: "$SERVER"
|
|
|
|
current-context: "$SERVER"
|
|
|
|
servers:
|
|
|
|
- grpc-web-root-path: ""
|
|
|
|
server: "$SERVER"
|
|
|
|
users:
|
|
|
|
- auth-token: $(cat /run/secrets/token)
|
|
|
|
name: "$SERVER"
|
|
|
|
EOF
|
|
|
|
"""#,
|
|
|
|
]
|
|
|
|
mount: "/run/secrets/token": secret: config.token
|
|
|
|
env: SERVER: config.server
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-08-13 16:43:06 +02:00
|
|
|
]
|
|
|
|
}
|