c3f21958d2
The todoapp example contains a Netlify plan which uses the latest dagger additions: do & Client API. We are thinking of merging the examples repository into this one to make working with this easier. This is a step in that direction. We are not using the yarn package so that we can revert https://github.com/dagger/dagger/pull/1673 without breaking this implementation. The GitHub Action is WIP, we will continue with that tomorrow: https://github.com/dagger/dagger-for-github/issues/24 Signed-off-by: Gerhard Lazu <gerhard@lazu.co.uk>
62 lines
1.5 KiB
Bash
Executable File
62 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e -o pipefail
|
|
|
|
NETLIFY_AUTH_TOKEN="$(cat /run/secrets/token)"
|
|
export NETLIFY_AUTH_TOKEN
|
|
|
|
create_site() {
|
|
url="https://api.netlify.com/api/v1/${NETLIFY_ACCOUNT:-}/sites"
|
|
|
|
curl -s -S --fail-with-body -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
|
|
-X POST -H "Content-Type: application/json" \
|
|
"$url" \
|
|
-d "{\"name\": \"${NETLIFY_SITE_NAME}\", \"custom_domain\": \"${NETLIFY_DOMAIN}\"}" -o body
|
|
|
|
# shellcheck disable=SC2181
|
|
if [ $? -ne 0 ]; then
|
|
cat body >&2
|
|
exit 1
|
|
fi
|
|
|
|
jq -r '.site_id' body
|
|
}
|
|
|
|
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
|
|
else
|
|
echo "clean create site API response..."
|
|
rm -f body
|
|
fi
|
|
fi
|
|
|
|
netlify link --id "$site_id"
|
|
netlify build
|
|
|
|
netlify deploy \
|
|
--dir="$(pwd)" \
|
|
--site="$site_id" \
|
|
--prod \
|
|
| tee /tmp/stdout
|
|
|
|
url="$(</tmp/stdout grep Website | grep -Eo 'https://[^ >]+' | head -1)"
|
|
deployUrl="$(</tmp/stdout grep Unique | grep -Eo 'https://[^ >]+' | head -1)"
|
|
logsUrl="$(</tmp/stdout grep Logs | grep -Eo 'https://[^ >]+' | head -1)"
|
|
|
|
# Write output files
|
|
mkdir -p /netlify
|
|
echo -n "$url" > /netlify/url
|
|
echo -n "$deployUrl" > /netlify/deployUrl
|
|
echo -n "$logsUrl" > /netlify/logsUrl
|