diff --git a/.gitignore b/.gitignore index 43cb1378..8a6a6c9c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ # Test binary, build with `go test -c` *.test -tests/report.xml +**/*/report.xml # Output of the go coverage tool, specifically when used with LiteIDE *.out @@ -26,3 +26,4 @@ tests/report.xml # node_modules tests/node_modules dist/ +docs/learn/tests/node_modules diff --git a/docs/learn/tests/.dagger/env/kube-kind-basic/.gitignore b/docs/learn/tests/.dagger/env/kube-kind-basic/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/docs/learn/tests/.dagger/env/kube-kind-basic/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/docs/learn/tests/.dagger/env/kube-kind-basic/values.yaml b/docs/learn/tests/.dagger/env/kube-kind-basic/values.yaml new file mode 100644 index 00000000..11457850 --- /dev/null +++ b/docs/learn/tests/.dagger/env/kube-kind-basic/values.yaml @@ -0,0 +1,23 @@ +plan: + package: ./kube-kind/basic +name: kube-kind-basic +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAwZ3FnR0NRay9TM1FaZXhT + T2hvQ1ZDRkNLMHpMMnh6a3QrZUpRcHhkQVVBCm5NWXdRZXVPVWhEQXdwSnQwQkZ3 + NE1wL3VyNjlVbmdqM2t2MDc1ZHVNd2sKLS0tIEZNUUtnUFVBOTEyMGVWbXgycHo4 + Z0RqSGxzN3pyc1RLcGN5b29GbHpkbWsKhNI37Ws2sWSW2ZKZSSFH5a2LD9meOQrH + MM2Xd0+Kh4OwYIfMXmCU1CmNRP/W1MUf6Eq/21uM3fDU8GDbpOV/pA== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-08-13T12:56:16Z" + mac: ENC[AES256_GCM,data:ODBv7782ofOQzVtETFu9wdMdmK/22jl1CqPzTqdOu6oZFWklbQ4grJ3N1cemE2Ud1Awb/x41QgpSuvVHaO2dHkVEF1FmlVDIqhqm6BNQlDg81RFuvs86FP60cW8rfr4K2dhCnQ1mRKGdTLsNUjUqBd3uwPDu5f49o3Ai/EpOg0A=,iv:1UdjtEKhKyFEnkjUOPAYlyIp8xYieDBIXKGxmxcYUbs=,tag:e6YcVmSVdsfLLMOPQXrN8A==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/docs/learn/tests/doc.bats b/docs/learn/tests/doc.bats index 7080d8ea..71e8ed67 100644 --- a/docs/learn/tests/doc.bats +++ b/docs/learn/tests/doc.bats @@ -2,162 +2,182 @@ ## Indentation is important, please append at the end setup() { - load 'helpers' + load 'helpers' - common_setup + common_setup } # Test 1003-get-started @test "doc-1003-get-started" { - setup_example_sandbox "doc" + setup_example_sandbox "doc" - # Set examples private key - ./import-tutorial-key.sh + # Set examples private key + ./import-tutorial-key.sh - # Collect url - dagger up - url=$(dagger query -f text url) + # Collect url + dagger up + url=$(dagger query -f text url) - # More commands - dagger list - ls -l ./s3 - dagger input list + # More commands + dagger list + ls -l ./s3 + dagger input list - # Check output - run curl $url - assert_output --partial "My Todo app" + # Check output + run curl $url + assert_output --partial "My Todo app" } @test "doc-1004-first-env" { - setup_example_sandbox "doc" + setup_example_sandbox "doc" - # Follow tutorial - mkdir multibucket - cp $CODEBLOC_SRC/multibucket/source.cue multibucket - cp $CODEBLOC_SRC/multibucket/yarn.cue multibucket - cp $CODEBLOC_SRC/multibucket/netlify.cue multibucket + # Follow tutorial + mkdir multibucket + cp $CODEBLOC_SRC/multibucket/source.cue multibucket + cp $CODEBLOC_SRC/multibucket/yarn.cue multibucket + cp $CODEBLOC_SRC/multibucket/netlify.cue multibucket - dagger doc alpha.dagger.io/netlify - dagger doc alpha.dagger.io/js/yarn + dagger doc alpha.dagger.io/netlify + dagger doc alpha.dagger.io/js/yarn - # Initialize new env - dagger new 'multibucket' -p ./multibucket + # Initialize new env + dagger new 'multibucket' -p ./multibucket - # Copy corresponding env - cp -r $CODEBLOC_SRC/.dagger/env/multibucket .dagger/env/ - # Add missing src input - dagger -e multibucket input dir src . + # Copy corresponding env + cp -r $CODEBLOC_SRC/.dagger/env/multibucket .dagger/env/ + # Add missing src input + dagger -e multibucket input dir src . - # Run test - dagger -e multibucket up - url=$(dagger -e multibucket query -f text site.netlify.deployUrl) + # Run test + dagger -e multibucket up + url=$(dagger -e multibucket query -f text site.netlify.deployUrl) - # Check output : - run curl $url - assert_output --partial "./static/css/main.9149988f.chunk.css" + # Check output : + run curl $url + assert_output --partial "./static/css/main.9149988f.chunk.css" } @test "doc-1006-google-cloud-run" { - setup_example_sandbox "doc" + setup_example_sandbox "doc" - mkdir gcpcloudrun - cp $CODEBLOC_SRC/gcpcloudrun/source.cue gcpcloudrun + mkdir gcpcloudrun + cp $CODEBLOC_SRC/gcpcloudrun/source.cue gcpcloudrun - # Initialize new env - dagger new 'gcpcloudrun' -p gcpcloudrun + # Initialize new env + dagger new 'gcpcloudrun' -p gcpcloudrun - # Copy corresponding env - cp -r $CODEBLOC_SRC/.dagger/env/gcpcloudrun .dagger/env/ - # Add missing src input - dagger -e gcpcloudrun input dir src . + # Copy corresponding env + cp -r $CODEBLOC_SRC/.dagger/env/gcpcloudrun .dagger/env/ + # Add missing src input + dagger -e gcpcloudrun input dir src . - # Run test - run dagger -e gcpcloudrun up - assert_success + # Run test + run dagger -e gcpcloudrun up + assert_success +} + +@test "doc-1007-kube-kind" { + skip_unless_local_kube + + #################### BASIC #################### + # Copy deployment to sendbox + copy_to_sandbox kube-kind-basic kube-kind + + # Add kubeconfig + dagger -w "$DAGGER_SANDBOX" -e kube-kind-basic input text kubeconfig -f "$HOME"/.kube/config + + # Up deployment + dagger -w "$DAGGER_SANDBOX" -e kube-kind-basic up + + # Check deployment + kubectl get deployment + + # Clean + kubectl delete deployments --all } @test "doc-1008-aws-cloudformation" { - setup_example_sandbox "doc" + setup_example_sandbox "doc" - ### Create a basic plan - ## Construct - mkdir cloudformation - cp $CODEBLOC_SRC/cloudformation/template.cue cloudformation + ### Create a basic plan + ## Construct + mkdir cloudformation + cp $CODEBLOC_SRC/cloudformation/template.cue cloudformation - # Cloudformation relay - dagger doc alpha.dagger.io/aws/cloudformation - cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue + # Cloudformation relay + dagger doc alpha.dagger.io/aws/cloudformation + cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue - # Initialize new env - dagger new 'cloudformation' -p cloudformation + # Initialize new env + dagger new 'cloudformation' -p cloudformation - # Finish template setup - cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue - # Copy corresponding env - cp -r $CODEBLOC_SRC/.dagger/env/cloudformation .dagger/env/ + # Finish template setup + cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue + # Copy corresponding env + cp -r $CODEBLOC_SRC/.dagger/env/cloudformation .dagger/env/ - # Run test - dagger -e cloudformation up - stackName=$(dagger -e cloudformation query cfnStackName -f text) + # Run test + dagger -e cloudformation up + stackName=$(dagger -e cloudformation query cfnStackName -f text) - ## Cleanup - # Place back empty source - cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue - cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue - # Prepare and run cloudformation cleanup - dagger -e cloudformation input text stackRemoval.stackName $stackName - dagger -e cloudformation up + ## Cleanup + # Place back empty source + cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue + cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue + # Prepare and run cloudformation cleanup + dagger -e cloudformation input text stackRemoval.stackName $stackName + dagger -e cloudformation up - ### Template part - ## Create convert.cue - cp $CODEBLOC_SRC/cloudformation/template/convert.cue cloudformation/convert.cue - rm cloudformation/source.cue cloudformation/deletion.cue + ### Template part + ## Create convert.cue + cp $CODEBLOC_SRC/cloudformation/template/convert.cue cloudformation/convert.cue + rm cloudformation/source.cue cloudformation/deletion.cue - ## Retrieve Unmarshalled JSON - dagger query -e cloudformation s3Template + ## Retrieve Unmarshalled JSON + dagger query -e cloudformation s3Template - ## Remove convert.cue - rm cloudformation/convert.cue - ## Store the output - cp $CODEBLOC_SRC/cloudformation/template/template-begin.cue cloudformation/template.cue - # Inspect conf - dagger query -e cloudformation template -f text + ## Remove convert.cue + rm cloudformation/convert.cue + ## Store the output + cp $CODEBLOC_SRC/cloudformation/template/template-begin.cue cloudformation/template.cue + # Inspect conf + dagger query -e cloudformation template -f text - cp $CODEBLOC_SRC/cloudformation/template/deployment.cue cloudformation/deployment.cue - cp $CODEBLOC_SRC/cloudformation/template/template-end.cue cloudformation/template.cue - cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue + cp $CODEBLOC_SRC/cloudformation/template/deployment.cue cloudformation/deployment.cue + cp $CODEBLOC_SRC/cloudformation/template/template-end.cue cloudformation/template.cue + cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue - # Deploy again - dagger -e cloudformation query template -f text - dagger -e cloudformation up - dagger -e cloudformation output list + # Deploy again + dagger -e cloudformation query template -f text + dagger -e cloudformation up + dagger -e cloudformation output list - ## Cleanup again - stackName=$(dagger -e cloudformation query cfnStackName -f text) - rm -rf cloudformation/* - # Place back empty source - cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue - cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue - # Prepare and run cloudformation cleanup - dagger -e cloudformation input text stackRemoval.stackName $stackName - dagger -e cloudformation up + ## Cleanup again + stackName=$(dagger -e cloudformation query cfnStackName -f text) + rm -rf cloudformation/* + # Place back empty source + cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue + cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue + # Prepare and run cloudformation cleanup + dagger -e cloudformation input text stackRemoval.stackName $stackName + dagger -e cloudformation up } @test "doc-1010-dev-cue-package" { - setup_example_sandbox "" + setup_example_sandbox "" - # Initializing workspace - mkdir workspace - cd workspace + # Initializing workspace + mkdir workspace + cd workspace - # Writing the package - dagger init - mkdir -p cue.mod/pkg/github.com/tjovicic/gcpcloudrun - cp $CODEBLOC_SRC/dev-cue-package/source.cue cue.mod/pkg/github.com/tjovicic/gcpcloudrun/source.cue - cp $CODEBLOC_SRC/dev-cue-package/script.sh . + # Writing the package + dagger init + mkdir -p cue.mod/pkg/github.com/tjovicic/gcpcloudrun + cp $CODEBLOC_SRC/dev-cue-package/source.cue cue.mod/pkg/github.com/tjovicic/gcpcloudrun/source.cue + cp $CODEBLOC_SRC/dev-cue-package/script.sh . - chmod +x script.sh - ./script.sh - run dagger up -e staging - assert_output --partial "environment=staging input=run.gcpConfig.serviceKey" + chmod +x script.sh + ./script.sh + run dagger up -e staging + assert_output --partial "environment=staging input=run.gcpConfig.serviceKey" } diff --git a/docs/learn/tests/kube-kind/basic/manifest.cue b/docs/learn/tests/kube-kind/basic/manifest.cue new file mode 100644 index 00000000..95c4430a --- /dev/null +++ b/docs/learn/tests/kube-kind/basic/manifest.cue @@ -0,0 +1,11 @@ +package main + +import ( + "alpha.dagger.io/git" +) + +manifest: git.#Repository & { + remote: "https://github.com/dagger/examples.git" + ref: "main" + subdir: "todoapp/k8s" +} diff --git a/docs/learn/tests/yarn.lock b/docs/learn/tests/yarn.lock new file mode 100644 index 00000000..b2efa236 --- /dev/null +++ b/docs/learn/tests/yarn.lock @@ -0,0 +1,15 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"bats-assert@https://github.com/bats-core/bats-assert": + version "2.0.0" + resolved "https://github.com/bats-core/bats-assert#e0de84e9c011223e7f88b7ccf1c929f4327097ba" + +"bats-support@https://github.com/bats-core/bats-support": + version "0.3.0" + resolved "https://github.com/bats-core/bats-support#d140a65044b2d6810381935ae7f0c94c7023c8c3" + +"bats@https://github.com/bats-core/bats-core#master": + version "1.4.1" + resolved "https://github.com/bats-core/bats-core#7ff2f3efc738976feaccfdf374164b61599f9e36"