Merge pull request #1424 from aluzzardi/fix-yarn

Europa yarn fixes and tests
This commit is contained in:
Sam Alba 2022-01-19 11:40:02 -08:00 committed by GitHub
commit 44335b5818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 134 additions and 35 deletions

View File

@ -0,0 +1 @@
module: "dagger.io"

View File

@ -22,14 +22,16 @@ let defaultVersion = "3.13.5@sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145
source: "index.docker.io/alpine:\(version)"
},
for pkgName, pkg in packages {
run: cmd: {
docker.#Run & {
cmd: {
name: "apk"
args: ["add", "\(pkgName)\(version)"]
args: ["add", "\(pkgName)\(pkg.version)"]
flags: {
"-U": true
"--no-cache": true
}
}
}
},
]
}

View File

@ -0,0 +1,5 @@
# generated by dagger
dagger.lock
alpha.dagger.io
dagger.io
universe.dagger.io

View File

@ -1 +0,0 @@
../../../stdlib

View File

@ -0,0 +1,80 @@
package yarn
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/yarn"
// "universe.dagger.io/alpine"
// "universe.dagger.io/bash"
)
dagger.#Plan & {
inputs: directories: {
testdata: path: "./testdata"
testdata2: path: "./testdata2"
}
actions: {
TestReact: {
cache: engine.#CacheDir & {
id: "yarn cache"
}
pkg: yarn.#Build & {
source: inputs.directories.testdata.contents
"cache": cache
}
_image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
// FIXME: use bash.#Script
test: engine.#Exec & {
input: _image.output
mounts: build: {
dest: "/build"
contents: pkg.output
}
args: [
"sh", "-c",
#"""
test "$(cat /build/test)" = "output"
"""#,
]
}
}
// FIXME: re-enable?
// TestSecretsAndFile: {
// pkg: #Package & {
// source: inputs.directories.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

@ -1,11 +0,0 @@
package yarn
import (
"dagger.io/dagger/engine"
)
b: #Build & {
source: engine.#Scratch
}
out: b.output

View File

@ -30,28 +30,51 @@ import (
// Run this yarn script
script: string | *"build"
// Fix for shadowing issues
let yarnScript = script
// Cache to use, passed by the caller
cache: engine.#CacheDir
// Optional arguments for the script
args: [...string] | *[]
// Secret variables
// FIXME: not implemented. Are they needed?
secrets: [string]: dagger.#Secret
// FIXME: Yarn's version depends on Alpine's version
// Yarn version
yarnVersion: *"=~1.22" | string
// yarnVersion: *"=~1.22" | string
// FIXME: custom base image not supported
image: alpine.#Build & {
packages: {
bash: {}
yarn: {}
}
}
// Run yarn in a containerized build environment
command: bash.#Run & {
*{
image: (alpine.#Build & {
bash: version: "=~5.1"
yarn: version: yarnVersion
}).image
env: CUSTOM_IMAGE: "0"
} | {
env: CUSTOM_IMAGE: "1"
}
// FIXME: not working?
// *{
// _image: alpine.#Build & {
// packages: {
// bash: version: "=~5.1"
// yarn: version: yarnVersion
// }
// }
script: """
// image: _image.output
// env: CUSTOM_IMAGE: "0"
// } | {
// env: CUSTOM_IMAGE: "1"
// }
"image": image.output
script: #"""
# Create $ENVFILE_NAME file if set
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
@ -60,12 +83,12 @@ import (
opts=( $(echo $YARN_ARGS) )
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
mv "$YARN_BUILD_DIRECTORY" /build
"""
"""#
mounts: {
"yarn cache": {
dest: "/cache/yarn"
contents: engine.#CacheDir
contents: cache
}
"package source": {
dest: "/src"
@ -74,10 +97,10 @@ import (
// FIXME: mount secrets
}
output: directories: "/build": _
export: directories: "/build": _
env: {
YARN_BUILD_SCRIPT: script
YARN_BUILD_SCRIPT: yarnScript
YARN_ARGS: strings.Join(args, "\n")
YARN_CACHE_FOLDER: "/cache/yarn"
YARN_CWD: cwd
@ -92,5 +115,5 @@ import (
}
// The final contents of the package after build
output: command.output.directories."/build".contents
output: command.export.directories."/build".contents
}

View File

@ -84,7 +84,7 @@ func (c *fsContext) FromValue(v *compiler.Value) (*FS, error) {
id, err := v.LookupPath(fsIDPath).String()
if err != nil {
return nil, fmt.Errorf("invalid FS %q: %w", v.Path(), err)
return nil, fmt.Errorf("invalid FS at path %q: %w", v.Path(), err)
}
fs, ok := c.store[id]