No more runtime spec validation
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
62
stdlib/cue.mod/pkg/dagger.cloud/dagger/dagger.cue
Normal file
62
stdlib/cue.mod/pkg/dagger.cloud/dagger/dagger.cue
Normal file
@@ -0,0 +1,62 @@
|
||||
package dagger
|
||||
|
||||
|
||||
// Any component can be referenced as a directory, since
|
||||
// every dagger script outputs a filesystem state (aka a directory)
|
||||
#Dir: #dagger: compute: [...#Op]
|
||||
|
||||
// One operation in a script
|
||||
#Op: #FetchContainer | #FetchGit | #Export | #Exec | #Local | #Copy | #Load | #Subdir
|
||||
|
||||
// Export a value from fs state to cue
|
||||
#Export: {
|
||||
do: "export"
|
||||
// Source path in the container
|
||||
source: string
|
||||
format: "json" | "yaml" | *"string"
|
||||
}
|
||||
|
||||
#Local: {
|
||||
do: "local"
|
||||
dir: string
|
||||
include: [...string] | *[]
|
||||
}
|
||||
|
||||
// FIXME: bring back load (more efficient than copy)
|
||||
|
||||
#Load: {
|
||||
do: "load"
|
||||
from: _
|
||||
}
|
||||
|
||||
#Subdir: {
|
||||
do: "subdir"
|
||||
dir: string | *"/"
|
||||
}
|
||||
|
||||
#Exec: {
|
||||
do: "exec"
|
||||
args: [...string]
|
||||
env?: [string]: string
|
||||
always?: true | *false
|
||||
dir: string | *"/"
|
||||
mount: [string]: "tmp" | "cache" | { from: _, path: string | *"/" }
|
||||
}
|
||||
|
||||
#FetchContainer: {
|
||||
do: "fetch-container"
|
||||
ref: string
|
||||
}
|
||||
|
||||
#FetchGit: {
|
||||
do: "fetch-git"
|
||||
remote: string
|
||||
ref: string
|
||||
}
|
||||
|
||||
#Copy: {
|
||||
do: "copy"
|
||||
from: _
|
||||
src: string | *"/"
|
||||
dest: string | *"/"
|
||||
}
|
126
stdlib/cue.mod/pkg/dagger.cloud/netlify/netlify.cue
Normal file
126
stdlib/cue.mod/pkg/dagger.cloud/netlify/netlify.cue
Normal file
@@ -0,0 +1,126 @@
|
||||
package netlify
|
||||
|
||||
import "dagger.cloud/dagger"
|
||||
|
||||
// A Netlify account
|
||||
#Account: {
|
||||
// Use this Netlify account name
|
||||
// (also referred to as "team" in the Netlify docs)
|
||||
name: string | *""
|
||||
|
||||
// Netlify authentication token
|
||||
token: string
|
||||
}
|
||||
|
||||
// A Netlify site
|
||||
#Site: {
|
||||
// Netlify account this site is attached to
|
||||
account: #Account
|
||||
|
||||
// Contents of the application to deploy
|
||||
contents: dagger.#Dir
|
||||
|
||||
// Deploy to this Netlify site
|
||||
name: string
|
||||
|
||||
// Host the site at this address
|
||||
customDomain: string
|
||||
|
||||
// Create the Netlify site if it doesn't exist?
|
||||
create: bool | *true
|
||||
|
||||
// Deployment url
|
||||
url: {
|
||||
string
|
||||
|
||||
#dagger: compute: [
|
||||
dagger.#FetchContainer & {
|
||||
ref: "alpine@sha256:08d6ca16c60fe7490c03d10dc339d9fd8ea67c6466dea8d558526b1330a85930"
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["apk", "add", "-U", "--no-cache", "bash=5.1.0-r0"]
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["apk", "add", "-U", "--no-cache", "jq=1.6-r1"]
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["apk", "add", "-U", "--no-cache", "curl=7.74.0-r0"]
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["apk", "add", "-U", "--no-cache", "yarn=1.22.10-r0"]
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["yarn", "global", "add", "netlify-cli@2.47.0"]
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
code,
|
||||
]
|
||||
env: {
|
||||
NETLIFY_SITE_NAME: name
|
||||
if (create) {
|
||||
NETLIFY_SITE_CREATE: "1"
|
||||
}
|
||||
if customDomain != _|_ {
|
||||
NETLIFY_DOMAIN: customDomain
|
||||
}
|
||||
NETLIFY_ACCOUNT: account.name
|
||||
NETLIFY_AUTH_TOKEN: account.token
|
||||
}
|
||||
dir: "/src"
|
||||
mount: "/src": from: contents
|
||||
},
|
||||
dagger.#Export & {
|
||||
source: "/url"
|
||||
format: "string"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
</tmp/stdout sed -n -e 's/^Website URL:.*\(https:\/\/.*\)$/\1/p' | tr -d '\n' > /url
|
||||
"""#
|
64
stdlib/cue.mod/pkg/dagger.cloud/yarn/yarn.cue
Normal file
64
stdlib/cue.mod/pkg/dagger.cloud/yarn/yarn.cue
Normal file
@@ -0,0 +1,64 @@
|
||||
package yarn
|
||||
|
||||
import (
|
||||
"dagger.cloud/dagger"
|
||||
)
|
||||
|
||||
// Yarn Script
|
||||
#Script: {
|
||||
// Source code of the javascript application
|
||||
source: dagger.#Dir
|
||||
|
||||
// Run this yarn script
|
||||
run: string | *"build"
|
||||
|
||||
// Read build output from this directory
|
||||
// (path must be relative to working directory).
|
||||
buildDirectory: string | *"build"
|
||||
|
||||
// Set these environment variables during the build
|
||||
env?: [string]: string
|
||||
|
||||
#dagger: compute: [
|
||||
dagger.#FetchContainer & {
|
||||
ref: "alpine@sha256:08d6ca16c60fe7490c03d10dc339d9fd8ea67c6466dea8d558526b1330a85930"
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["apk", "add", "-U", "--no-cache", "bash=5.1.0-r0"]
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: ["apk", "add", "-U", "--no-cache", "yarn=1.22.10-r0"]
|
||||
},
|
||||
dagger.#Exec & {
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
"""
|
||||
yarn install --production false
|
||||
yarn run "$YARN_BUILD_SCRIPT"
|
||||
mv "$YARN_BUILD_DIRECTORY" /build
|
||||
""",
|
||||
]
|
||||
if env != _|_ {
|
||||
"env": env
|
||||
}
|
||||
"env": {
|
||||
YARN_BUILD_SCRIPT: run
|
||||
YARN_CACHE_FOLDER: "/cache/yarn"
|
||||
YARN_BUILD_DIRECTORY: buildDirectory
|
||||
}
|
||||
dir: "/src"
|
||||
mount: {
|
||||
"/src": from: source
|
||||
"/cache/yarn": dagger.#MountCache
|
||||
}
|
||||
},
|
||||
dagger.#Subdir & {
|
||||
dir: "/build"
|
||||
},
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user