From ee621590ff75beac8f5902b240cffc11bfaa2112 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 7 Apr 2021 16:57:39 +0000 Subject: [PATCH] stdlib: dagger.io/js/react Signed-off-by: Solomon Hykes --- examples/react/cue.mod/pkg/dagger.io | 1 + examples/react/main.cue | 11 +--- stdlib/dagger/op/op.cue | 2 +- stdlib/js/react/react.cue | 66 +++++++++++++++++++ stdlib/yarn/yarn.cue | 63 ------------------ tests/stdlib/js/react/react.cue | 39 +++++++++++ .../{yarn => js/react}/testdata/package.json | 0 tests/stdlib/yarn/yarn.cue | 36 ---------- tests/test-stdlib.sh | 4 +- 9 files changed, 112 insertions(+), 110 deletions(-) create mode 120000 examples/react/cue.mod/pkg/dagger.io create mode 100644 stdlib/js/react/react.cue delete mode 100644 stdlib/yarn/yarn.cue create mode 100644 tests/stdlib/js/react/react.cue rename tests/stdlib/{yarn => js/react}/testdata/package.json (100%) delete mode 100644 tests/stdlib/yarn/yarn.cue diff --git a/examples/react/cue.mod/pkg/dagger.io b/examples/react/cue.mod/pkg/dagger.io new file mode 120000 index 00000000..1aafa4de --- /dev/null +++ b/examples/react/cue.mod/pkg/dagger.io @@ -0,0 +1 @@ +../../../../stdlib \ No newline at end of file diff --git a/examples/react/main.cue b/examples/react/main.cue index 4a96ee67..01f0bce9 100644 --- a/examples/react/main.cue +++ b/examples/react/main.cue @@ -2,7 +2,7 @@ package main import ( "dagger.io/netlify" - "dagger.io/yarn" + "dagger.io/js/react" "dagger.io/git" ) @@ -19,14 +19,9 @@ www: netlify.#Site & { // Deploy the output of yarn build // (Netlify build feature is not used, to avoid extra cost). - contents: build + contents: app.build } -// Build the application with Yarn -build: yarn.#Script & { - // What to build +app: react.#App & { source: repo - - // How to build it (name of yarn script) - run: "build" } diff --git a/stdlib/dagger/op/op.cue b/stdlib/dagger/op/op.cue index 6a30148f..d48943a3 100644 --- a/stdlib/dagger/op/op.cue +++ b/stdlib/dagger/op/op.cue @@ -38,7 +38,7 @@ package op #Subdir: { do: "subdir" - dir: string | *"/" + dir: string } #Exec: { diff --git a/stdlib/js/react/react.cue b/stdlib/js/react/react.cue new file mode 100644 index 00000000..420e1452 --- /dev/null +++ b/stdlib/js/react/react.cue @@ -0,0 +1,66 @@ +package react + +import ( + "dagger.io/dagger" + "dagger.io/alpine" + "dagger.io/docker" +) + +// A ReactJS application +#App: { + // Application source code + source: dagger.#Artifact + + // Yarn-specific settings + yarn: { + // Read build output from this directory + // (path must be relative to working directory). + buildDir: string | *"build" + + // Run this yarn script + script: string | *"build" + } + setup: [ + "mkdir -p /cache/yarn", + ] + + // Build the application in a container, using yarn + build: docker.#Container & { + image: alpine.#Image & { + package: bash: "=~5.1" + package: yarn: "=~1.22" + } + dir: "/src" + command: """ + yarn install --production false + yarn run "$YARN_BUILD_SCRIPT" + mv "$YARN_BUILD_DIRECTORY" \(outputDir) + """ + volume: { + src: { + from: source + dest: "/src" + } + // yarnCache: { + // type: "cache" + // dest: "/cache/yarn" + // } + } + outputDir: "/build" + shell: { + path: "/bin/bash" + args: [ + "--noprofile", + "--norc", + "-eo", "pipefail", + "-c", + ] + } + env: { + YARN_BUILD_SCRIPT: yarn.script + YARN_CACHE_FOLDER: "/cache/yarn" + YARN_BUILD_DIRECTORY: yarn.buildDir + } + } + +} diff --git a/stdlib/yarn/yarn.cue b/stdlib/yarn/yarn.cue deleted file mode 100644 index 66481d8e..00000000 --- a/stdlib/yarn/yarn.cue +++ /dev/null @@ -1,63 +0,0 @@ -package yarn - -import ( - "dagger.io/dagger" - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -// Yarn Script -#Script: { - // Source code of the javascript application - source: dagger.#Artifact - - // Run this yarn script - run: string | *"build" - - // Read build output from this directory - // (path must be relative to working directory). - buildDirectory: string | *"build" - - // Set these environment variables during the build - env?: [string]: string - - #up: [ - op.#Load & { - from: alpine.#Image & { - package: bash: "=~5.1" - package: yarn: "=~1.22" - } - }, - op.#Exec & { - args: [ - "/bin/bash", - "--noprofile", - "--norc", - "-eo", - "pipefail", - "-c", - """ - yarn install --production false - yarn run "$YARN_BUILD_SCRIPT" - mv "$YARN_BUILD_DIRECTORY" /build - """, - ] - if env != _|_ { - "env": env - } - "env": { - YARN_BUILD_SCRIPT: run - YARN_CACHE_FOLDER: "/cache/yarn" - YARN_BUILD_DIRECTORY: buildDirectory - } - dir: "/src" - mount: { - "/src": from: source - "/cache/yarn": "cache" - } - }, - op.#Subdir & { - dir: "/build" - }, - ] -} diff --git a/tests/stdlib/js/react/react.cue b/tests/stdlib/js/react/react.cue new file mode 100644 index 00000000..5fb6530c --- /dev/null +++ b/tests/stdlib/js/react/react.cue @@ -0,0 +1,39 @@ +package react + +import ( + "dagger.io/dagger" + "dagger.io/js/react" + "dagger.io/alpine" + "dagger.io/docker" +) + +TestData: dagger.#Artifact + +TestReact: { + app: react.#App & { + source: TestData + } + + test: docker.#Container & { + image: alpine.#Image & { + package: bash: "=5.1.0-r0" + } + volume: build: { + from: app.build + dest: "/build" + } + command: """ + test "$(cat /build/test)" = "output" + """ + shell: { + path: "/bin/bash" + args: [ + "--noprofile", + "--norc", + "-eo", + "pipefail", + "-c", + ] + } + } +} diff --git a/tests/stdlib/yarn/testdata/package.json b/tests/stdlib/js/react/testdata/package.json similarity index 100% rename from tests/stdlib/yarn/testdata/package.json rename to tests/stdlib/js/react/testdata/package.json diff --git a/tests/stdlib/yarn/yarn.cue b/tests/stdlib/yarn/yarn.cue deleted file mode 100644 index 8c566d40..00000000 --- a/tests/stdlib/yarn/yarn.cue +++ /dev/null @@ -1,36 +0,0 @@ -package yarn - -import ( - "dagger.io/dagger" - "dagger.io/yarn" - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -TestData: dagger.#Artifact - -TestYarn: { - run: yarn.#Script & { - source: TestData - } - - test: #up: [ - op.#Load & {from: alpine.#Image & { - package: bash: "=5.1.0-r0" - }}, - op.#Exec & { - mount: "/build": from: run - args: [ - "/bin/bash", - "--noprofile", - "--norc", - "-eo", - "pipefail", - "-c", - """ - test "$(cat /build/test)" = "output" - """, - ] - }, - ] -} diff --git a/tests/test-stdlib.sh b/tests/test-stdlib.sh index 40eac0ab..dec4623a 100644 --- a/tests/test-stdlib.sh +++ b/tests/test-stdlib.sh @@ -9,8 +9,8 @@ test::stdlib(){ test::one "stdlib: alpine" \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/stdlib/alpine - test::one "stdlib: yarn" \ - "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/stdlib/yarn --input-dir TestData="$d"/stdlib/yarn/testdata + test::one "stdlib: react" \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/stdlib/js/react --input-dir TestData="$d"/stdlib/js/react/testdata test::one "stdlib: go" \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/stdlib/go --input-dir TestData="$d"/stdlib/go/testdata test::one "stdlib: file" \