Merge pull request #1610 from shykes/netlify-image
netlify: enable image customization; improve tests
This commit is contained in:
commit
27aa487b21
@ -59,7 +59,7 @@ import (
|
|||||||
|
|
||||||
// Run the netlify client in a container
|
// Run the netlify client in a container
|
||||||
container: bash.#Run & {
|
container: bash.#Run & {
|
||||||
input: _build.output
|
input: *_build.output | docker.#Image
|
||||||
script: {
|
script: {
|
||||||
_load: engine.#Source & {
|
_load: engine.#Source & {
|
||||||
path: "."
|
path: "."
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package yarn
|
package netlify
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dagger.io/dagger"
|
"dagger.io/dagger"
|
||||||
"dagger.io/dagger/engine"
|
"dagger.io/dagger/engine"
|
||||||
|
|
||||||
|
"universe.dagger.io/docker"
|
||||||
"universe.dagger.io/netlify"
|
"universe.dagger.io/netlify"
|
||||||
"universe.dagger.io/alpine"
|
|
||||||
"universe.dagger.io/bash"
|
"universe.dagger.io/netlify/test/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
@ -16,13 +17,16 @@ dagger.#Plan & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actions: tests: {
|
actions: tests: {
|
||||||
// Test: netlify.#Deploy correctly receives API token
|
|
||||||
receiveToken: {
|
// Configuration common to all tests
|
||||||
|
common: {
|
||||||
testSecrets: dagger.#DecodeSecret & {
|
testSecrets: dagger.#DecodeSecret & {
|
||||||
input: inputs.secrets.test.contents
|
input: inputs.secrets.test.contents
|
||||||
format: "yaml"
|
format: "yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token: testSecrets.output.netlifyToken.contents
|
||||||
|
|
||||||
marker: "hello world"
|
marker: "hello world"
|
||||||
|
|
||||||
data: engine.#WriteFile & {
|
data: engine.#WriteFile & {
|
||||||
@ -30,29 +34,66 @@ dagger.#Plan & {
|
|||||||
path: "index.html"
|
path: "index.html"
|
||||||
contents: marker
|
contents: marker
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test: deploy a simple site to Netlify
|
||||||
|
simple: {
|
||||||
// Deploy to netlify
|
// Deploy to netlify
|
||||||
deploy: netlify.#Deploy & {
|
deploy: netlify.#Deploy & {
|
||||||
team: "blocklayer"
|
team: "blocklayer"
|
||||||
token: testSecrets.output.netlifyToken.contents
|
token: common.token
|
||||||
|
|
||||||
site: "dagger-test"
|
site: "dagger-test"
|
||||||
contents: data.output
|
contents: common.data.output
|
||||||
}
|
}
|
||||||
|
|
||||||
image: alpine.#Build & {
|
verify: testutils.#AssertURL & {
|
||||||
packages: {
|
url: deploy.deployUrl
|
||||||
bash: {}
|
contents: common.marker
|
||||||
curl: {}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test: deploy to Netlify with a custom image
|
||||||
|
swapImage: {
|
||||||
|
// Deploy to netlify
|
||||||
|
deploy: netlify.#Deploy & {
|
||||||
|
team: "blocklayer"
|
||||||
|
token: common.token
|
||||||
|
site: "dagger-test"
|
||||||
|
contents: common.data.output
|
||||||
|
container: input: customImage.output
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the website was deployed
|
customImage: docker.#Build & {
|
||||||
verify: bash.#Run & {
|
steps: [
|
||||||
input: image.output
|
docker.#Pull & {
|
||||||
script: contents: #"""
|
source: "alpine"
|
||||||
test "$(curl \#(deploy.deployUrl))" = "\#(marker)"
|
},
|
||||||
"""#
|
docker.#Run & {
|
||||||
|
command: {
|
||||||
|
name: "apk"
|
||||||
|
args: [
|
||||||
|
"add",
|
||||||
|
"--no-cache",
|
||||||
|
"yarn",
|
||||||
|
"bash",
|
||||||
|
"rsync",
|
||||||
|
"curl",
|
||||||
|
"jq",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
docker.#Run & {
|
||||||
|
command: {
|
||||||
|
name: "yarn"
|
||||||
|
args: ["global", "add", "netlify-cli"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
verify: testutils.#AssertURL & {
|
||||||
|
url: deploy.deployUrl
|
||||||
|
contents: common.marker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
pkg/universe.dagger.io/netlify/test/testutils/testutils.cue
Normal file
26
pkg/universe.dagger.io/netlify/test/testutils/testutils.cue
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package testutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"universe.dagger.io/bash"
|
||||||
|
"universe.dagger.io/alpine"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Assert the text contents available at a URL
|
||||||
|
#AssertURL: {
|
||||||
|
url: string
|
||||||
|
contents: string
|
||||||
|
|
||||||
|
run: bash.#Run & {
|
||||||
|
input: image.output
|
||||||
|
script: "contents": """
|
||||||
|
test "$(curl \(url))" = "\(contents)"
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
image: alpine.#Build & {
|
||||||
|
packages: {
|
||||||
|
bash: {}
|
||||||
|
curl: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user