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,11 @@
{
"name": "test",
"main": "index.js",
"license": {
"type": "Apache-2.0",
"url": "https://opensource.org/licenses/apache2.0.php"
},
"scripts": {
"build": "mkdir -p ./build && echo output > ./build/test && touch .env && cp .env ./build/"
}
}

View File

@@ -0,0 +1,12 @@
{
"name": "test",
"main": "index.js",
"license": {
"type": "Apache-2.0",
"url": "https://opensource.org/licenses/apache2.0.php"
},
"scripts": {
"build": "mkdir -p ./build && cp /.env ./build/env"
}
}

View File

@@ -0,0 +1,57 @@
package yarn
import (
"alpha.dagger.io/dagger"
"alpha.dagger.io/alpine"
"alpha.dagger.io/os"
)
TestData: dagger.#Artifact
TestReact: {
pkg: #Package & {
source: TestData
}
test: os.#Container & {
image: alpine.#Image & {
package: bash: true
}
mount: "/build": from: pkg.build
command: """
test "$(cat /build/test)" = "output"
"""
}
}
TestData2: dagger.#Artifact
TestSecretsAndFile: {
pkg: #Package & {
source: TestData2
writeEnvFile: "/.env"
env: {
one: "one"
two: "two"
}
secrets: {
secretone: dagger.#Secret @dagger(input)
secretwo: dagger.#Secret @dagger(input)
}
}
test: os.#Container & {
image: alpine.#Image & {
package: bash: true
}
shell: path: "/bin/bash"
mount: "/build": from: pkg.build
command: """
content="$(cat /build/env)"
[[ "${content}" = *"SECRETONE="* ]] && \\
[[ "${content}" = *"SECRETWO="* ]] && \\
[[ "${content}" = *"ONE=one"* ]] && \\
[[ "${content}" = *"TWO=two"* ]]
"""
}
}

View File

@@ -0,0 +1,100 @@
// Yarn is a package manager for Javascript applications
package yarn
import (
"strings"
"alpha.dagger.io/dagger"
"alpha.dagger.io/alpine"
"alpha.dagger.io/os"
)
// A Yarn package
#Package: {
// Application source code
source: dagger.#Artifact @dagger(input)
// Extra alpine packages to install
package: {
[string]: true | false | string
} @dagger(input)
// working directory to use
cwd: *"." | string @dagger(input)
// Environment variables
env: {
[string]: string
} @dagger(input)
// Write the contents of `environment` to this file,
// in the "envfile" format
writeEnvFile: string | *"" @dagger(input)
// Read build output from this directory
// (path must be relative to working directory)
buildDir: string | *"build" @dagger(input)
// Run this yarn script
script: string | *"build" @dagger(input)
// Optional arguments for the script
args: [...string] | *[] @dagger(input)
// Secret variables
secrets: [string]: dagger.#Secret
// Build output directory
build: os.#Dir & {
from: ctr
path: "/build"
} @dagger(output)
ctr: os.#Container & {
image: alpine.#Image & {
"package": package & {
bash: true
yarn: true
}
}
shell: path: "/bin/bash"
command: """
# Create $ENVFILE_NAME file if set
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
# Safely export secrets, or prepend them to $ENVFILE_NAME if set
shopt -s dotglob
for FILE in /tmp/secrets/*; do
val=$(echo "${FILE##*/}" | tr '[:lower:]' '[:upper:]') # Collect name
path=$(cat "$FILE") # Collect value
# Prepend
[ -n "$ENVFILE_NAME" ] && echo "$val=$path"$'\n'"$(cat "$ENVFILE_NAME")" > "$ENVFILE_NAME" \\
|| export "$val"="$path" # Or export
done
# Execute
yarn --cwd "$YARN_CWD" install --production false
opts=( $(echo $YARN_ARGS) )
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
mv "$YARN_BUILD_DIRECTORY" /build
"""
"env": env & {
YARN_BUILD_SCRIPT: script
YARN_ARGS: strings.Join(args, "\n")
YARN_CACHE_FOLDER: "/cache/yarn"
YARN_CWD: cwd
YARN_BUILD_DIRECTORY: buildDir
if writeEnvFile != "" {
ENVFILE_NAME: writeEnvFile
ENVFILE: strings.Join([ for k, v in env {"\(k)=\(v)"}], "\n")
}
}
for name, s in secrets {
secret: "/tmp/secrets/\(name)": s
}
dir: "/src"
mount: "/src": from: source
cache: "/cache/yarn": true
}
}