From f8f39ca75b794a99783cee50aaffd4256583f735 Mon Sep 17 00:00:00 2001 From: Kevin Poirot Date: Fri, 13 Aug 2021 16:43:06 +0200 Subject: [PATCH 01/13] 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 +} From 7299cb4d1d371b2a676cecdc4abb9d843999764e Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Mon, 16 Aug 2021 16:50:42 +0200 Subject: [PATCH 02/13] Update argoCD environment with CI key Signed-off-by: Tom Chauveau --- stdlib/.dagger/env/argocd/values.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stdlib/.dagger/env/argocd/values.yaml b/stdlib/.dagger/env/argocd/values.yaml index 3c4aa52d..ff0b1f80 100644 --- a/stdlib/.dagger/env/argocd/values.yaml +++ b/stdlib/.dagger/env/argocd/values.yaml @@ -3,24 +3,24 @@ plan: name: argocd inputs: TestConfig.argocdConfig.token: - secret: ENC[AES256_GCM,data:/iN8Xv5Gsr3E6NphR6+SyVLI2vvyWKED3b28,iv:ZZYKy3L5n4izaw/UM+2TaEFMlXCuBgewqY8LxS3ckuo=,tag:OeBGkvNSyO1wXHld6e0oVQ==,type:str] + secret: ENC[AES256_GCM,data:N7hA,iv:7gqCkackbGFXXBmTI+7eKq5OWSWttOt33vr9IwvN6wQ=,tag:yoBj8vEQv3b9lQJg2Ht51w==,type:str] sops: kms: [] gcp_kms: [] azure_kv: [] hc_vault: [] age: - - recipient: age1ajcyrzr7xlhfpge6pd0zruqpggp4624hhrkslxytyvjgks5rzsrs8y95av + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk enc: | -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBGcGVyeENBZWl6VmZ5NEVo - QTB4QjlXeS8wRnpXOFIvU294M25ieUVZR0RjCjFMbkRQdlRqYjJZNDNubVZ3d0d6 - TjNUaVJOVzBkM0pBUUswdVZLMTV1R3MKLS0tIHUzMEpjempnemsvY0dFVnZ0cThh - NFRwMyt0NUR5b1ViTlRxcnNHUTR0UXMKqpP24y8fPz5/tkx0YBGC7huylg1xIv2Q - MAjqMAk6tjZMX1va9VTTu2aaWwlZCBX6WE23gaIYuVCpbqGyp1B/WQ== + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBuV3FTdWpWRjUxSS9hcVU4 + T094TC9GRkcxQThPMVI3NzVCb2d3Q2cvUFRvClVHT1J6OFRVY1ZTYWQ2eDZmWXN3 + N1VjdC9WNnlBNzRIdFVBN0E4Zm0xUzAKLS0tIEc2VFFSYmRqYUI5VDBDRGtTK2k1 + WG5JdHlKYUlnZnZlMVNIRjczSld5ek0KF0z0UqtoGcYFFeOyMwIDAY1pyKosaOii + IVqsMSYfj4+vz7mRd8HoXoSiSnuc7mLJek/izsdZtYUTfD/QnTC71Q== -----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] + lastmodified: "2021-08-16T14:41:25Z" + mac: ENC[AES256_GCM,data:IGmsWqxTDcWRjAgGQbQ5s5Ip1FrTj3ncqpWpdW/HXYp2DqA1SMQ1aH3whJ9JcxlBALWzc0jI4LXuPS+wxy5zrSC/Syp6bt3hYyo7DRsPMpPozm2q26hbGFPDAEXRF5K1+ZHRQ+DnuKecQJuQVz4UNZQg1HTsebnDgZ+D9OHMaek=,iv:AFWorUNhkwxR6R7ilttnJHuWeohsgHsc6NIZPtM3nr4=,tag:kXrm1i09+bvuFAaZqFvNKA==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 From f038e11fc578dab91d29fb30c1272be10abf7da6 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Mon, 16 Aug 2021 16:51:05 +0200 Subject: [PATCH 03/13] Update argoCD test file to use `os.#Container` Signed-off-by: Tom Chauveau --- stdlib/argocd/tests/argocd.cue | 31 +++++++++++-------------------- stdlib/universe.bats | 4 ++-- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/stdlib/argocd/tests/argocd.cue b/stdlib/argocd/tests/argocd.cue index 260eb927..1af27a3f 100644 --- a/stdlib/argocd/tests/argocd.cue +++ b/stdlib/argocd/tests/argocd.cue @@ -3,7 +3,7 @@ package app import ( "alpha.dagger.io/argocd" "alpha.dagger.io/dagger" - "alpha.dagger.io/dagger/op" + "alpha.dagger.io/os" ) TestConfig: argocdConfig: argocd.#Config & { @@ -12,22 +12,13 @@ TestConfig: argocdConfig: argocd.#Config & { 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 - }, -] +TestArgoCD2: os.#Container & { + image: argocd.#CLI & { + config: TestConfig.argocdConfig + } + always: true + command: #""" + 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 95524a2f..f8cb4861 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -76,7 +76,7 @@ setup() { } @test "docker run: local" { - skip "Not implemented yet + missing inputs leading to failure" + skip "Not implemented yet + missing inputs leading to failure" # dagger -e docker-run-local up } @@ -217,6 +217,6 @@ setup() { @test "argocd" { - skip "ArgoCD CI secrets not yet generated" + skip "ArgoCD CI secrets not yet generated - Infra not implemented yet" #dagger -e argocd up } From b136cdcaaf24e664c75dd4fa429399e9d72ab5fa Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 9 Sep 2021 13:00:23 +0200 Subject: [PATCH 04/13] Split definition into files and add #App to create argocd project Signed-off-by: Tom Chauveau --- stdlib/argocd/app.cue | 47 +++++++++++++++ stdlib/argocd/{app/app.cue => status.cue} | 70 ++++------------------- stdlib/argocd/sync.cue | 35 ++++++++++++ 3 files changed, 94 insertions(+), 58 deletions(-) create mode 100644 stdlib/argocd/app.cue rename stdlib/argocd/{app/app.cue => status.cue} (52%) create mode 100644 stdlib/argocd/sync.cue diff --git a/stdlib/argocd/app.cue b/stdlib/argocd/app.cue new file mode 100644 index 00000000..42e2e09c --- /dev/null +++ b/stdlib/argocd/app.cue @@ -0,0 +1,47 @@ +package argocd + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/os" +) + +// Create an ArgoCD application +#App: { + // ArgoCD configuration + config: #Config + + // App name + name: dagger.#Input & {string} + + // Repository url (git or helm) + repo: dagger.#Input & {string} + + // Folder to deploy + path: dagger.#Input & {"." | string} + + // Destination server + server: dagger.#Input & {*"https://kubernetes.default.svc" | string} + + // Destination namespace + namespace: dagger.#Input & {*"default" | string} + + _ctr: os.Container & { + from: #CLI & { + "config": config + } + command: #""" + argocd app create "$APP_NAME" \ + --repo "$APP_REPO" \ + --path "$APP_PATH" \ + --dest-server "$APP_SERVER" \ + --dest-namespace "$APP_NAMESPACE" + """# + env: { + APP_NAME: name + APP_REPO: repo + APP_PATH: path + APP_SERVER: server + APP_NAMESPACE: namespace + } + } +} diff --git a/stdlib/argocd/app/app.cue b/stdlib/argocd/status.cue similarity index 52% rename from stdlib/argocd/app/app.cue rename to stdlib/argocd/status.cue index 2e39ad64..9900b6d7 100644 --- a/stdlib/argocd/app/app.cue +++ b/stdlib/argocd/status.cue @@ -1,15 +1,14 @@ -// ArgoCD applications -package app +package argocd import ( - "alpha.dagger.io/argocd" "alpha.dagger.io/dagger" "alpha.dagger.io/dagger/op" ) -// Get an application -#Application: { - config: argocd.#Config +// Get application's status +#Status: { + // ArgoCD configuration + config: #Config // ArgoCD application name: dagger.#Input & {string} @@ -37,7 +36,7 @@ import ( outputs: #up: [ op.#Load & { - from: argocd.#CLI & { + from: #CLI & { "config": config } }, @@ -45,10 +44,15 @@ import ( op.#Exec & { args: ["sh", "-c", #""" + ls ~/.argocd + cat ~/.argocd/config 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 + env: { + APPLICATION: name + ARGOCD_OPTS: "--port-forward-namespace argocd" + } }, op.#Export & { @@ -57,53 +61,3 @@ import ( }, ] } - -// 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/sync.cue b/stdlib/argocd/sync.cue new file mode 100644 index 00000000..d6d3d2df --- /dev/null +++ b/stdlib/argocd/sync.cue @@ -0,0 +1,35 @@ +package argocd + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/os" +) + +// Sync an application to its targer state +#Sync: { + // ArgoCD configuration + config: #Config + + // ArgoCD application + application: dagger.#Input & {string} + + // Wait the application to sync correctly + wait: dagger.#Input & {*false | bool} + + _ctr: os.#Container & { + image: #CLI & { + "config": config + } + command: #""" + argocd app sync "$APPLICATION" + + if [ -n "$WAIT_FLAG" ]; then + argocd app wait "$APPLICATION" + fi + """# + env: APPLICATION: application + if wait { + env: WAIT_FLAG: "wait" + } + } +} From 9337eed2bb5b09c9b00fc40e893ec6de31b43b73 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 9 Sep 2021 13:01:50 +0200 Subject: [PATCH 05/13] Update argocd documentation Signed-off-by: Tom Chauveau --- docs/reference/README.md | 3 +- docs/reference/argocd.md | 111 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 docs/reference/argocd.md diff --git a/docs/reference/README.md b/docs/reference/README.md index 11758391..734ab675 100644 --- a/docs/reference/README.md +++ b/docs/reference/README.md @@ -1,8 +1,7 @@ # Index - [alpine](./alpine.md) - Base package for Alpine Linux -- [argocd](./argocd/README.md) - ArgoCD client operations -- [argocd/app](./argocd/app.md) - ArgoCD applications +- [argocd](./argocd.md) - ArgoCD client operations - [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.md b/docs/reference/argocd.md new file mode 100644 index 00000000..4ebc5a03 --- /dev/null +++ b/docs/reference/argocd.md @@ -0,0 +1,111 @@ +--- +sidebar_label: argocd +--- + +# alpha.dagger.io/argocd + +ArgoCD client operations + +```cue +import "alpha.dagger.io/argocd" +``` + +## argocd.#App + +Create an ArgoCD application + +### argocd.#App 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` |App name | +|*repo* | `string` |Repository url (git or helm) | +|*path* | `string` |Folder to deploy | +|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server | +|*namespace* | `*"default" \| string` |Destination namespace | + +### argocd.#App Outputs + +_No output._ + +## 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._ + +## argocd.#Status + +Get application's status + +### argocd.#Status 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 | + +### argocd.#Status 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 | + +## argocd.#Sync + +Sync an application to its targer state + +### argocd.#Sync 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 | +|*wait* | `*false \| bool` |Wait the application to sync correctly | + +### argocd.#Sync Outputs + +_No output._ From a73b34d096daa41961a418008648dbd17f4e03f8 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 9 Sep 2021 13:02:34 +0200 Subject: [PATCH 06/13] Add argocd-infra deployment to deploy it to a cluster Signed-off-by: Tom Chauveau --- stdlib/.dagger/env/argocd-infra/.gitignore | 2 ++ stdlib/.dagger/env/argocd-infra/values.yaml | 23 +++++++++++++++++++++ stdlib/argocd/tests/infra/infra.cue | 14 +++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 stdlib/.dagger/env/argocd-infra/.gitignore create mode 100644 stdlib/.dagger/env/argocd-infra/values.yaml create mode 100644 stdlib/argocd/tests/infra/infra.cue diff --git a/stdlib/.dagger/env/argocd-infra/.gitignore b/stdlib/.dagger/env/argocd-infra/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/argocd-infra/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/argocd-infra/values.yaml b/stdlib/.dagger/env/argocd-infra/values.yaml new file mode 100644 index 00000000..c9d4ef55 --- /dev/null +++ b/stdlib/.dagger/env/argocd-infra/values.yaml @@ -0,0 +1,23 @@ +plan: + package: ./argocd/tests/infra +name: argocd-infra +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBmVmEzZ3RDdjlBRXBleURr + cmx6YW40ZHFLMHpqa2RYWUlIdTFIZlYyZ3pnCmVieTB2MXdid1l5ZitUMkprVGFz + RHl4elJzdWRTYS9MaXZkU29UMG1SSmcKLS0tIHFjNHhBVVVwcGwrVWZHOXoxdGps + RWlubERCTjFkSStyQXdpbSttbXB1RmcKQeRMIc8QGKI8HkoBXCQzR/gaBoiYTYxy + vLjf1kMlX4BvmwTpmDO9Wer8a/NXEwA3zpK/kHaoXGBZln8Lf4J87A== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-09-09T10:52:18Z" + mac: ENC[AES256_GCM,data:B5CZFBYviKy/l8YYzg3luUdeFpRTGx5q+Q5b56SvIVvdp33TQwvU6bftiNOwUHjI3a3B2p70QNKxam+Yk7Pf9jC1nN6dR1jWh0RcicTjQOI6URN6NgS667/iCG7e94fKiVKlbgRq/P7eudnJrkhPsiqqHopmWg41g+izH+YOX2I=,iv:X6nxvaEdtnyUSEPODJLrPfuju906b9EYsye4MstBGRc=,tag:olbgC+EtQ8U8FJejQv5u/Q==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/argocd/tests/infra/infra.cue b/stdlib/argocd/tests/infra/infra.cue new file mode 100644 index 00000000..30ca30b5 --- /dev/null +++ b/stdlib/argocd/tests/infra/infra.cue @@ -0,0 +1,14 @@ +package infra + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/kubernetes" +) + +TestKubeconfig: dagger.#Input & {string} + +TestArgoInfra: kubernetes.#Resources & { + kubeconfig: TestKubeconfig + namespace: "argocd" + url: "https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml" +} From 2a91ae1d8094479ebc10568a49974855267972f2 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 9 Sep 2021 13:03:07 +0200 Subject: [PATCH 07/13] Update argoCD test Signed-off-by: Tom Chauveau --- .github/workflows/ci.yml | 21 ++- stdlib/.dagger/env/argocd/values.yaml | 8 +- stdlib/argocd/tests/argocd.cue | 20 +-- stdlib/helpers.bash | 11 ++ stdlib/universe.bats | 181 ++++++++++++++------------ 5 files changed, 143 insertions(+), 98 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84b6677b..ae8a54d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -141,16 +141,27 @@ jobs: run: | mkdir -p ~/.config/dagger echo "$DAGGER_AGE_KEY" > ~/.config/dagger/keys.txt - + - name: Provision Localstack AWS resources env: - AWS_ACCESS_KEY_ID: test - AWS_SECRET_ACCESS_KEY: test - AWS_DEFAULT_REGION: us-east-2 + AWS_ACCESS_KEY_ID: test + AWS_SECRET_ACCESS_KEY: test + AWS_DEFAULT_REGION: us-east-2 run: | aws --endpoint-url=http://localhost:4566 s3 mb s3://dagger-ci aws --endpoint-url=http://localhost:4566 ecr create-repository --repository-name dagger-ci - + + - name: Setup ArgoCD infra + run: | + make install + dagger -w universe -e argocd-infra input text TestKubeconfig -f "$HOME"/.kube/config + dagger -w universe -e dagger-infra up + + # Expose Argo API + kubectl port-forward svc/argocd-server -n argocd 8080:443 & + curl localhost:8080 + continue-on-error: true + - name: Universe Test run: | make universe-test diff --git a/stdlib/.dagger/env/argocd/values.yaml b/stdlib/.dagger/env/argocd/values.yaml index ff0b1f80..2fa22e0d 100644 --- a/stdlib/.dagger/env/argocd/values.yaml +++ b/stdlib/.dagger/env/argocd/values.yaml @@ -2,8 +2,10 @@ plan: package: ./argocd/tests name: argocd inputs: + TestConfig.argocdConfig.server: + text: localhost:8080 TestConfig.argocdConfig.token: - secret: ENC[AES256_GCM,data:N7hA,iv:7gqCkackbGFXXBmTI+7eKq5OWSWttOt33vr9IwvN6wQ=,tag:yoBj8vEQv3b9lQJg2Ht51w==,type:str] + secret: ENC[AES256_GCM,data:TC8wCWyJ+yTkAQXBLLioVDUm4YfkMMgHEzcxyRBr/uwOErEYAWDE539dahcPclQYW/Ds7UVQIv+PMS+43zXSqIv5lde842IhOEIZwemCGnWrGy2yBC566WCYPxU16k76MzslwhJrYGDi4GF4zlIyvtVO6AbviumZqGT+wAq4/Z6KZ2CQTDWNf42ise2orGNsBTj7jqpazLO34A+Wt9USW/cJrSqU+BtAjGkoLZW65iGJ8ui8RdADxw5/A0rkdJaoN4mnSUi7yARpcmTdQBdo33385csTxxqy8oWw7OR4itUfzzWKbOprQph/EeEtxMtPAuHOB/9As/6dvIGcynwxPjw=,iv:xAb0eF1lCmNoaE9Tzfnq2uLB647DK2Cat2BZTPn272s=,tag:D2mfkvEAzVi34y7WYSg7JQ==,type:str] sops: kms: [] gcp_kms: [] @@ -19,8 +21,8 @@ sops: WG5JdHlKYUlnZnZlMVNIRjczSld5ek0KF0z0UqtoGcYFFeOyMwIDAY1pyKosaOii IVqsMSYfj4+vz7mRd8HoXoSiSnuc7mLJek/izsdZtYUTfD/QnTC71Q== -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-08-16T14:41:25Z" - mac: ENC[AES256_GCM,data:IGmsWqxTDcWRjAgGQbQ5s5Ip1FrTj3ncqpWpdW/HXYp2DqA1SMQ1aH3whJ9JcxlBALWzc0jI4LXuPS+wxy5zrSC/Syp6bt3hYyo7DRsPMpPozm2q26hbGFPDAEXRF5K1+ZHRQ+DnuKecQJuQVz4UNZQg1HTsebnDgZ+D9OHMaek=,iv:AFWorUNhkwxR6R7ilttnJHuWeohsgHsc6NIZPtM3nr4=,tag:kXrm1i09+bvuFAaZqFvNKA==,type:str] + lastmodified: "2021-09-09T09:31:30Z" + mac: ENC[AES256_GCM,data:khUMYQdGj8qwNd7TZa2TPJIeOD9WjOn6LpNhqnZ2VZPOHWzre56MSytBS65h2bqgB5ljaYOM8qR8qc6UzSFhcNOBaAKofOYfuD1Zy6BcjNzNbJ9wvQE9qvT5o25VHsLk+fNhJt04wNdGdWjPuJNJrTTGLj82CXKCUPGyxvV72Pg=,iv:ut+MuwUELE+xu+I1G6NmqFrxu39++2pr96SHShQ5scI=,tag:5Fa6WPRo7R9UN5L7ankYzA==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 diff --git a/stdlib/argocd/tests/argocd.cue b/stdlib/argocd/tests/argocd.cue index 1af27a3f..2d45be68 100644 --- a/stdlib/argocd/tests/argocd.cue +++ b/stdlib/argocd/tests/argocd.cue @@ -1,19 +1,18 @@ -package app +package argocd import ( - "alpha.dagger.io/argocd" "alpha.dagger.io/dagger" "alpha.dagger.io/os" ) -TestConfig: argocdConfig: argocd.#Config & { - version: "v2.0.5" - server: "dagger-example-argocd-server.tld" - token: dagger.#Secret & dagger.#Input +TestConfig: argocdConfig: #Config & { + version: dagger.#Input & {*"v2.0.5" | string} + server: dagger.#Input & {*"dagger-example-argocd-server.tld" | string} + token: dagger.#Input & {dagger.#Secret} } -TestArgoCD2: os.#Container & { - image: argocd.#CLI & { +TestArgoCD: os.#Container & { + image: #CLI & { config: TestConfig.argocdConfig } always: true @@ -22,3 +21,8 @@ TestArgoCD2: os.#Container & { """# env: VERSION: TestConfig.argocdConfig.version } + +TestArgoCDStatus: #Status & { + config: TestConfig.argocdConfig + name: "test" +} diff --git a/stdlib/helpers.bash b/stdlib/helpers.bash index e61da042..dbea6b8b 100644 --- a/stdlib/helpers.bash +++ b/stdlib/helpers.bash @@ -81,6 +81,17 @@ skip_unless_local_kube() { fi } +# Check if there is a local endpoint. +# +# This is necessary to do test with endpoint. +# Usage: +# skip_unless_endpoint_available "localhost:8080" +skip_unless_endpoint_available() { + local endpoint="$1" + + curl "$endpoint" +} + # Cleanup local Localstack instances setup_localstack() { if [ "$(curl -s http://localhost:4566)" = '{"status": "running"}' ] && \ diff --git a/stdlib/universe.bats b/stdlib/universe.bats index f8cb4861..e741ec79 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -1,87 +1,87 @@ # Instead of setup, this runs only once setup_file() { - load 'helpers' + load 'helpers' - setup_localstack + setup_localstack } setup() { - load 'helpers' + load 'helpers' - common_setup + common_setup } @test "cue-sanity-check" { - dagger -e sanity-check up + dagger -e sanity-check up } @test "os" { - dagger -e os up + dagger -e os up } @test "go" { - dagger -e go up + dagger -e go up } @test "js/yarn" { - dagger -e js-yarn up + dagger -e js-yarn up } @test "java/maven" { - dagger -e java-maven up + dagger -e java-maven up } @test "alpine" { - dagger -e alpine up + dagger -e alpine up } @test "netlify" { - dagger -e netlify up + dagger -e netlify up } @test "git" { - # Fetch repo - dagger -e git-repo up + # Fetch repo + dagger -e git-repo up - # Commit & push - dagger -e git-commit up + # Commit & push + dagger -e git-commit up } @test "os.#Container" { - dagger -e os-container up + dagger -e os-container up } @test "aws: ecr" { - dagger -e aws-ecr up + dagger -e aws-ecr up } @test "aws: ecr/localstack" { - skip_unless_local_localstack + skip_unless_local_localstack - dagger -e aws-ecr-localstack up + dagger -e aws-ecr-localstack up } @test "aws: s3" { - dagger -e aws-s3 up + dagger -e aws-s3 up } @test "aws: s3/localstack" { - skip_unless_local_localstack + skip_unless_local_localstack - dagger -e aws-s3-localstack up + dagger -e aws-s3-localstack up } @test "aws: eks" { - dagger -e aws-eks up + dagger -e aws-eks up } @test "docker run: local" { - skip "Not implemented yet + missing inputs leading to failure" - # dagger -e docker-run-local up + skip "Not implemented yet + missing inputs leading to failure" + # dagger -e docker-run-local up } @test "docker build" { - dagger -e docker-build up + dagger -e docker-build up } @test "docker push and pull" { @@ -96,7 +96,7 @@ setup() { } @test "docker push: multi registry" { - run dagger -e docker-push-multi-registry up + run dagger -e docker-push-multi-registry up } @test "docker push: invalid credential" { @@ -106,117 +106,134 @@ setup() { } @test "docker command: ssh" { - dagger -e docker-command-ssh up + dagger -e docker-command-ssh up } @test "docker command: ssh with key passphrase" { - dagger -e docker-command-ssh-key-passphrase up + dagger -e docker-command-ssh-key-passphrase up } @test "docker command: ssh with wrong key passphrase" { - run dagger -e docker-command-ssh-wrong-key-passphrase up - assert_failure + run dagger -e docker-command-ssh-wrong-key-passphrase up + assert_failure } @test "docker compose" { - dagger -e docker-compose up + dagger -e docker-compose up } @test "docker run: ssh" { - dagger -e docker-run-ssh up + dagger -e docker-run-ssh up } @test "kubernetes: deployment" { - skip_unless_local_kube + skip_unless_local_kube - # Copy deployment to sandbox - copy_to_sandbox kubernetes-deployment kubernetes + # Copy deployment to sandbox + copy_to_sandbox kubernetes-deployment kubernetes - # Set kubeconfig - dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment input text TestKubeconfig -f "$HOME"/.kube/config + # Set kubeconfig + dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment input text TestKubeconfig -f "$HOME"/.kube/config - dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment up + dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment up - # Unset kubeconfig - dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment input unset TestKubeconfig + # Unset kubeconfig + dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment input unset TestKubeconfig } @test "kubernetes: kustomize" { - dagger -e kubernetes-kustomize up + dagger -e kubernetes-kustomize up } @test "kubernetes: helm" { - skip_unless_local_kube + skip_unless_local_kube - # Copy deployment to sandbox - copy_to_sandbox kubernetes-helm kubernetes + # Copy deployment to sandbox + copy_to_sandbox kubernetes-helm kubernetes - # Set kubeconfig - dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm input text TestKubeconfig -f "$HOME"/.kube/config + # Set kubeconfig + dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm input text TestKubeconfig -f "$HOME"/.kube/config - dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm up + dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm up - # Unset kubeconfig - dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm input unset TestKubeconfig + # Unset kubeconfig + dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm input unset TestKubeconfig } @test "google cloud: gcr" { - dagger -e google-gcr up + dagger -e google-gcr up } @test "google cloud: gcs" { - dagger -e google-gcs up + dagger -e google-gcs up } @test "google cloud: gke" { - dagger -e google-gke up + dagger -e google-gke up } @test "google cloud: cloudrun" { - dagger -e google-cloudrun up + dagger -e google-cloudrun up } @test "terraform" { - # it must fail because of a missing var - run dagger -e terraform up - assert_failure + # it must fail because of a missing var + run dagger -e terraform up + assert_failure - # Copy deployment to sandbox - copy_to_sandbox terraform terraform + # Copy deployment to sandbox + copy_to_sandbox terraform terraform - # Add the var and try again - run dagger -w "$DAGGER_SANDBOX" -e terraform input text TestTerraform.apply.tfvars.input "42" - run dagger -w "$DAGGER_SANDBOX" -e terraform up - assert_success + # Add the var and try again + run dagger -w "$DAGGER_SANDBOX" -e terraform input text TestTerraform.apply.tfvars.input "42" + run dagger -w "$DAGGER_SANDBOX" -e terraform up + assert_success - # ensure the tfvar was passed correctly - run dagger -w "$DAGGER_SANDBOX" query -e terraform TestTerraform.apply.output.input.value -f text - assert_success - assert_output "42" + # ensure the tfvar was passed correctly + run dagger -w "$DAGGER_SANDBOX" query -e terraform TestTerraform.apply.output.input.value -f text + assert_success + assert_output "42" - # ensure the random value is always the same - # this proves we're effectively using the s3 backend - run dagger -w "$DAGGER_SANDBOX" query -e terraform TestTerraform.apply.output.random.value -f json - assert_success - assert_output "36" + # ensure the random value is always the same + # this proves we're effectively using the s3 backend + run dagger -w "$DAGGER_SANDBOX" query -e terraform TestTerraform.apply.output.random.value -f json + assert_success + assert_output "36" - # Unset input - run dagger -w "$DAGGER_SANDBOX" -e terraform input unset TestTerraform.apply.tfvars.input - assert_success + # Unset input + run dagger -w "$DAGGER_SANDBOX" -e terraform input unset TestTerraform.apply.tfvars.input + assert_success } @test "azure-resourcegroup" { - skip "Azure CI infra not implemented yet - manually tested and working" - #dagger -e azure-resourcegroup up + skip "Azure CI infra not implemented yet - manually tested and working" + #dagger -e azure-resourcegroup up } @test "azure-storage" { - skip "Azure CI infra not implemented yet - manually tested and working" - #dagger -e azure-storage up + 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 - Infra not implemented yet" - #dagger -e argocd up + skip_unless_local_kube + + # Deploy argoCD infra + # dagger -e argocd-infra input text TestKubeconfig -f "$HOME"/.kube/config + #dagger -e argocd-infra up + # pid=$! + + curl localhost:8080 + + # Kill Pid + #check_pid=$(pgrep "$pid") + #if [ "$pid" -eq "$check_pid" ]; then + # kill "$pid" + #fi + # skip "ArgoCD CI secrets not yet generated - Infra not implemented yet" + # dagger -e argocd input secret TestConfig.argocdConfig.token "$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo)" + # dagger -e argocd up + + # Kill forward + # >&2 echo "kill pid" } From 0fe8b14e78fa63bc10a07ee10c4336ba762ef956 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 9 Sep 2021 15:14:49 +0200 Subject: [PATCH 08/13] Improve ArgoCD and fix CI Signed-off-by: Tom Chauveau --- .github/workflows/ci.yml | 11 --------- stdlib/.dagger/env/argocd/values.yaml | 6 ++--- stdlib/argocd/app.cue | 4 +-- stdlib/argocd/argocd.cue | 35 +++++++++++---------------- stdlib/argocd/status.cue | 4 +-- stdlib/argocd/sync.cue | 2 +- stdlib/argocd/tests/argocd.cue | 25 ++++++++++++------- stdlib/universe.bats | 25 +++++++++---------- 8 files changed, 48 insertions(+), 64 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae8a54d3..632769f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -151,17 +151,6 @@ jobs: aws --endpoint-url=http://localhost:4566 s3 mb s3://dagger-ci aws --endpoint-url=http://localhost:4566 ecr create-repository --repository-name dagger-ci - - name: Setup ArgoCD infra - run: | - make install - dagger -w universe -e argocd-infra input text TestKubeconfig -f "$HOME"/.kube/config - dagger -w universe -e dagger-infra up - - # Expose Argo API - kubectl port-forward svc/argocd-server -n argocd 8080:443 & - curl localhost:8080 - continue-on-error: true - - name: Universe Test run: | make universe-test diff --git a/stdlib/.dagger/env/argocd/values.yaml b/stdlib/.dagger/env/argocd/values.yaml index 2fa22e0d..90edff9b 100644 --- a/stdlib/.dagger/env/argocd/values.yaml +++ b/stdlib/.dagger/env/argocd/values.yaml @@ -4,8 +4,6 @@ name: argocd inputs: TestConfig.argocdConfig.server: text: localhost:8080 - TestConfig.argocdConfig.token: - secret: ENC[AES256_GCM,data:TC8wCWyJ+yTkAQXBLLioVDUm4YfkMMgHEzcxyRBr/uwOErEYAWDE539dahcPclQYW/Ds7UVQIv+PMS+43zXSqIv5lde842IhOEIZwemCGnWrGy2yBC566WCYPxU16k76MzslwhJrYGDi4GF4zlIyvtVO6AbviumZqGT+wAq4/Z6KZ2CQTDWNf42ise2orGNsBTj7jqpazLO34A+Wt9USW/cJrSqU+BtAjGkoLZW65iGJ8ui8RdADxw5/A0rkdJaoN4mnSUi7yARpcmTdQBdo33385csTxxqy8oWw7OR4itUfzzWKbOprQph/EeEtxMtPAuHOB/9As/6dvIGcynwxPjw=,iv:xAb0eF1lCmNoaE9Tzfnq2uLB647DK2Cat2BZTPn272s=,tag:D2mfkvEAzVi34y7WYSg7JQ==,type:str] sops: kms: [] gcp_kms: [] @@ -21,8 +19,8 @@ sops: WG5JdHlKYUlnZnZlMVNIRjczSld5ek0KF0z0UqtoGcYFFeOyMwIDAY1pyKosaOii IVqsMSYfj4+vz7mRd8HoXoSiSnuc7mLJek/izsdZtYUTfD/QnTC71Q== -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-09-09T09:31:30Z" - mac: ENC[AES256_GCM,data:khUMYQdGj8qwNd7TZa2TPJIeOD9WjOn6LpNhqnZ2VZPOHWzre56MSytBS65h2bqgB5ljaYOM8qR8qc6UzSFhcNOBaAKofOYfuD1Zy6BcjNzNbJ9wvQE9qvT5o25VHsLk+fNhJt04wNdGdWjPuJNJrTTGLj82CXKCUPGyxvV72Pg=,iv:ut+MuwUELE+xu+I1G6NmqFrxu39++2pr96SHShQ5scI=,tag:5Fa6WPRo7R9UN5L7ankYzA==,type:str] + lastmodified: "2021-09-09T12:42:58Z" + mac: ENC[AES256_GCM,data:CMNfY3kBAbDOkyh1s3csD7uGToV/5TubN/0z3NaG0rVOeHzgPx//PUw7jfhBe3iTCe5m7z5jpGwbI9h6+GoANrsPX887/XYvC22JLQ7vqfOqJYOrYY9YbEJnYK+GXthQB7bqn5Yh2+yiNRVk9vHJkXyhqea9/ud32kiKhG2tE3o=,iv:eT3sjgmh4NF1sS+MSsOEZbgvAiWOwep72aM2fDenG0s=,tag:HcKVlnDpn6kQxFdlKSCALg==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 diff --git a/stdlib/argocd/app.cue b/stdlib/argocd/app.cue index 42e2e09c..94f60290 100644 --- a/stdlib/argocd/app.cue +++ b/stdlib/argocd/app.cue @@ -25,8 +25,8 @@ import ( // Destination namespace namespace: dagger.#Input & {*"default" | string} - _ctr: os.Container & { - from: #CLI & { + ctr: os.#Container & { + image: #CLI & { "config": config } command: #""" diff --git a/stdlib/argocd/argocd.cue b/stdlib/argocd/argocd.cue index f119929c..75648379 100644 --- a/stdlib/argocd/argocd.cue +++ b/stdlib/argocd/argocd.cue @@ -18,8 +18,11 @@ import ( // ArgoCD project project: *"default" | dagger.#Input & {string} - // ArgoCD authentication token - token: dagger.#Secret & dagger.#Input + // Username + username: dagger.#Input & {string} + + // Password + password: dagger.#Input & {dagger.#Secret} } // Re-usable CLI component @@ -46,27 +49,17 @@ import ( env: VERSION: config.version }, - // Write config file + // Login to ArgoCD server 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 - """#, + args: ["sh", "-c", #""" + argocd login "$ARGO_SERVER" --username "$ARGO_USERNAME" --password $(cat /run/secrets/password) --insecure + """#, ] - mount: "/run/secrets/token": secret: config.token - env: SERVER: config.server + env: { + ARGO_SERVER: config.server + ARGO_USERNAME: config.username + } + mount: "/run/secrets/password": secret: config.password }, ] } diff --git a/stdlib/argocd/status.cue b/stdlib/argocd/status.cue index 9900b6d7..017f7b4d 100644 --- a/stdlib/argocd/status.cue +++ b/stdlib/argocd/status.cue @@ -44,14 +44,12 @@ import ( op.#Exec & { args: ["sh", "-c", #""" - ls ~/.argocd - cat ~/.argocd/config + // FIXME JQ failed 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 - ARGOCD_OPTS: "--port-forward-namespace argocd" } }, diff --git a/stdlib/argocd/sync.cue b/stdlib/argocd/sync.cue index d6d3d2df..72186aff 100644 --- a/stdlib/argocd/sync.cue +++ b/stdlib/argocd/sync.cue @@ -16,7 +16,7 @@ import ( // Wait the application to sync correctly wait: dagger.#Input & {*false | bool} - _ctr: os.#Container & { + ctr: os.#Container & { image: #CLI & { "config": config } diff --git a/stdlib/argocd/tests/argocd.cue b/stdlib/argocd/tests/argocd.cue index 2d45be68..dde89457 100644 --- a/stdlib/argocd/tests/argocd.cue +++ b/stdlib/argocd/tests/argocd.cue @@ -6,23 +6,30 @@ import ( ) TestConfig: argocdConfig: #Config & { - version: dagger.#Input & {*"v2.0.5" | string} - server: dagger.#Input & {*"dagger-example-argocd-server.tld" | string} - token: dagger.#Input & {dagger.#Secret} + version: dagger.#Input & {*"v2.0.5" | string} + server: dagger.#Input & {*"dagger-example-argocd-server.tld" | string} + username: dagger.#Input & {*"admin" | string} + password: dagger.#Input & {dagger.#Secret} } -TestArgoCD: os.#Container & { +TestClient: os.#Container & { image: #CLI & { config: TestConfig.argocdConfig } - always: true command: #""" - argocd version --output json | jq -e 'all(.client.Version; startswith("$VERSION"))' + argocd account list | grep "$ARGOCD_USERNAME" """# - env: VERSION: TestConfig.argocdConfig.version + env: ARGOCD_USERNAME: TestConfig.argocdConfig.username } -TestArgoCDStatus: #Status & { +TestApp: #App & { config: TestConfig.argocdConfig - name: "test" + name: "daggerci-test" + repo: "https://github.com/argoproj/argocd-example-apps.git" + path: "guestbook" +} + +TestArgoCDStatus: #Sync & { + config: TestApp.config + application: TestApp.name } diff --git a/stdlib/universe.bats b/stdlib/universe.bats index e741ec79..b0d7d4e6 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -219,21 +219,20 @@ setup() { skip_unless_local_kube # Deploy argoCD infra - # dagger -e argocd-infra input text TestKubeconfig -f "$HOME"/.kube/config - #dagger -e argocd-infra up - # pid=$! + dagger -e argocd-infra input text TestKubeconfig -f "$HOME"/.kube/config + dagger -e argocd-infra up - curl localhost:8080 + # Forward port + kubectl port-forward svc/argocd-server -n argocd 8080:443 >/dev/null 2>/dev/null & + pid=$! + sleep 3 + + # Run test + dagger -e argocd input secret TestConfig.argocdConfig.password "$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)" + dagger -e up + dagger -e argocd input unset TestConfig.argocdConfig.password # Kill Pid - #check_pid=$(pgrep "$pid") - #if [ "$pid" -eq "$check_pid" ]; then - # kill "$pid" - #fi - # skip "ArgoCD CI secrets not yet generated - Infra not implemented yet" - # dagger -e argocd input secret TestConfig.argocdConfig.token "$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo)" - # dagger -e argocd up + pkill kubectl - # Kill forward - # >&2 echo "kill pid" } From 083fee85a50e62c6a3b5fe65ca6dc7e60f08c7e0 Mon Sep 17 00:00:00 2001 From: Kevin Poirot Date: Fri, 10 Sep 2021 09:40:46 +0200 Subject: [PATCH 09/13] Fix ArgoCD outputs parse Signed-off-by: Kevin Poirot --- stdlib/argocd/status.cue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/argocd/status.cue b/stdlib/argocd/status.cue index 017f7b4d..0fe5f639 100644 --- a/stdlib/argocd/status.cue +++ b/stdlib/argocd/status.cue @@ -44,8 +44,7 @@ import ( op.#Exec & { args: ["sh", "-c", #""" - // FIXME JQ failed - 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 + 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: { From d34200c9f63590e301be08846711825cacb8b299 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 10 Sep 2021 10:44:12 +0200 Subject: [PATCH 10/13] Fix CI check Signed-off-by: Tom Chauveau --- docs/reference/argocd.md | 97 ++++++++++++++++++++++++---------------- stdlib/argocd/status.cue | 4 +- stdlib/helpers.bash | 2 +- stdlib/universe.bats | 1 - 4 files changed, 61 insertions(+), 43 deletions(-) diff --git a/docs/reference/argocd.md b/docs/reference/argocd.md index 4ebc5a03..40241cf5 100644 --- a/docs/reference/argocd.md +++ b/docs/reference/argocd.md @@ -16,17 +16,28 @@ Create an ArgoCD application ### argocd.#App 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` |App name | -|*repo* | `string` |Repository url (git or helm) | -|*path* | `string` |Folder to deploy | -|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server | -|*namespace* | `*"default" \| string` |Destination namespace | +| 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.username* | `string` |Username | +|*config.password* | `dagger.#Secret` |Password | +|*name* | `string` |App name | +|*repo* | `string` |Repository url (git or helm) | +|*path* | `string` |Folder to deploy | +|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server | +|*namespace* | `*"default" \| string` |Destination namespace | +|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*ctr.image.config.server* | `string` |ArgoCD server | +|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | +|*ctr.image.config.username* | `string` |Username | +|*ctr.image.config.password* | `dagger.#Secret` |Password | +|*ctr.env.APP_NAME* | `string` |- | +|*ctr.env.APP_REPO* | `string` |- | +|*ctr.env.APP_PATH* | `string` |- | +|*ctr.env.APP_SERVER* | `*"https://kubernetes.default.svc" \| string` |- | +|*ctr.env.APP_NAMESPACE* | `*"default" \| string` |- | ### argocd.#App Outputs @@ -38,12 +49,13 @@ 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 | +| 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.username* | `string` |Username | +|*config.password* | `dagger.#Secret` |Password | ### argocd.#CLI Outputs @@ -55,12 +67,13 @@ 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 | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*server* | `string` |ArgoCD server | +|*project* | `*"default" \| string` |ArgoCD project | +|*username* | `string` |Username | +|*password* | `dagger.#Secret` |Password | ### argocd.#Config Outputs @@ -72,13 +85,14 @@ Get application's status ### argocd.#Status 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 | +| 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.username* | `string` |Username | +|*config.password* | `dagger.#Secret` |Password | +|*name* | `string` |ArgoCD application | ### argocd.#Status Outputs @@ -97,14 +111,21 @@ Sync an application to its targer state ### argocd.#Sync 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 | -|*wait* | `*false \| bool` |Wait the application to sync correctly | +| 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.username* | `string` |Username | +|*config.password* | `dagger.#Secret` |Password | +|*application* | `string` |ArgoCD application | +|*wait* | `*false \| bool` |Wait the application to sync correctly | +|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*ctr.image.config.server* | `string` |ArgoCD server | +|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | +|*ctr.image.config.username* | `string` |Username | +|*ctr.image.config.password* | `dagger.#Secret` |Password | +|*ctr.env.APPLICATION* | `string` |- | ### argocd.#Sync Outputs diff --git a/stdlib/argocd/status.cue b/stdlib/argocd/status.cue index 0fe5f639..890645e8 100644 --- a/stdlib/argocd/status.cue +++ b/stdlib/argocd/status.cue @@ -47,9 +47,7 @@ import ( 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 - } + env: APPLICATION: name }, op.#Export & { diff --git a/stdlib/helpers.bash b/stdlib/helpers.bash index dbea6b8b..bf9b7325 100644 --- a/stdlib/helpers.bash +++ b/stdlib/helpers.bash @@ -74,7 +74,7 @@ skip_unless_local_localstack() { # # This is need to do kubernetes test in the CI. skip_unless_local_kube() { - if [ -f ~/.kube/config ] && grep -q "user: kind-kind" ~/.kube/config &> /dev/null && grep -q "127.0.0.1" ~/.kube/config &> /dev/null; then + if [ -f ~/.kube/config ] && grep -q "127.0.0.1" ~/.kube/config &> /dev/null; then echo "Kubernetes available" else skip "local kubernetes cluster not available" diff --git a/stdlib/universe.bats b/stdlib/universe.bats index b0d7d4e6..f7717afd 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -224,7 +224,6 @@ setup() { # Forward port kubectl port-forward svc/argocd-server -n argocd 8080:443 >/dev/null 2>/dev/null & - pid=$! sleep 3 # Run test From 05b165bcc89988b3e2d54bd13524ea5350ad2279 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 10 Sep 2021 11:13:10 +0200 Subject: [PATCH 11/13] Supports both basicAuth & Token Signed-off-by: Tom Chauveau --- docs/reference/argocd.md | 111 ++++++++++++-------------- stdlib/.dagger/env/argocd/values.yaml | 14 ++-- stdlib/argocd/argocd.cue | 62 ++++++++++---- stdlib/argocd/tests/argocd.cue | 12 +-- stdlib/universe.bats | 12 +-- 5 files changed, 120 insertions(+), 91 deletions(-) diff --git a/docs/reference/argocd.md b/docs/reference/argocd.md index 40241cf5..26230c96 100644 --- a/docs/reference/argocd.md +++ b/docs/reference/argocd.md @@ -16,28 +16,26 @@ Create an ArgoCD application ### argocd.#App 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.username* | `string` |Username | -|*config.password* | `dagger.#Secret` |Password | -|*name* | `string` |App name | -|*repo* | `string` |Repository url (git or helm) | -|*path* | `string` |Folder to deploy | -|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server | -|*namespace* | `*"default" \| string` |Destination namespace | -|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | -|*ctr.image.config.server* | `string` |ArgoCD server | -|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | -|*ctr.image.config.username* | `string` |Username | -|*ctr.image.config.password* | `dagger.#Secret` |Password | -|*ctr.env.APP_NAME* | `string` |- | -|*ctr.env.APP_REPO* | `string` |- | -|*ctr.env.APP_PATH* | `string` |- | -|*ctr.env.APP_SERVER* | `*"https://kubernetes.default.svc" \| string` |- | -|*ctr.env.APP_NAMESPACE* | `*"default" \| string` |- | +| 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` |App name | +|*repo* | `string` |Repository url (git or helm) | +|*path* | `string` |Folder to deploy | +|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server | +|*namespace* | `*"default" \| string` |Destination namespace | +|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*ctr.image.config.server* | `string` |ArgoCD server | +|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | +|*ctr.image.config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*ctr.env.APP_NAME* | `string` |- | +|*ctr.env.APP_REPO* | `string` |- | +|*ctr.env.APP_PATH* | `string` |- | +|*ctr.env.APP_SERVER* | `*"https://kubernetes.default.svc" \| string` |- | +|*ctr.env.APP_NAMESPACE* | `*"default" \| string` |- | ### argocd.#App Outputs @@ -49,13 +47,12 @@ 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.username* | `string` |Username | -|*config.password* | `dagger.#Secret` |Password | +| 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 @@ -67,13 +64,12 @@ 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 | -|*username* | `string` |Username | -|*password* | `dagger.#Secret` |Password | +| 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 @@ -85,14 +81,13 @@ Get application's status ### argocd.#Status 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.username* | `string` |Username | -|*config.password* | `dagger.#Secret` |Password | -|*name* | `string` |ArgoCD application | +| 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 | ### argocd.#Status Outputs @@ -111,21 +106,19 @@ Sync an application to its targer state ### argocd.#Sync 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.username* | `string` |Username | -|*config.password* | `dagger.#Secret` |Password | -|*application* | `string` |ArgoCD application | -|*wait* | `*false \| bool` |Wait the application to sync correctly | -|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | -|*ctr.image.config.server* | `string` |ArgoCD server | -|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | -|*ctr.image.config.username* | `string` |Username | -|*ctr.image.config.password* | `dagger.#Secret` |Password | -|*ctr.env.APPLICATION* | `string` |- | +| 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 | +|*wait* | `*false \| bool` |Wait the application to sync correctly | +|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*ctr.image.config.server* | `string` |ArgoCD server | +|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | +|*ctr.image.config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*ctr.env.APPLICATION* | `string` |- | ### argocd.#Sync Outputs diff --git a/stdlib/.dagger/env/argocd/values.yaml b/stdlib/.dagger/env/argocd/values.yaml index 90edff9b..484b4e88 100644 --- a/stdlib/.dagger/env/argocd/values.yaml +++ b/stdlib/.dagger/env/argocd/values.yaml @@ -13,14 +13,14 @@ sops: - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk enc: | -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBuV3FTdWpWRjUxSS9hcVU4 - T094TC9GRkcxQThPMVI3NzVCb2d3Q2cvUFRvClVHT1J6OFRVY1ZTYWQ2eDZmWXN3 - N1VjdC9WNnlBNzRIdFVBN0E4Zm0xUzAKLS0tIEc2VFFSYmRqYUI5VDBDRGtTK2k1 - WG5JdHlKYUlnZnZlMVNIRjczSld5ek0KF0z0UqtoGcYFFeOyMwIDAY1pyKosaOii - IVqsMSYfj4+vz7mRd8HoXoSiSnuc7mLJek/izsdZtYUTfD/QnTC71Q== + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBhZEhvaGFiVGVUcWZhcjVj + WmthWWRMMmFXSmRIbzNKUm9IMms0TUltcjBvClE4UHlwcHVGcjVJTHRhNUx1Lyt4 + UHZlTlBRRnhtMmMzcmFPUGlBTXlVMncKLS0tIFpkSXU1SDUvZTR4MVgxNWxKV3V3 + LzM4MENHSVZFNVJza3FhVGkyd0R4d3cKPI6V2o1BR8WVrsAdsuuKOW9Lw32c+KUh + WBHXbYucWjPeogNVIZK+/iJs4Pz92fQ1awdj0H47ro3d7I3QfZoeJQ== -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-09-09T12:42:58Z" - mac: ENC[AES256_GCM,data:CMNfY3kBAbDOkyh1s3csD7uGToV/5TubN/0z3NaG0rVOeHzgPx//PUw7jfhBe3iTCe5m7z5jpGwbI9h6+GoANrsPX887/XYvC22JLQ7vqfOqJYOrYY9YbEJnYK+GXthQB7bqn5Yh2+yiNRVk9vHJkXyhqea9/ud32kiKhG2tE3o=,iv:eT3sjgmh4NF1sS+MSsOEZbgvAiWOwep72aM2fDenG0s=,tag:HcKVlnDpn6kQxFdlKSCALg==,type:str] + lastmodified: "2021-09-10T09:08:35Z" + mac: ENC[AES256_GCM,data:RhRtuEL1xqfJ8pvofq91JMKElZY4Pqvb3SY3IhVevotGBAR6UvmKBA6Nfi3VsvbjfAlbA8/Ip+ifHNhuv6iS1kcj+u5Y7E+6esMdXoXlPmry1Jpt8fWu+zeO2t2XiVGsSEw8nLhPyZfMsp0KBoec1I43NUIKQXoPMbUFMMy1rLQ=,iv:Q817XyIlU/0BgUc6tNVZ8f9cz83I/3FbF8wvqaWNtso=,tag:/Ui9/AAT4RnnwfrOw83xew==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 diff --git a/stdlib/argocd/argocd.cue b/stdlib/argocd/argocd.cue index 75648379..348cdb57 100644 --- a/stdlib/argocd/argocd.cue +++ b/stdlib/argocd/argocd.cue @@ -18,11 +18,17 @@ import ( // ArgoCD project project: *"default" | dagger.#Input & {string} - // Username - username: dagger.#Input & {string} + // Basic authentification to login + basicAuth: { + // Username + username: dagger.#Input & {string} - // Password - password: dagger.#Input & {dagger.#Secret} + // Password + password: dagger.#Input & {dagger.#Secret} + } | *null + + // ArgoCD authentication token + token: dagger.#Input & {*null | dagger.#Secret} } // Re-usable CLI component @@ -49,17 +55,45 @@ import ( env: VERSION: config.version }, - // 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.username + 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 } - mount: "/run/secrets/password": secret: config.password }, + + 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 + } + }, + ] } diff --git a/stdlib/argocd/tests/argocd.cue b/stdlib/argocd/tests/argocd.cue index dde89457..b172cd5f 100644 --- a/stdlib/argocd/tests/argocd.cue +++ b/stdlib/argocd/tests/argocd.cue @@ -6,10 +6,12 @@ import ( ) TestConfig: argocdConfig: #Config & { - version: dagger.#Input & {*"v2.0.5" | string} - server: dagger.#Input & {*"dagger-example-argocd-server.tld" | string} - username: dagger.#Input & {*"admin" | string} - password: dagger.#Input & {dagger.#Secret} + version: dagger.#Input & {*"v2.0.5" | string} + server: dagger.#Input & {*"dagger-example-argocd-server.tld" | string} + basicAuth: { + username: dagger.#Input & {*"admin" | string} + password: dagger.#Input & {dagger.#Secret} + } } TestClient: os.#Container & { @@ -19,7 +21,7 @@ TestClient: os.#Container & { command: #""" argocd account list | grep "$ARGOCD_USERNAME" """# - env: ARGOCD_USERNAME: TestConfig.argocdConfig.username + env: ARGOCD_USERNAME: TestConfig.argocdConfig.basicAuth.username } TestApp: #App & { diff --git a/stdlib/universe.bats b/stdlib/universe.bats index f7717afd..a05d40a0 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -223,15 +223,15 @@ setup() { dagger -e argocd-infra up # Forward port + # We need to kill subprocess to avoid infinity loop kubectl port-forward svc/argocd-server -n argocd 8080:443 >/dev/null 2>/dev/null & - sleep 3 + sleep 3 || (pkill kubectl && exit 1) # Run test - dagger -e argocd input secret TestConfig.argocdConfig.password "$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)" - dagger -e up - dagger -e argocd input unset TestConfig.argocdConfig.password + dagger -e argocd input secret TestConfig.argocdConfig.basicAuth.password "$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)" || (pkill kubectl && exit 1) + dagger -e argocd up || (pkill kubectl && exit 1) + dagger -e argocd input unset TestConfig.argocdConfig.basicAuth.password || (pkill kubectl && exit 1) # Kill Pid - pkill kubectl - + pgrep kubectl && pkill kubectl } From ef112e21ec4e01e70ba2dca147d4c34d4a0c37c4 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 10 Sep 2021 15:37:37 +0200 Subject: [PATCH 12/13] Fix caching issue on argoCD package Signed-off-by: Tom Chauveau --- docs/reference/argocd.md | 66 ++++++++++++++++++++-------------------- stdlib/argocd/app.cue | 3 +- stdlib/argocd/status.cue | 1 + stdlib/argocd/sync.cue | 3 +- stdlib/universe.bats | 3 ++ 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/docs/reference/argocd.md b/docs/reference/argocd.md index 26230c96..8c819934 100644 --- a/docs/reference/argocd.md +++ b/docs/reference/argocd.md @@ -16,26 +16,26 @@ Create an ArgoCD application ### argocd.#App 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` |App name | -|*repo* | `string` |Repository url (git or helm) | -|*path* | `string` |Folder to deploy | -|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server | -|*namespace* | `*"default" \| string` |Destination namespace | -|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | -|*ctr.image.config.server* | `string` |ArgoCD server | -|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | -|*ctr.image.config.token* | `dagger.#Secret` |ArgoCD authentication token | -|*ctr.env.APP_NAME* | `string` |- | -|*ctr.env.APP_REPO* | `string` |- | -|*ctr.env.APP_PATH* | `string` |- | -|*ctr.env.APP_SERVER* | `*"https://kubernetes.default.svc" \| string` |- | -|*ctr.env.APP_NAMESPACE* | `*"default" \| string` |- | +| 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` |App name | +|*repo* | `string` |Repository url (git or helm) | +|*path* | `string` |Folder to deploy | +|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server | +|*image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*image.config.server* | `string` |ArgoCD server | +|*image.config.project* | `*"default" \| string` |ArgoCD project | +|*image.config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*namespace* | `*"default" \| string` |Destination namespace | +|*env.APP_NAME* | `string` |- | +|*env.APP_REPO* | `string` |- | +|*env.APP_PATH* | `string` |- | +|*env.APP_SERVER* | `*"https://kubernetes.default.svc" \| string` |- | +|*env.APP_NAMESPACE* | `*"default" \| string` |- | ### argocd.#App Outputs @@ -106,19 +106,19 @@ Sync an application to its targer state ### argocd.#Sync 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 | -|*wait* | `*false \| bool` |Wait the application to sync correctly | -|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | -|*ctr.image.config.server* | `string` |ArgoCD server | -|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | -|*ctr.image.config.token* | `dagger.#Secret` |ArgoCD authentication token | -|*ctr.env.APPLICATION* | `string` |- | +| 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 | +|*image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*image.config.server* | `string` |ArgoCD server | +|*image.config.project* | `*"default" \| string` |ArgoCD project | +|*image.config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*wait* | `*false \| bool` |Wait the application to sync correctly | +|*env.APPLICATION* | `string` |- | ### argocd.#Sync Outputs diff --git a/stdlib/argocd/app.cue b/stdlib/argocd/app.cue index 94f60290..dd652f10 100644 --- a/stdlib/argocd/app.cue +++ b/stdlib/argocd/app.cue @@ -25,7 +25,7 @@ import ( // Destination namespace namespace: dagger.#Input & {*"default" | string} - ctr: os.#Container & { + os.#Container & { image: #CLI & { "config": config } @@ -36,6 +36,7 @@ import ( --dest-server "$APP_SERVER" \ --dest-namespace "$APP_NAMESPACE" """# + always: true env: { APP_NAME: name APP_REPO: repo diff --git a/stdlib/argocd/status.cue b/stdlib/argocd/status.cue index 890645e8..0383f4d1 100644 --- a/stdlib/argocd/status.cue +++ b/stdlib/argocd/status.cue @@ -48,6 +48,7 @@ import ( """#, ] env: APPLICATION: name + always: true }, op.#Export & { diff --git a/stdlib/argocd/sync.cue b/stdlib/argocd/sync.cue index 72186aff..69a75bcf 100644 --- a/stdlib/argocd/sync.cue +++ b/stdlib/argocd/sync.cue @@ -16,7 +16,7 @@ import ( // Wait the application to sync correctly wait: dagger.#Input & {*false | bool} - ctr: os.#Container & { + os.#Container & { image: #CLI & { "config": config } @@ -27,6 +27,7 @@ import ( argocd app wait "$APPLICATION" fi """# + always: true env: APPLICATION: application if wait { env: WAIT_FLAG: "wait" diff --git a/stdlib/universe.bats b/stdlib/universe.bats index a05d40a0..ad751934 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -222,6 +222,9 @@ setup() { dagger -e argocd-infra input text TestKubeconfig -f "$HOME"/.kube/config dagger -e argocd-infra up + # Wait for infra to be ready + kubectl -n argocd wait --for=condition=available deployment -l "app.kubernetes.io/part-of=argocd" --timeout=45s + # Forward port # We need to kill subprocess to avoid infinity loop kubectl port-forward svc/argocd-server -n argocd 8080:443 >/dev/null 2>/dev/null & From 733cac09d34317f2ed40062b91b6c0a9c5141248 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 10 Sep 2021 16:29:29 +0200 Subject: [PATCH 13/13] `argocd.#Sync` now retrieve status Signed-off-by: Tom Chauveau --- docs/reference/argocd.md | 40 ++++++++++++++++++++++------------ stdlib/argocd/sync.cue | 7 +++++- stdlib/argocd/tests/argocd.cue | 1 + stdlib/universe.bats | 5 +++++ 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/docs/reference/argocd.md b/docs/reference/argocd.md index 8c819934..c29bb096 100644 --- a/docs/reference/argocd.md +++ b/docs/reference/argocd.md @@ -106,20 +106,32 @@ Sync an application to its targer state ### argocd.#Sync 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 | -|*image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | -|*image.config.server* | `string` |ArgoCD server | -|*image.config.project* | `*"default" \| string` |ArgoCD project | -|*image.config.token* | `dagger.#Secret` |ArgoCD authentication token | -|*wait* | `*false \| bool` |Wait the application to sync correctly | -|*env.APPLICATION* | `string` |- | +| 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 | +|*wait* | `*false \| bool` |Wait the application to sync correctly | +|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*ctr.image.config.server* | `string` |ArgoCD server | +|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project | +|*ctr.image.config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*ctr.env.APPLICATION* | `string` |- | +|*status.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version | +|*status.config.server* | `string` |ArgoCD server | +|*status.config.project* | `*"default" \| string` |ArgoCD project | +|*status.config.token* | `dagger.#Secret` |ArgoCD authentication token | +|*status.name* | `string` |ArgoCD application | ### argocd.#Sync Outputs -_No output._ +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*status.outputs.health* | `string` |Application health | +|*status.outputs.sync* | `string` |Application sync state | +|*status.outputs.namespace* | `string` |Namespace | +|*status.outputs.server* | `string` |Server | +|*status.outputs.urls* | `string` |Comma separated list of application URLs | +|*status.outputs.state* | `string` |Last operation state message | diff --git a/stdlib/argocd/sync.cue b/stdlib/argocd/sync.cue index 69a75bcf..718aada4 100644 --- a/stdlib/argocd/sync.cue +++ b/stdlib/argocd/sync.cue @@ -16,7 +16,7 @@ import ( // Wait the application to sync correctly wait: dagger.#Input & {*false | bool} - os.#Container & { + ctr: os.#Container & { image: #CLI & { "config": config } @@ -33,4 +33,9 @@ import ( env: WAIT_FLAG: "wait" } } + + status: #Status & { + config: ctr.image.config + name: application + } } diff --git a/stdlib/argocd/tests/argocd.cue b/stdlib/argocd/tests/argocd.cue index b172cd5f..bfd1d71e 100644 --- a/stdlib/argocd/tests/argocd.cue +++ b/stdlib/argocd/tests/argocd.cue @@ -34,4 +34,5 @@ TestApp: #App & { TestArgoCDStatus: #Sync & { config: TestApp.config application: TestApp.name + wait: true } diff --git a/stdlib/universe.bats b/stdlib/universe.bats index ad751934..dafd0f54 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -237,4 +237,9 @@ setup() { # Kill Pid pgrep kubectl && pkill kubectl + + # Check output + run dagger -e argocd query TestArgoCDStatus.status.outputs.health -f json + assert_success + assert_output "\"Healthy\"" }