cue modules: move stdlib to pkg/alpha.dagger.io

In preparation for Europa, we will vendor multiple CUE modules:

- `pkg/alpha.dagger.io`: legacy non-europa packages
- `pkg/dagger.io`: core Europa packages
- `pkg/universe.dagger.io`: Europa universe

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2022-01-11 12:40:02 -08:00
parent e5316f3a1e
commit 282759c0e5
277 changed files with 33 additions and 31 deletions

View File

@@ -0,0 +1,91 @@
// Netlify client operations
package netlify
import (
"alpha.dagger.io/dagger"
"alpha.dagger.io/alpine"
"alpha.dagger.io/os"
)
// Netlify account credentials
#Account: {
// Use this Netlify account name
// (also referred to as "team" in the Netlify docs)
name: string | *"" @dagger(input)
// Netlify authentication token
token: dagger.#Secret @dagger(input)
}
// Netlify site
#Site: {
// Netlify account this site is attached to
account: #Account
// Contents of the application to deploy
contents: dagger.#Artifact @dagger(input)
// Deploy to this Netlify site
name: string @dagger(input)
// Host the site at this address
customDomain?: string @dagger(input)
// Create the Netlify site if it doesn't exist?
create: bool | *true @dagger(input)
// Website url
url: {
os.#File & {
from: ctr
path: "/netlify/url"
}
}.contents @dagger(output)
// Unique Deploy URL
deployUrl: {
os.#File & {
from: ctr
path: "/netlify/deployUrl"
}
}.contents @dagger(output)
// Logs URL for this deployment
logsUrl: {
os.#File & {
from: ctr
path: "/netlify/logsUrl"
}
}.contents @dagger(output)
ctr: os.#Container & {
image: alpine.#Image & {
package: {
bash: true
jq: true
curl: true
yarn: true
}
}
setup: [
"yarn global add netlify-cli@8.6.1",
]
// set in netlify.sh.cue
// FIXME: use embedding once cue supports it
command: _
always: true
env: {
NETLIFY_SITE_NAME: name
if (create) {
NETLIFY_SITE_CREATE: "1"
}
if customDomain != _|_ {
NETLIFY_DOMAIN: customDomain
}
NETLIFY_ACCOUNT: account.name
}
dir: "/src"
mount: "/src": from: contents
secret: "/run/secrets/token": account.token
}
}

View File

@@ -0,0 +1,56 @@
package netlify
#Site: ctr: command: #"""
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="$(cat /tmp/stdout | grep Website | grep -Eo 'https://[^ >]+' | head -1)"
deployUrl="$(cat /tmp/stdout | grep Unique | grep -Eo 'https://[^ >]+' | head -1)"
logsUrl="$(cat /tmp/stdout | grep Logs | grep -Eo 'https://[^ >]+' | head -1)"
# Write output files
mkdir -p /netlify
printf "$url" > /netlify/url
printf "$deployUrl" > /netlify/deployUrl
printf "$logsUrl" > /netlify/logsUrl
"""#

View File

@@ -0,0 +1,50 @@
package netlify
import (
"alpha.dagger.io/dagger/op"
"alpha.dagger.io/alpine"
"alpha.dagger.io/random"
)
TestNetlify: {
data: random.#String & {
seed: ""
}
// Generate a website containing the random number
html: #up: [
op.#WriteFile & {
content: data.out
dest: "index.html"
},
]
// Deploy to netlify
deploy: #Site & {
contents: html
name: "dagger-test"
}
// Check if the deployed site has the random marker
check: #up: [
op.#Load & {
from: alpine.#Image & {
package: bash: true
package: curl: true
}
},
op.#Exec & {
args: [
"/bin/bash",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"-c",
#"""
test "$(curl \#(deploy.deployUrl))" = "\#(data.out)"
"""#,
]
},
]
}