Europa: integrate core packages, separate universe

Signed-off-by: Solomon Hykes <solomon@dagger.io>
This commit is contained in:
Solomon Hykes
2021-12-14 00:16:12 +00:00
parent dd4c360a7b
commit c1c585bcd5
57 changed files with 612 additions and 142 deletions

View File

@@ -0,0 +1 @@
deploy.sh.cue

View File

@@ -0,0 +1,56 @@
package netlify
_deployScript: #"""
export NETLIFY_AUTH_TOKEN="$(cat /run/secrets/token)"
create_site() {
url="https://api.netlify.com/api/v1/${NETLIFY_ACCOUNT:-}/sites"
response=$(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
)
if [ $? -ne 0 ]; then
cat body >&2
exit 1
fi
cat body | 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 link --id "$site_id"
netlify build
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')
# Write output files
mkdir -p /netlify
printf "$url" > /netlify/url
printf "$deployUrl" > /netlify/deployUrl
printf "$logsUrl" > /netlify/logsUrl
"""#

View File

@@ -0,0 +1,99 @@
// Deploy to Netlify
// https://netlify.com
package netlify
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
)
// Deploy a site to Netlify
#Deploy: {
// Contents of the site
contents: dagger.#FS
// Name of the Netlify site
// Example: "my-super-site"
site: string
// Netlify API token
token: dagger.#Secret
// Name of the Netlify team (optional)
// Example: "acme-inc"
// Default: use the Netlify account's default team
team: string | *""
// Domain at which the site should be available (optional)
// If not set, Netlify will allocate one under netlify.app.
// Example: "www.mysupersite.tld"
domain: string | *null
// Create the site if it doesn't exist
create: *true | false
// Execute `netlify deploy` in a container
command: bash.#Run & {
// Container image. `netlify` must be available in the execution path
*{
_buildDefaultImage: docker.#Build & {
input: alpine.#Build & {
bash: version: "=~5.1"
jq: version: "=~1.6"
curl: {}
yarn: version: "=~1.22"
}
steps: [{
run: script: "yarn global add netlify-cli@3.38.10"
}]
}
// No nested tasks, boo hoo hoo
image: _buildDefaultImage.output
env: CUSTOM_IMAGE: "0"
} | {
env: CUSTOM_IMAGE: "1"
}
script: _deployScript // see deploy.sh
always: true
env: {
NETLIFY_SITE_NAME: site
if (create) {
NETLIFY_SITE_CREATE: "1"
}
if domain != null {
NETLIFY_DOMAIN: domain
}
NETLIFY_ACCOUNT: team
}
workdir: "/src"
mounts: {
"Site contents": {
dest: "/src"
"contents": contents
}
"Netlify token": {
dest: "/run/secrets/token"
contents: token
}
}
output: files: {
"/netlify/url": _
"/netlify/deployUrl": _
"/netlify/logsUrl": _
}
}
// URL of the deployed site
url: command.output.files."/netlify/url".contents
// URL of the latest deployment
deployUrl: command.output.files."/netlify/deployUrl".contents
// URL for logs of the latest deployment
logsUrl: command.output.files."/netlify/logsUrl".contents
}

View File

@@ -0,0 +1,9 @@
package netlify
import (
"dagger.io/dagger"
)
deploy: #Deploy & {
contents: dagger.#Scratch
}