stdlib: yarn: support cwd, args and packages

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-05-29 01:21:52 -07:00
parent 3605d399c9
commit 39527b761d

View File

@ -15,6 +15,14 @@ import (
// Application source code // Application source code
source: dagger.#Artifact @dagger(input) 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 // Environment variables
env: { env: {
[string]: string @dagger(input) [string]: string @dagger(input)
@ -31,6 +39,9 @@ import (
// Run this yarn script // Run this yarn script
script: string | *"build" @dagger(input) script: string | *"build" @dagger(input)
// Optional arguments for the script
args: [...string] | *[] @dagger(input)
build: os.#Dir & { build: os.#Dir & {
from: ctr from: ctr
path: "/build" path: "/build"
@ -38,7 +49,7 @@ import (
ctr: os.#Container & { ctr: os.#Container & {
image: alpine.#Image & { image: alpine.#Image & {
package: { "package": package & {
bash: "=~5.1" bash: "=~5.1"
yarn: "=~1.22" yarn: "=~1.22"
} }
@ -46,13 +57,17 @@ import (
shell: path: "/bin/bash" shell: path: "/bin/bash"
command: """ command: """
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME" [ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
yarn install --production false yarn --cwd "$YARN_CWD" install --production false
yarn run "$YARN_BUILD_SCRIPT"
opts=( $(echo $YARN_ARGS) )
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
mv "$YARN_BUILD_DIRECTORY" /build mv "$YARN_BUILD_DIRECTORY" /build
""" """
"env": env & { "env": env & {
YARN_BUILD_SCRIPT: script YARN_BUILD_SCRIPT: script
YARN_ARGS: strings.Join(args, "\n")
YARN_CACHE_FOLDER: "/cache/yarn" YARN_CACHE_FOLDER: "/cache/yarn"
YARN_CWD: cwd
YARN_BUILD_DIRECTORY: buildDir YARN_BUILD_DIRECTORY: buildDir
if writeEnvFile != "" { if writeEnvFile != "" {
ENVFILE_NAME: writeEnvFile ENVFILE_NAME: writeEnvFile