Merge pull request #1673 from dagger/extract-yarn-install-into-a-separate-step
Extract yarn install into a separate step
This commit is contained in:
commit
5267d72b1d
@ -66,7 +66,7 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
build: yarn.#Build & {
|
build: yarn.#Build & {
|
||||||
source: common.data
|
source: common.data
|
||||||
container: input: buildImage.output
|
container: #input: buildImage.output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,28 +16,26 @@ import (
|
|||||||
script: *"build" | string
|
script: *"build" | string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a Yarn package
|
// Run a Yarn command
|
||||||
#Run: {
|
#Run: {
|
||||||
// Custom name for the build.
|
// Custom name for this command.
|
||||||
// When building different apps in the same plan, assign
|
// Assign an app-specific name if there are multiple apps in the same plan.
|
||||||
// different names for optimal caching.
|
|
||||||
name: string | *""
|
name: string | *""
|
||||||
|
|
||||||
// Application source code
|
// App source code
|
||||||
source: dagger.#FS
|
source: dagger.#FS
|
||||||
|
|
||||||
// working directory to use
|
// Working directory to use
|
||||||
cwd: *"." | string
|
cwd: *"." | string
|
||||||
|
|
||||||
// Write the contents of `environment` to this file,
|
// Write the contents of `environment` to this file, in the "envfile" format
|
||||||
// in the "envfile" format
|
|
||||||
writeEnvFile: string | *""
|
writeEnvFile: string | *""
|
||||||
|
|
||||||
// Read build output from this directory
|
// Optional: Read build output from this directory
|
||||||
// (path must be relative to working directory)
|
// Must be relative to working directory, cwd
|
||||||
buildDir?: string
|
buildDir?: string
|
||||||
|
|
||||||
// Run this yarn script
|
// Yarn script to run for this command.
|
||||||
script: string
|
script: string
|
||||||
|
|
||||||
// Fix for shadowing issues
|
// Fix for shadowing issues
|
||||||
@ -50,29 +48,56 @@ import (
|
|||||||
// FIXME: not implemented. Are they needed?
|
// FIXME: not implemented. Are they needed?
|
||||||
secrets: [string]: dagger.#Secret
|
secrets: [string]: dagger.#Secret
|
||||||
|
|
||||||
|
container: #input: docker.#Image | *{
|
||||||
// FIXME: Yarn's version depends on Alpine's version
|
// FIXME: Yarn's version depends on Alpine's version
|
||||||
// Yarn version
|
// Yarn version
|
||||||
// yarnVersion: *"=~1.22" | string
|
// yarnVersion: *"=~1.22" | string
|
||||||
|
|
||||||
// FIXME: custom base image not supported
|
// FIXME: custom base image not supported
|
||||||
_buildImage: alpine.#Build & {
|
alpine.#Build & {
|
||||||
packages: {
|
packages: {
|
||||||
bash: {}
|
bash: {}
|
||||||
yarn: {}
|
yarn: {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run yarn in a docker container
|
_run: docker.#Build & {
|
||||||
container: bash.#Run & {
|
steps: [
|
||||||
input: *_buildImage.output | docker.#Image
|
container.#input,
|
||||||
|
|
||||||
|
docker.#Copy & {
|
||||||
|
dest: "/src"
|
||||||
|
contents: source
|
||||||
|
},
|
||||||
|
|
||||||
|
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"
|
||||||
|
contents: dagger.#CacheDir & {
|
||||||
|
// 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
|
// FIXME: move shell script to its own file
|
||||||
script: contents: #"""
|
script: contents: #"""
|
||||||
# Create $ENVFILE_NAME file if set
|
# Create $ENVFILE_NAME file if set
|
||||||
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
|
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
|
||||||
|
|
||||||
yarn --cwd "$YARN_CWD" install --production false
|
|
||||||
|
|
||||||
opts=( $(echo $YARN_ARGS) )
|
opts=( $(echo $YARN_ARGS) )
|
||||||
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
|
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
|
||||||
if [ ! -z "${YARN_BUILD_DIRECTORY:-}" ]; then
|
if [ ! -z "${YARN_BUILD_DIRECTORY:-}" ]; then
|
||||||
@ -82,21 +107,13 @@ import (
|
|||||||
fi
|
fi
|
||||||
"""#
|
"""#
|
||||||
|
|
||||||
mounts: {
|
mounts: "yarn cache": {
|
||||||
"yarn cache": {
|
|
||||||
dest: "/cache/yarn"
|
dest: "/cache/yarn"
|
||||||
contents: dagger.#CacheDir & {
|
contents: dagger.#CacheDir & {
|
||||||
// FIXME: are there character limitations in cache ID?
|
// FIXME: are there character limitations in cache ID?
|
||||||
id: "universe.dagger.io/yarn.#Build \(name)"
|
id: "universe.dagger.io/yarn.#Run \(name)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"package source": {
|
|
||||||
dest: "/src"
|
|
||||||
contents: source
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export: directories: "/build": _
|
|
||||||
|
|
||||||
env: {
|
env: {
|
||||||
YARN_BUILD_SCRIPT: yarnScript
|
YARN_BUILD_SCRIPT: yarnScript
|
||||||
@ -113,8 +130,15 @@ import (
|
|||||||
}
|
}
|
||||||
|
|
||||||
workdir: "/src"
|
workdir: "/src"
|
||||||
|
},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// The final contents of the package after build
|
// The final contents of the package after run
|
||||||
output: container.export.directories."/build"
|
_output: dagger.#Subdir & {
|
||||||
|
input: _run.output.rootfs
|
||||||
|
path: "/build"
|
||||||
|
}
|
||||||
|
|
||||||
|
output: _output.output
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user