From f8f39ca75b794a99783cee50aaffd4256583f735 Mon Sep 17 00:00:00 2001 From: Kevin Poirot Date: Fri, 13 Aug 2021 16:43:06 +0200 Subject: [PATCH] stdlib: argocd app support Signed-off-by: Kevin Poirot --- docs/reference/README.md | 2 + docs/reference/argocd/README.md | 45 +++++++++++ docs/reference/argocd/app.md | 72 +++++++++++++++++ stdlib/.dagger/env/argocd/.gitignore | 2 + stdlib/.dagger/env/argocd/values.yaml | 26 ++++++ stdlib/argocd/app/app.cue | 109 ++++++++++++++++++++++++++ stdlib/argocd/argocd.cue | 72 +++++++++++++++++ stdlib/argocd/tests/argocd.cue | 33 ++++++++ stdlib/universe.bats | 6 ++ 9 files changed, 367 insertions(+) create mode 100644 docs/reference/argocd/README.md create mode 100644 docs/reference/argocd/app.md create mode 100644 stdlib/.dagger/env/argocd/.gitignore create mode 100644 stdlib/.dagger/env/argocd/values.yaml create mode 100644 stdlib/argocd/app/app.cue create mode 100644 stdlib/argocd/argocd.cue create mode 100644 stdlib/argocd/tests/argocd.cue diff --git a/docs/reference/README.md b/docs/reference/README.md index 7d3223a2..11758391 100644 --- a/docs/reference/README.md +++ b/docs/reference/README.md @@ -1,6 +1,8 @@ # Index - [alpine](./alpine.md) - Base package for Alpine Linux +- [argocd](./argocd/README.md) - ArgoCD client operations +- [argocd/app](./argocd/app.md) - ArgoCD applications - [aws](./aws/README.md) - AWS base package - [aws/cloudformation](./aws/cloudformation.md) - AWS CloudFormation - [aws/ecr](./aws/ecr.md) - Amazon Elastic Container Registry (ECR) diff --git a/docs/reference/argocd/README.md b/docs/reference/argocd/README.md new file mode 100644 index 00000000..827ea983 --- /dev/null +++ b/docs/reference/argocd/README.md @@ -0,0 +1,45 @@ +--- +sidebar_label: argocd +--- + +# alpha.dagger.io/argocd + +ArgoCD client operations + +```cue +import "alpha.dagger.io/argocd" +``` + +## argocd.#CLI + +Re-usable CLI component + +### argocd.#CLI Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*config.server* | `string` |ArgoCD server | +|*config.project* | `*"default" \| string` |ArgoCD project | +|*config.token* | `dagger.#Secret` |ArgoCD authentication token | + +### argocd.#CLI Outputs + +_No output._ + +## argocd.#Config + +ArgoCD configuration + +### argocd.#Config Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*server* | `string` |ArgoCD server | +|*project* | `*"default" \| string` |ArgoCD project | +|*token* | `dagger.#Secret` |ArgoCD authentication token | + +### argocd.#Config Outputs + +_No output._ diff --git a/docs/reference/argocd/app.md b/docs/reference/argocd/app.md new file mode 100644 index 00000000..177cdee1 --- /dev/null +++ b/docs/reference/argocd/app.md @@ -0,0 +1,72 @@ +--- +sidebar_label: app +--- + +# alpha.dagger.io/argocd/app + +ArgoCD applications + +```cue +import "alpha.dagger.io/argocd/app" +``` + +## app.#Application + +Get an application + +### app.#Application Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*config.server* | `string` |ArgoCD server | +|*config.project* | `*"default" \| string` |ArgoCD project | +|*config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*name* | `string` |ArgoCD application | + +### app.#Application Outputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*outputs.health* | `string` |Application health | +|*outputs.sync* | `string` |Application sync state | +|*outputs.namespace* | `string` |Namespace | +|*outputs.server* | `string` |Server | +|*outputs.urls* | `string` |Comma separated list of application URLs | +|*outputs.state* | `string` |Last operation state message | + +## app.#Synchronization + +Sync an application to its target state + +### app.#Synchronization Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*config.server* | `string` |ArgoCD server | +|*config.project* | `*"default" \| string` |ArgoCD project | +|*config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*application* | `string` |ArgoCD application | + +### app.#Synchronization Outputs + +_No output._ + +## app.#SynchronizedApplication + +Wait for an application to reach a synced and healthy state + +### app.#SynchronizedApplication Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*config.server* | `string` |ArgoCD server | +|*config.project* | `*"default" \| string` |ArgoCD project | +|*config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*application* | `string` |ArgoCD application | + +### app.#SynchronizedApplication Outputs + +_No output._ diff --git a/stdlib/.dagger/env/argocd/.gitignore b/stdlib/.dagger/env/argocd/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/argocd/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/argocd/values.yaml b/stdlib/.dagger/env/argocd/values.yaml new file mode 100644 index 00000000..3c4aa52d --- /dev/null +++ b/stdlib/.dagger/env/argocd/values.yaml @@ -0,0 +1,26 @@ +plan: + package: ./argocd/tests +name: argocd +inputs: + TestConfig.argocdConfig.token: + secret: ENC[AES256_GCM,data:/iN8Xv5Gsr3E6NphR6+SyVLI2vvyWKED3b28,iv:ZZYKy3L5n4izaw/UM+2TaEFMlXCuBgewqY8LxS3ckuo=,tag:OeBGkvNSyO1wXHld6e0oVQ==,type:str] +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1ajcyrzr7xlhfpge6pd0zruqpggp4624hhrkslxytyvjgks5rzsrs8y95av + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBGcGVyeENBZWl6VmZ5NEVo + QTB4QjlXeS8wRnpXOFIvU294M25ieUVZR0RjCjFMbkRQdlRqYjJZNDNubVZ3d0d6 + TjNUaVJOVzBkM0pBUUswdVZLMTV1R3MKLS0tIHUzMEpjempnemsvY0dFVnZ0cThh + NFRwMyt0NUR5b1ViTlRxcnNHUTR0UXMKqpP24y8fPz5/tkx0YBGC7huylg1xIv2Q + MAjqMAk6tjZMX1va9VTTu2aaWwlZCBX6WE23gaIYuVCpbqGyp1B/WQ== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-08-13T19:52:35Z" + mac: ENC[AES256_GCM,data:gjNL1Tkf96MSABBuvr6itPh5HjfESefMF2yPyqluR73BvcIIC1zimYmy2laAVjPzxN9JmqCmZJ9v1iQ99BKB8WJ40sHlztl1f7gCcnwiBYWuV+8YfvMYhdyZrmWNlhhIt8hHMcloNR2/DnH8hIJZVjF1dNmSyIqnMv6bM5oaQhA=,iv:ZzpW6bzbzvbrH/PKLhBFRk+D70opxdl2AnvXXium204=,tag:gMAw8d2Qg2upptV0xXeQ9w==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/argocd/app/app.cue b/stdlib/argocd/app/app.cue new file mode 100644 index 00000000..2e39ad64 --- /dev/null +++ b/stdlib/argocd/app/app.cue @@ -0,0 +1,109 @@ +// ArgoCD applications +package app + +import ( + "alpha.dagger.io/argocd" + "alpha.dagger.io/dagger" + "alpha.dagger.io/dagger/op" +) + +// Get an application +#Application: { + config: argocd.#Config + + // ArgoCD application + name: dagger.#Input & {string} + + // ArgoCD CLI output + outputs: { + // Application health + health: dagger.#Output & {string} + + // Application sync state + sync: dagger.#Output & {string} + + // Namespace + namespace: dagger.#Output & {string} + + // Server + server: dagger.#Output & {string} + + // Comma separated list of application URLs + urls: dagger.#Output & {string} + + // Last operation state message + state: dagger.#Output & {string} + } + + outputs: #up: [ + op.#Load & { + from: argocd.#CLI & { + "config": config + } + }, + + op.#Exec & { + args: ["sh", "-c", + #""" + argocd app get "$APPLICATION" --output json | jq '{health:.status.health.status,sync:.status.sync.status,namespace:.spec.destination.namespace,server:.spec.destination.server,urls:.status.summary.externalURLs|join(","),state:.status.operationState.message}' > /output.json + """#, + ] + env: APPLICATION: name + }, + + op.#Export & { + source: "/output.json" + format: "json" + }, + ] +} + +// Sync an application to its target state +#Synchronization: { + config: argocd.#Config + + // ArgoCD application + application: dagger.#Input & {string} + + #up: [ + op.#Load & { + from: argocd.#CLI & { + "config": config + } + }, + + op.#Exec & { + args: [ + "sh", "-c", #""" + argocd app sync "$APPLICATION" + """#, + ] + env: APPLICATION: application + }, + ] +} + +// Wait for an application to reach a synced and healthy state +#SynchronizedApplication: { + config: argocd.#Config + + // ArgoCD application + application: dagger.#Input & {string} + + #up: [ + op.#Load & { + from: argocd.#CLI & { + "config": config + } + }, + + op.#Exec & { + args: [ + "sh", "-c", #""" + argocd app wait "$APPLICATION" + """#, + ] + env: APPLICATION: application + }, + ] +} diff --git a/stdlib/argocd/argocd.cue b/stdlib/argocd/argocd.cue new file mode 100644 index 00000000..f119929c --- /dev/null +++ b/stdlib/argocd/argocd.cue @@ -0,0 +1,72 @@ +// 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} + + // ArgoCD authentication token + token: dagger.#Secret & dagger.#Input +} + +// Re-usable CLI component +#CLI: { + config: #Config + + #up: [ + op.#Load & { + from: alpine.#Image & { + package: bash: "=~5.1" + package: jq: "=~1.6" + 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 + }, + + // Write config file + op.#Exec & { + args: ["sh", "-c", + #""" + mkdir ~/.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 + }, + ] +} diff --git a/stdlib/argocd/tests/argocd.cue b/stdlib/argocd/tests/argocd.cue new file mode 100644 index 00000000..260eb927 --- /dev/null +++ b/stdlib/argocd/tests/argocd.cue @@ -0,0 +1,33 @@ +package app + +import ( + "alpha.dagger.io/argocd" + "alpha.dagger.io/dagger" + "alpha.dagger.io/dagger/op" +) + +TestConfig: argocdConfig: argocd.#Config & { + version: "v2.0.5" + server: "dagger-example-argocd-server.tld" + token: dagger.#Secret & dagger.#Input +} + +TestArgocd: #up: [ + // Initialize ArgoCD CLI binary + op.#Load & { + from: argocd.#CLI & { + config: TestConfig.argocdConfig + } + }, + + // Check the binary and its version + op.#Exec & { + args: [ + "sh", "-c", + #""" + argocd version --output json | jq -e 'all(.client.Version; startswith("$VERSION"))' + """#, + ] + env: VERSION: TestConfig.argocdConfig.version + }, +] diff --git a/stdlib/universe.bats b/stdlib/universe.bats index b0470e94..95524a2f 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -214,3 +214,9 @@ setup() { skip "Azure CI infra not implemented yet - manually tested and working" #dagger -e azure-storage up } + + +@test "argocd" { + skip "ArgoCD CI secrets not yet generated" + #dagger -e argocd up +}