stdlib: netlify: use docker.#Container
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
parent
4318aeb323
commit
00710fe387
@ -3,7 +3,7 @@ package netlify
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/alpine"
|
||||
"dagger.io/dagger/op"
|
||||
"dagger.io/docker"
|
||||
)
|
||||
|
||||
// A Netlify account
|
||||
@ -42,28 +42,34 @@ import (
|
||||
// Logs URL for this deployment
|
||||
logsUrl: string
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: alpine.#Image & {
|
||||
package: bash: "=~5.1"
|
||||
package: jq: "=~1.6"
|
||||
package: curl: "=~7.74"
|
||||
package: yarn: "=~1.22"
|
||||
// Deployment container
|
||||
#deploy: docker.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: {
|
||||
bash: "=~5.1"
|
||||
jq: "=~1.6"
|
||||
curl: "=~7.74"
|
||||
yarn: "=~1.22"
|
||||
}
|
||||
},
|
||||
op.#Exec & {
|
||||
args: ["yarn", "global", "add", "netlify-cli@2.47.0"]
|
||||
},
|
||||
op.#Exec & {
|
||||
}
|
||||
setup: [
|
||||
"yarn global add netlify-cli@2.47.0",
|
||||
]
|
||||
shell: {
|
||||
path: "/bin/bash"
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
code,
|
||||
]
|
||||
}
|
||||
dir: "/src"
|
||||
volume: "contents": {
|
||||
dest: "/src"
|
||||
from: contents
|
||||
}
|
||||
env: {
|
||||
NETLIFY_SITE_NAME: name
|
||||
if (create) {
|
||||
@ -75,61 +81,13 @@ import (
|
||||
NETLIFY_ACCOUNT: account.name
|
||||
NETLIFY_AUTH_TOKEN: account.token
|
||||
}
|
||||
dir: "/src"
|
||||
mount: "/src": from: contents
|
||||
},
|
||||
op.#Export & {
|
||||
export: {
|
||||
source: "/output.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" \
|
||||
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
|
||||
"""#
|
||||
// FIXME: this is a hack to use docker.#Container while exporting
|
||||
// values.
|
||||
#up: #deploy.#up
|
||||
}
|
||||
|
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