commit
3bc91530e0
@ -3,6 +3,44 @@
|
|||||||
All example commands should be executed in the `examples/` directory
|
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).
|
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
|
## 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)
|
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
|
```sh
|
||||||
dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY
|
dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY
|
dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -165,9 +200,6 @@ dagger new
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY
|
dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY
|
dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -217,9 +249,6 @@ dagger new
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY
|
dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY
|
dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY
|
||||||
```
|
```
|
||||||
|
|
||||||
|
33
examples/simple-s3/main.cue
Normal file
33
examples/simple-s3/main.cue
Normal file
@ -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: """
|
||||||
|
<html>
|
||||||
|
</head>
|
||||||
|
<title>Simple static website on S3</title>
|
||||||
|
</head>
|
||||||
|
<h1>Hello!</h1>
|
||||||
|
<li>Hey \(name)</li>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
deploy: s3.#Put & {
|
||||||
|
config: awsConfig
|
||||||
|
sourceInline: page
|
||||||
|
contentType: "text/html"
|
||||||
|
target: "s3://\(bucket)/index.html"
|
||||||
|
}
|
@ -4,7 +4,7 @@ import (
|
|||||||
"dagger.io/dagger/op"
|
"dagger.io/dagger/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
let defaultVersion = "3.13.2@sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be"
|
let defaultVersion = "3.13.5@sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f"
|
||||||
|
|
||||||
#Image: {
|
#Image: {
|
||||||
package: [string]: true | false | string
|
package: [string]: true | false | string
|
||||||
|
@ -24,10 +24,10 @@ import (
|
|||||||
op.#Load & {
|
op.#Load & {
|
||||||
from: alpine.#Image & {
|
from: alpine.#Image & {
|
||||||
"package": package
|
"package": package
|
||||||
"package": bash: "=5.1.0-r0"
|
"package": bash: "=~5.1"
|
||||||
"package": jq: "=1.6-r1"
|
"package": jq: "=~1.6"
|
||||||
"package": curl: "=7.74.0-r1"
|
"package": curl: "=~7.76"
|
||||||
"package": "aws-cli": "=1.18.177-r0"
|
"package": "aws-cli": "=~1.18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
61
stdlib/aws/s3/s3.cue
Normal file
61
stdlib/aws/s3/s3.cue
Normal file
@ -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://<bucket-name>/<path>/<sub-path>)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,9 +20,9 @@ import (
|
|||||||
#up: [
|
#up: [
|
||||||
op.#Load & {
|
op.#Load & {
|
||||||
from: alpine.#Image & {
|
from: alpine.#Image & {
|
||||||
package: bash: "=5.1.0-r0"
|
package: bash: "=~5.1"
|
||||||
package: jq: "=1.6-r1"
|
package: jq: "=~1.6"
|
||||||
package: curl: "=7.74.0-r1"
|
package: curl: "=~7.76"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
op.#WriteFile & {
|
op.#WriteFile & {
|
||||||
|
@ -47,7 +47,7 @@ import (
|
|||||||
from: alpine.#Image & {
|
from: alpine.#Image & {
|
||||||
package: bash: "=~5.1"
|
package: bash: "=~5.1"
|
||||||
package: jq: "=~1.6"
|
package: jq: "=~1.6"
|
||||||
package: curl: "=~7.74"
|
package: curl: "=~7.76"
|
||||||
package: yarn: "=~1.22"
|
package: yarn: "=~1.22"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
TestImageVersion: {
|
TestImageVersion: {
|
||||||
image: alpine.#Image & {
|
image: alpine.#Image & {
|
||||||
// install an old version on purpose
|
// install an old version on purpose
|
||||||
version: "3.10.6"
|
version: "3.10.9"
|
||||||
}
|
}
|
||||||
|
|
||||||
test: #up: [
|
test: #up: [
|
||||||
@ -18,7 +18,7 @@ TestImageVersion: {
|
|||||||
"sh",
|
"sh",
|
||||||
"-ec",
|
"-ec",
|
||||||
"""
|
"""
|
||||||
test "$(cat /etc/alpine-release)" = 3.10.6
|
test "$(cat /etc/alpine-release)" = 3.10.9
|
||||||
""",
|
""",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -28,7 +28,8 @@ TestImageVersion: {
|
|||||||
TestPackageInstall: {
|
TestPackageInstall: {
|
||||||
image: alpine.#Image & {
|
image: alpine.#Image & {
|
||||||
package: jq: true
|
package: jq: true
|
||||||
package: curl: "=~7.74.0"
|
package: curl: "=~7.76"
|
||||||
|
version: "3.13"
|
||||||
}
|
}
|
||||||
|
|
||||||
test: #up: [
|
test: #up: [
|
||||||
@ -37,7 +38,7 @@ TestPackageInstall: {
|
|||||||
args: ["jq", "--version"]
|
args: ["jq", "--version"]
|
||||||
},
|
},
|
||||||
op.#Exec & {
|
op.#Exec & {
|
||||||
args: ["sh", "-ec", "curl --version | grep -q 7.74.0"]
|
args: ["sh", "-ec", "curl --version | grep -q 7.76"]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ TestNetlify: {
|
|||||||
op.#Load & {
|
op.#Load & {
|
||||||
from: alpine.#Image & {
|
from: alpine.#Image & {
|
||||||
package: bash: "=~5.1"
|
package: bash: "=~5.1"
|
||||||
package: curl: "=~7.74"
|
package: curl: "=~7.76"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
op.#Exec & {
|
op.#Exec & {
|
||||||
|
Reference in New Issue
Block a user