2021-05-13 01:32:02 +02:00
|
|
|
// Yarn is a package manager for Javascript applications
|
|
|
|
// https://yarnpkg.com
|
|
|
|
package yarn
|
2021-04-07 18:57:39 +02:00
|
|
|
|
|
|
|
import (
|
2021-04-13 23:10:14 +02:00
|
|
|
"strings"
|
|
|
|
|
2021-04-07 18:57:39 +02:00
|
|
|
"dagger.io/dagger"
|
|
|
|
"dagger.io/alpine"
|
2021-05-06 08:53:04 +02:00
|
|
|
"dagger.io/os"
|
2021-04-07 18:57:39 +02:00
|
|
|
)
|
|
|
|
|
2021-05-13 01:32:02 +02:00
|
|
|
// A Yarn package.
|
|
|
|
#Package: {
|
2021-04-07 18:57:39 +02:00
|
|
|
// Application source code
|
2021-05-26 12:23:44 +02:00
|
|
|
source: dagger.#Artifact @dagger(input)
|
2021-04-07 18:57:39 +02:00
|
|
|
|
2021-05-29 10:21:52 +02:00
|
|
|
// Extra alpine packages to install
|
|
|
|
package: {
|
|
|
|
[string]: true | false | string @dagger(input)
|
|
|
|
}
|
|
|
|
|
|
|
|
// working directory to use
|
|
|
|
cwd: *"." | string @dagger(input)
|
|
|
|
|
2021-04-13 23:10:14 +02:00
|
|
|
// Environment variables
|
2021-05-26 12:28:24 +02:00
|
|
|
env: {
|
|
|
|
[string]: string @dagger(input)
|
|
|
|
}
|
2021-04-13 23:10:14 +02:00
|
|
|
|
|
|
|
// Write the contents of `environment` to this file,
|
|
|
|
// in the "envfile" format.
|
2021-05-26 12:23:44 +02:00
|
|
|
writeEnvFile: string | *"" @dagger(input)
|
2021-04-13 23:10:14 +02:00
|
|
|
|
2021-05-13 01:32:02 +02:00
|
|
|
// Read build output from this directory
|
|
|
|
// (path must be relative to working directory).
|
2021-05-26 12:23:44 +02:00
|
|
|
buildDir: string | *"build" @dagger(input)
|
2021-04-07 18:57:39 +02:00
|
|
|
|
2021-05-13 01:32:02 +02:00
|
|
|
// Run this yarn script
|
2021-05-26 12:23:44 +02:00
|
|
|
script: string | *"build" @dagger(input)
|
2021-04-07 18:57:39 +02:00
|
|
|
|
2021-05-29 10:21:52 +02:00
|
|
|
// Optional arguments for the script
|
|
|
|
args: [...string] | *[] @dagger(input)
|
|
|
|
|
2021-05-06 08:53:04 +02:00
|
|
|
build: os.#Dir & {
|
|
|
|
from: ctr
|
|
|
|
path: "/build"
|
2021-05-26 12:23:44 +02:00
|
|
|
} @dagger(output)
|
2021-05-06 08:53:04 +02:00
|
|
|
|
|
|
|
ctr: os.#Container & {
|
|
|
|
image: alpine.#Image & {
|
2021-05-29 10:21:52 +02:00
|
|
|
"package": package & {
|
2021-05-06 08:53:04 +02:00
|
|
|
bash: "=~5.1"
|
|
|
|
yarn: "=~1.22"
|
2021-04-13 23:10:14 +02:00
|
|
|
}
|
2021-05-06 08:53:04 +02:00
|
|
|
}
|
|
|
|
shell: path: "/bin/bash"
|
|
|
|
command: """
|
|
|
|
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
|
2021-05-29 10:21:52 +02:00
|
|
|
yarn --cwd "$YARN_CWD" install --production false
|
|
|
|
|
|
|
|
opts=( $(echo $YARN_ARGS) )
|
|
|
|
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
|
2021-05-06 08:53:04 +02:00
|
|
|
mv "$YARN_BUILD_DIRECTORY" /build
|
|
|
|
"""
|
|
|
|
"env": env & {
|
2021-05-13 01:32:02 +02:00
|
|
|
YARN_BUILD_SCRIPT: script
|
2021-05-29 10:21:52 +02:00
|
|
|
YARN_ARGS: strings.Join(args, "\n")
|
2021-05-06 08:53:04 +02:00
|
|
|
YARN_CACHE_FOLDER: "/cache/yarn"
|
2021-05-29 10:21:52 +02:00
|
|
|
YARN_CWD: cwd
|
2021-05-13 01:32:02 +02:00
|
|
|
YARN_BUILD_DIRECTORY: buildDir
|
2021-05-06 08:53:04 +02:00
|
|
|
if writeEnvFile != "" {
|
|
|
|
ENVFILE_NAME: writeEnvFile
|
|
|
|
ENVFILE: strings.Join([ for k, v in env {"\(k)=\(v)"}], "\n")
|
2021-04-13 23:10:14 +02:00
|
|
|
}
|
2021-05-06 08:53:04 +02:00
|
|
|
}
|
|
|
|
dir: "/src"
|
|
|
|
mount: "/src": from: source
|
|
|
|
cache: "/cache/yarn": true
|
|
|
|
}
|
2021-04-07 18:57:39 +02:00
|
|
|
}
|