2021-11-04 08:05:24 +01:00
|
|
|
// Yarn is a package manager for Javascript applications
|
|
|
|
package yarn
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"dagger.io/dagger"
|
2022-03-26 16:09:21 +01:00
|
|
|
"dagger.io/dagger/core"
|
2021-11-04 08:05:24 +01:00
|
|
|
|
2022-01-19 18:50:06 +01:00
|
|
|
"universe.dagger.io/alpine"
|
2021-11-04 08:05:24 +01:00
|
|
|
"universe.dagger.io/bash"
|
2022-02-12 08:28:11 +01:00
|
|
|
"universe.dagger.io/docker"
|
2021-11-04 08:05:24 +01:00
|
|
|
)
|
|
|
|
|
2022-02-17 21:28:41 +01:00
|
|
|
#Build: #Run & {
|
|
|
|
buildDir: *"build" | string
|
|
|
|
script: *"build" | string
|
|
|
|
}
|
|
|
|
|
2022-03-01 20:17:13 +01:00
|
|
|
// Run a Yarn command
|
2022-02-17 21:28:41 +01:00
|
|
|
#Run: {
|
2022-03-03 13:39:32 +01:00
|
|
|
// Custom name for this command.
|
|
|
|
// Assign an app-specific name if there are multiple apps in the same plan.
|
2022-02-07 06:57:06 +01:00
|
|
|
name: string | *""
|
|
|
|
|
2022-03-03 13:39:32 +01:00
|
|
|
// App source code
|
2021-11-04 08:05:24 +01:00
|
|
|
source: dagger.#FS
|
|
|
|
|
2022-03-03 13:39:32 +01:00
|
|
|
// Working directory to use
|
2021-11-04 08:05:24 +01:00
|
|
|
cwd: *"." | string
|
|
|
|
|
2022-03-03 13:39:32 +01:00
|
|
|
// Write the contents of `environment` to this file, in the "envfile" format
|
2021-11-04 08:05:24 +01:00
|
|
|
writeEnvFile: string | *""
|
|
|
|
|
2022-03-03 13:39:32 +01:00
|
|
|
// Optional: Read build output from this directory
|
|
|
|
// Must be relative to working directory, cwd
|
2022-02-17 21:28:41 +01:00
|
|
|
buildDir?: string
|
2021-11-04 08:05:24 +01:00
|
|
|
|
2022-03-03 13:39:32 +01:00
|
|
|
// Yarn script to run for this command.
|
2022-02-17 21:28:41 +01:00
|
|
|
script: string
|
2021-11-04 08:05:24 +01:00
|
|
|
|
2022-01-14 02:43:34 +01:00
|
|
|
// Fix for shadowing issues
|
|
|
|
let yarnScript = script
|
|
|
|
|
2021-11-04 08:05:24 +01:00
|
|
|
// Optional arguments for the script
|
|
|
|
args: [...string] | *[]
|
|
|
|
|
|
|
|
// Secret variables
|
2022-01-14 02:43:34 +01:00
|
|
|
// FIXME: not implemented. Are they needed?
|
2021-11-04 08:05:24 +01:00
|
|
|
secrets: [string]: dagger.#Secret
|
|
|
|
|
2022-03-03 13:39:32 +01:00
|
|
|
container: #input: docker.#Image | *{
|
|
|
|
// FIXME: Yarn's version depends on Alpine's version
|
|
|
|
// Yarn version
|
|
|
|
// yarnVersion: *"=~1.22" | string
|
|
|
|
// FIXME: custom base image not supported
|
|
|
|
alpine.#Build & {
|
|
|
|
packages: {
|
|
|
|
bash: {}
|
|
|
|
yarn: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_run: docker.#Build & {
|
2022-03-01 20:17:13 +01:00
|
|
|
steps: [
|
2022-03-03 13:39:32 +01:00
|
|
|
container.#input,
|
2022-03-01 20:17:13 +01:00
|
|
|
|
|
|
|
docker.#Copy & {
|
2021-11-04 08:05:24 +01:00
|
|
|
dest: "/src"
|
|
|
|
contents: source
|
2022-03-01 20:17:13 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
bash.#Run & {
|
|
|
|
// FIXME: move shell script to its own file
|
|
|
|
script: contents: #"""
|
|
|
|
yarn --cwd "$YARN_CWD" install --production false
|
|
|
|
"""#
|
|
|
|
|
|
|
|
mounts: "yarn cache": {
|
|
|
|
dest: "/cache/yarn"
|
2022-03-26 16:09:21 +01:00
|
|
|
contents: core.#CacheDir & {
|
2022-03-01 20:17:13 +01:00
|
|
|
// FIXME: are there character limitations in cache ID?
|
|
|
|
id: "universe.dagger.io/yarn.#Run \(name)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
env: {
|
|
|
|
YARN_CACHE_FOLDER: "/cache/yarn"
|
|
|
|
YARN_CWD: cwd
|
|
|
|
}
|
|
|
|
|
|
|
|
workdir: "/src"
|
|
|
|
},
|
|
|
|
|
|
|
|
bash.#Run & {
|
|
|
|
// FIXME: move shell script to its own file
|
|
|
|
script: contents: #"""
|
|
|
|
# Create $ENVFILE_NAME file if set
|
|
|
|
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
|
|
|
|
|
|
|
|
opts=( $(echo $YARN_ARGS) )
|
|
|
|
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
|
|
|
|
if [ ! -z "${YARN_BUILD_DIRECTORY:-}" ]; then
|
|
|
|
mv "$YARN_BUILD_DIRECTORY" /build
|
|
|
|
else
|
|
|
|
mkdir /build
|
|
|
|
fi
|
|
|
|
"""#
|
|
|
|
|
|
|
|
mounts: "yarn cache": {
|
|
|
|
dest: "/cache/yarn"
|
2022-03-26 16:09:21 +01:00
|
|
|
contents: core.#CacheDir & {
|
2022-03-01 20:17:13 +01:00
|
|
|
// FIXME: are there character limitations in cache ID?
|
|
|
|
id: "universe.dagger.io/yarn.#Run \(name)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
env: {
|
|
|
|
YARN_BUILD_SCRIPT: yarnScript
|
|
|
|
YARN_ARGS: strings.Join(args, "\n")
|
|
|
|
YARN_CACHE_FOLDER: "/cache/yarn"
|
|
|
|
YARN_CWD: cwd
|
|
|
|
if buildDir != _|_ {
|
|
|
|
YARN_BUILD_DIRECTORY: buildDir
|
|
|
|
}
|
|
|
|
if writeEnvFile != "" {
|
|
|
|
ENVFILE_NAME: writeEnvFile
|
|
|
|
ENVFILE: strings.Join([ for k, v in env {"\(k)=\(v)"}], "\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
workdir: "/src"
|
|
|
|
},
|
|
|
|
]
|
2021-11-04 08:05:24 +01:00
|
|
|
}
|
|
|
|
|
2022-03-03 13:39:32 +01:00
|
|
|
// The final contents of the package after run
|
2022-03-26 16:09:21 +01:00
|
|
|
_output: core.#Subdir & {
|
2022-03-03 13:39:32 +01:00
|
|
|
input: _run.output.rootfs
|
2022-03-01 20:17:13 +01:00
|
|
|
path: "/build"
|
|
|
|
}
|
|
|
|
|
|
|
|
output: _output.output
|
2021-11-04 08:05:24 +01:00
|
|
|
}
|