From 413017f7cbc196ef2a3e4a2b691f5b0067373288 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 14 Apr 2021 11:57:37 -0700 Subject: [PATCH 1/4] stdlib/aws: implemented s3 Signed-off-by: Sam Alba --- stdlib/aws/s3/s3.cue | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 stdlib/aws/s3/s3.cue diff --git a/stdlib/aws/s3/s3.cue b/stdlib/aws/s3/s3.cue new file mode 100644 index 00000000..5c1ef05e --- /dev/null +++ b/stdlib/aws/s3/s3.cue @@ -0,0 +1,61 @@ +package s3 + +import ( + "dagger.io/dagger" + "dagger.io/aws" +) + +// S3 file or Directory upload +#Put: { + + // AWS Config + config: aws.#Config + + // Source Artifact to upload to S3 + source?: dagger.#Artifact + + // Source inlined as a string to upload to S3 + sourceInline?: string + + // Target S3 URL (eg. s3:////) + target: string + + // Object content type + contentType: string | *"" + + // URL of the uploaded S3 object + url: out + + out: string + aws.#Script & { + files: { + if sourceInline != _|_ { + "/inputs/source": sourceInline + } + "/inputs/target": target + if contentType != "" { + "/inputs/content_type": contentType + } + } + + export: "/url" + + code: #""" + opts="" + if [ -d /inputs/source ]; then + opts="--recursive" + fi + if [ -f /inputs/content_type ]; then + opts="--content-type $(cat /inputs/content_type)" + fi + aws s3 cp $opts /inputs/source "$(cat /inputs/target)" + cat /inputs/target \ + | sed -E 's=^s3://([^/]*)/=https://\1.s3.amazonaws.com/=' \ + > /url + """# + + if sourceInline == _|_ { + mount: "/inputs/source": from: source + } + } +} From 39f7170cc5a9f167dcdb98558845eb7f374fe164 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 14 Apr 2021 11:57:58 -0700 Subject: [PATCH 2/4] examples: added simple s3 for static website example Signed-off-by: Sam Alba --- examples/README.md | 47 ++++++++++++++++++++++++++++++------- examples/simple-s3/main.cue | 33 ++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 examples/simple-s3/main.cue diff --git a/examples/README.md b/examples/README.md index 20665522..6d40f92d 100644 --- a/examples/README.md +++ b/examples/README.md @@ -3,6 +3,44 @@ All example commands should be executed in the `examples/` directory in an up-to-date checkout of the [dagger repository](https://github.com/dagger/dagger). +## Deploy a static page to S3 + +This example shows how to generate a simple HTML page and serve it from an S3 bucket. + +Components: + +- [Amazon S3](https://aws.amazon.com/s3/) for hosting + +1. Change the current directory to the example deployment plan and create a new deployment + +```sh +cd ./simple-s3 +dagger new +``` + +2. Configure your AWS credentials + +```sh +dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY +dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY +``` + +3. Deploy! + +```sh +dagger up +``` + +4. Change a variable to alter the content + +In this example config, the HTML content is created from a variable `name` that has a default value, here is a simple +way to change it without changing the code: + +```sh +dagger input text name "someone else!" +dagger up +``` + ## Deploy a simple React application This example shows how to deploy an example React Application. [Read the deployment plan](https://github.com/dagger/dagger/tree/main/examples/react) @@ -120,9 +158,6 @@ dagger new ```sh dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY -``` - -```sh dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY ``` @@ -165,9 +200,6 @@ dagger new ```sh dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY -``` - -```sh dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY ``` @@ -217,9 +249,6 @@ dagger new ```sh dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY -``` - -```sh dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY ``` diff --git a/examples/simple-s3/main.cue b/examples/simple-s3/main.cue new file mode 100644 index 00000000..f93ff379 --- /dev/null +++ b/examples/simple-s3/main.cue @@ -0,0 +1,33 @@ +package main + +import ( + "dagger.io/aws" + "dagger.io/aws/s3" +) + +// AWS Config for credentials and default region +awsConfig: aws.#Config & { + region: *"us-east-1" | string +} + +// Name of the S3 bucket to use +bucket: *"hello-s3.infralabs.io" | string + +name: string | *"world" + +page: """ + + + Simple static website on S3 + +

Hello!

+
  • Hey \(name)
  • + + """ + +deploy: s3.#Put & { + config: awsConfig + sourceInline: page + contentType: "text/html" + target: "s3://\(bucket)/index.html" +} From 8e5024db3719d7965cff13737f3cdcf5824211d4 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 14 Apr 2021 13:35:48 -0700 Subject: [PATCH 3/4] fix alpine test + only select major versions for aws pkgs Signed-off-by: Sam Alba --- stdlib/aws/aws.cue | 8 ++++---- tests/stdlib/alpine/alpine.cue | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/stdlib/aws/aws.cue b/stdlib/aws/aws.cue index 1a3663c8..e23a88f5 100644 --- a/stdlib/aws/aws.cue +++ b/stdlib/aws/aws.cue @@ -24,10 +24,10 @@ import ( op.#Load & { from: alpine.#Image & { "package": package - "package": bash: "=5.1.0-r0" - "package": jq: "=1.6-r1" - "package": curl: "=7.74.0-r1" - "package": "aws-cli": "=1.18.177-r0" + "package": bash: "=~5.1" + "package": jq: "=~1.6" + "package": curl: "=~7.74" + "package": "aws-cli": "=~1.18" } }, ] diff --git a/tests/stdlib/alpine/alpine.cue b/tests/stdlib/alpine/alpine.cue index 1bcd3e62..19a100d4 100644 --- a/tests/stdlib/alpine/alpine.cue +++ b/tests/stdlib/alpine/alpine.cue @@ -8,7 +8,7 @@ import ( TestImageVersion: { image: alpine.#Image & { // install an old version on purpose - version: "3.10.6" + version: "3.10.9" } test: #up: [ @@ -18,7 +18,7 @@ TestImageVersion: { "sh", "-ec", """ - test "$(cat /etc/alpine-release)" = 3.10.6 + test "$(cat /etc/alpine-release)" = 3.10.9 """, ] }, @@ -28,7 +28,8 @@ TestImageVersion: { TestPackageInstall: { image: alpine.#Image & { package: jq: true - package: curl: "=~7.74.0" + package: curl: "=~7.76" + version: "3.13" } test: #up: [ @@ -37,7 +38,7 @@ TestPackageInstall: { args: ["jq", "--version"] }, op.#Exec & { - args: ["sh", "-ec", "curl --version | grep -q 7.74.0"] + args: ["sh", "-ec", "curl --version | grep -q 7.76"] }, ] } From 5d22e9ed432322a97e76257256e601c0c881b6db Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 14 Apr 2021 14:06:51 -0700 Subject: [PATCH 4/4] stdlib: updated alpine base image and fixed pkg dependencies in sub libs Signed-off-by: Sam Alba --- stdlib/alpine/alpine.cue | 2 +- stdlib/aws/aws.cue | 2 +- stdlib/kubernetes/kubernetes.cue | 6 +++--- stdlib/netlify/netlify.cue | 2 +- tests/stdlib/netlify/netlify.cue | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/alpine/alpine.cue b/stdlib/alpine/alpine.cue index 29094070..a3013780 100644 --- a/stdlib/alpine/alpine.cue +++ b/stdlib/alpine/alpine.cue @@ -4,7 +4,7 @@ import ( "dagger.io/dagger/op" ) -let defaultVersion = "3.13.2@sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be" +let defaultVersion = "3.13.5@sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f" #Image: { package: [string]: true | false | string diff --git a/stdlib/aws/aws.cue b/stdlib/aws/aws.cue index e23a88f5..79c3b64f 100644 --- a/stdlib/aws/aws.cue +++ b/stdlib/aws/aws.cue @@ -26,7 +26,7 @@ import ( "package": package "package": bash: "=~5.1" "package": jq: "=~1.6" - "package": curl: "=~7.74" + "package": curl: "=~7.76" "package": "aws-cli": "=~1.18" } }, diff --git a/stdlib/kubernetes/kubernetes.cue b/stdlib/kubernetes/kubernetes.cue index e3013cce..c8c9f722 100644 --- a/stdlib/kubernetes/kubernetes.cue +++ b/stdlib/kubernetes/kubernetes.cue @@ -20,9 +20,9 @@ import ( #up: [ op.#Load & { from: alpine.#Image & { - package: bash: "=5.1.0-r0" - package: jq: "=1.6-r1" - package: curl: "=7.74.0-r1" + package: bash: "=~5.1" + package: jq: "=~1.6" + package: curl: "=~7.76" } }, op.#WriteFile & { diff --git a/stdlib/netlify/netlify.cue b/stdlib/netlify/netlify.cue index b9410867..04d41761 100644 --- a/stdlib/netlify/netlify.cue +++ b/stdlib/netlify/netlify.cue @@ -47,7 +47,7 @@ import ( from: alpine.#Image & { package: bash: "=~5.1" package: jq: "=~1.6" - package: curl: "=~7.74" + package: curl: "=~7.76" package: yarn: "=~1.22" } }, diff --git a/tests/stdlib/netlify/netlify.cue b/tests/stdlib/netlify/netlify.cue index 40c5fe18..68683cfe 100644 --- a/tests/stdlib/netlify/netlify.cue +++ b/tests/stdlib/netlify/netlify.cue @@ -40,7 +40,7 @@ TestNetlify: { op.#Load & { from: alpine.#Image & { package: bash: "=~5.1" - package: curl: "=~7.74" + package: curl: "=~7.76" } }, op.#Exec & {