commit
de1d20563d
@ -8,13 +8,21 @@ import (
|
|||||||
|
|
||||||
"dagger.io/dagger"
|
"dagger.io/dagger"
|
||||||
"dagger.io/dagger/op"
|
"dagger.io/dagger/op"
|
||||||
|
|
||||||
|
"dagger.io/alpine"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Default image for basic use cases
|
||||||
|
// FIXME: should just be 'alpine.#Image'.
|
||||||
|
// referring to '#.up' is a workaround to a dagger engine bug.
|
||||||
|
// see https://github.com/dagger/dagger/issues/304
|
||||||
|
#DefaultImage: alpine.#Image.#up
|
||||||
|
|
||||||
// Run a Docker container
|
// Run a Docker container
|
||||||
#Container: {
|
#Container: {
|
||||||
|
|
||||||
// Container image
|
// Container image
|
||||||
image: dagger.#Artifact
|
image: dagger.#Artifact | *#DefaultImage
|
||||||
|
|
||||||
// Independently cacheable setup commands
|
// Independently cacheable setup commands
|
||||||
setup: [...string]
|
setup: [...string]
|
||||||
@ -86,6 +94,12 @@ import (
|
|||||||
}
|
}
|
||||||
env: PATH: string | *strings.Join([ for p, v in shell.search if v {p}], ":")
|
env: PATH: string | *strings.Join([ for p, v in shell.search if v {p}], ":")
|
||||||
|
|
||||||
|
// Export values from the container to the cue configuration
|
||||||
|
export: *null | {
|
||||||
|
source: string
|
||||||
|
format: op.#Export.format
|
||||||
|
}
|
||||||
|
|
||||||
#up: [
|
#up: [
|
||||||
op.#Load & {from: image},
|
op.#Load & {from: image},
|
||||||
// Copy volumes with type=copy
|
// Copy volumes with type=copy
|
||||||
@ -122,5 +136,11 @@ import (
|
|||||||
op.#Subdir & {
|
op.#Subdir & {
|
||||||
dir: outputDir
|
dir: outputDir
|
||||||
},
|
},
|
||||||
|
if export != null {
|
||||||
|
op.#Export & {
|
||||||
|
source: export.source
|
||||||
|
format: export.format
|
||||||
|
}
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package netlify
|
|||||||
import (
|
import (
|
||||||
"dagger.io/dagger"
|
"dagger.io/dagger"
|
||||||
"dagger.io/alpine"
|
"dagger.io/alpine"
|
||||||
"dagger.io/dagger/op"
|
"dagger.io/docker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Netlify account
|
// A Netlify account
|
||||||
@ -42,94 +42,52 @@ import (
|
|||||||
// Logs URL for this deployment
|
// Logs URL for this deployment
|
||||||
logsUrl: string
|
logsUrl: string
|
||||||
|
|
||||||
#up: [
|
// Deployment container
|
||||||
op.#Load & {
|
#deploy: docker.#Container & {
|
||||||
from: alpine.#Image & {
|
image: alpine.#Image & {
|
||||||
package: bash: "=~5.1"
|
package: {
|
||||||
package: jq: "=~1.6"
|
bash: "=~5.1"
|
||||||
package: curl: "=~7.74"
|
jq: "=~1.6"
|
||||||
package: yarn: "=~1.22"
|
curl: "=~7.74"
|
||||||
|
yarn: "=~1.22"
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
op.#Exec & {
|
setup: [
|
||||||
args: ["yarn", "global", "add", "netlify-cli@2.47.0"]
|
"yarn global add netlify-cli@2.47.0",
|
||||||
},
|
]
|
||||||
op.#Exec & {
|
shell: {
|
||||||
|
path: "/bin/bash"
|
||||||
args: [
|
args: [
|
||||||
"/bin/bash",
|
|
||||||
"--noprofile",
|
"--noprofile",
|
||||||
"--norc",
|
"--norc",
|
||||||
"-eo",
|
"-eo",
|
||||||
"pipefail",
|
"pipefail",
|
||||||
"-c",
|
"-c",
|
||||||
code,
|
|
||||||
]
|
]
|
||||||
env: {
|
}
|
||||||
NETLIFY_SITE_NAME: name
|
dir: "/src"
|
||||||
if (create) {
|
volume: "contents": {
|
||||||
NETLIFY_SITE_CREATE: "1"
|
dest: "/src"
|
||||||
}
|
from: contents
|
||||||
if customDomain != _|_ {
|
}
|
||||||
NETLIFY_DOMAIN: customDomain
|
env: {
|
||||||
}
|
NETLIFY_SITE_NAME: name
|
||||||
NETLIFY_ACCOUNT: account.name
|
if (create) {
|
||||||
NETLIFY_AUTH_TOKEN: account.token
|
NETLIFY_SITE_CREATE: "1"
|
||||||
}
|
}
|
||||||
dir: "/src"
|
if customDomain != _|_ {
|
||||||
mount: "/src": from: contents
|
NETLIFY_DOMAIN: customDomain
|
||||||
},
|
}
|
||||||
op.#Export & {
|
NETLIFY_ACCOUNT: account.name
|
||||||
|
NETLIFY_AUTH_TOKEN: account.token
|
||||||
|
}
|
||||||
|
export: {
|
||||||
source: "/output.json"
|
source: "/output.json"
|
||||||
format: "json"
|
format: "json"
|
||||||
},
|
}
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: this should be outside
|
|
||||||
let code = #"""
|
|
||||||
create_site() {
|
|
||||||
url="https://api.netlify.com/api/v1/${NETLIFY_ACCOUNT:-}/sites"
|
|
||||||
|
|
||||||
response=$(curl -s -S -f -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
|
|
||||||
-X POST -H "Content-Type: application/json" \
|
|
||||||
$url \
|
|
||||||
-d "{\"name\": \"${NETLIFY_SITE_NAME}\", \"custom_domain\": \"${NETLIFY_DOMAIN}\"}"
|
|
||||||
)
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo $response | jq -r '.site_id'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
site_id=$(curl -s -S -f -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
|
// FIXME: this is a hack to use docker.#Container while exporting
|
||||||
https://api.netlify.com/api/v1/sites\?filter\=all | \
|
// values.
|
||||||
jq -r ".[] | select(.name==\"$NETLIFY_SITE_NAME\") | .id" \
|
#up: #deploy.#up
|
||||||
)
|
}
|
||||||
if [ -z "$site_id" ] ; then
|
|
||||||
if [ "${NETLIFY_SITE_CREATE:-}" != 1 ]; then
|
|
||||||
echo "Site $NETLIFY_SITE_NAME does not exist"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
site_id=$(create_site)
|
|
||||||
if [ -z "$site_id" ]; then
|
|
||||||
echo "create site failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
netlify deploy \
|
|
||||||
--dir="$(pwd)" \
|
|
||||||
--site="$site_id" \
|
|
||||||
--prod \
|
|
||||||
| tee /tmp/stdout
|
|
||||||
|
|
||||||
url=$(</tmp/stdout sed -n -e 's/^Website URL:.*\(https:\/\/.*\)$/\1/p' | tr -d '\n')
|
|
||||||
deployUrl=$(</tmp/stdout sed -n -e 's/^Unique Deploy URL:.*\(https:\/\/.*\)$/\1/p' | tr -d '\n')
|
|
||||||
logsUrl=$(</tmp/stdout sed -n -e 's/^Logs:.*\(https:\/\/.*\)$/\1/p' | tr -d '\n')
|
|
||||||
|
|
||||||
jq -n \
|
|
||||||
--arg url "$url" \
|
|
||||||
--arg deployUrl "$deployUrl" \
|
|
||||||
--arg logsUrl "$logsUrl" \
|
|
||||||
'{url: $url, deployUrl: $deployUrl, logsUrl: $logsUrl}' > /output.json
|
|
||||||
"""#
|
|
||||||
|
49
stdlib/netlify/netlify.sh.cue
Normal file
49
stdlib/netlify/netlify.sh.cue
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package netlify
|
||||||
|
|
||||||
|
#Site: #deploy: command: #"""
|
||||||
|
create_site() {
|
||||||
|
url="https://api.netlify.com/api/v1/${NETLIFY_ACCOUNT:-}/sites"
|
||||||
|
|
||||||
|
response=$(curl -s -S -f -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
|
||||||
|
-X POST -H "Content-Type: application/json" \
|
||||||
|
$url \
|
||||||
|
-d "{\"name\": \"${NETLIFY_SITE_NAME}\", \"custom_domain\": \"${NETLIFY_DOMAIN}\"}"
|
||||||
|
)
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $response | jq -r '.site_id'
|
||||||
|
}
|
||||||
|
|
||||||
|
site_id=$(curl -s -S -f -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
|
||||||
|
https://api.netlify.com/api/v1/sites\?filter\=all | \
|
||||||
|
jq -r ".[] | select(.name==\"$NETLIFY_SITE_NAME\") | .id" \
|
||||||
|
)
|
||||||
|
if [ -z "$site_id" ] ; then
|
||||||
|
if [ "${NETLIFY_SITE_CREATE:-}" != 1 ]; then
|
||||||
|
echo "Site $NETLIFY_SITE_NAME does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
site_id=$(create_site)
|
||||||
|
if [ -z "$site_id" ]; then
|
||||||
|
echo "create site failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
netlify deploy \
|
||||||
|
--dir="$(pwd)" \
|
||||||
|
--site="$site_id" \
|
||||||
|
--prod \
|
||||||
|
| tee /tmp/stdout
|
||||||
|
|
||||||
|
url=$(</tmp/stdout sed -n -e 's/^Website URL:.*\(https:\/\/.*\)$/\1/p' | tr -d '\n')
|
||||||
|
deployUrl=$(</tmp/stdout sed -n -e 's/^Unique Deploy URL:.*\(https:\/\/.*\)$/\1/p' | tr -d '\n')
|
||||||
|
logsUrl=$(</tmp/stdout sed -n -e 's/^Logs:.*\(https:\/\/.*\)$/\1/p' | tr -d '\n')
|
||||||
|
|
||||||
|
jq -n \
|
||||||
|
--arg url "$url" \
|
||||||
|
--arg deployUrl "$deployUrl" \
|
||||||
|
--arg logsUrl "$logsUrl" \
|
||||||
|
'{url: $url, deployUrl: $deployUrl, logsUrl: $logsUrl}' > /output.json
|
||||||
|
"""#
|
Reference in New Issue
Block a user