From 89882dbe818934e5655492a1d18574685b5ef3bd Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 13 Apr 2021 14:10:14 -0700 Subject: [PATCH] stdlib/js/react, stdlib/netlify: removed docker.#Container abstraction (gh issue #319) Signed-off-by: Sam Alba --- stdlib/js/react/react.cue | 86 ++++++++++++++++++++--------------- stdlib/netlify/netlify.cue | 69 +++++++++++++--------------- stdlib/netlify/netlify.sh.cue | 2 +- 3 files changed, 81 insertions(+), 76 deletions(-) diff --git a/stdlib/js/react/react.cue b/stdlib/js/react/react.cue index 420e1452..42ea07a8 100644 --- a/stdlib/js/react/react.cue +++ b/stdlib/js/react/react.cue @@ -1,9 +1,11 @@ package react import ( + "strings" + "dagger.io/dagger" + "dagger.io/dagger/op" "dagger.io/alpine" - "dagger.io/docker" ) // A ReactJS application @@ -11,6 +13,13 @@ import ( // Application source code source: dagger.#Artifact + // Environment variables + env: [string]: string + + // Write the contents of `environment` to this file, + // in the "envfile" format. + writeEnvFile: string | *"" + // Yarn-specific settings yarn: { // Read build output from this directory @@ -20,47 +29,50 @@ import ( // 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" + build: #up: [ + op.#Load & { + from: alpine.#Image & { + package: bash: "=~5.1" + package: yarn: "=~1.22" } - // yarnCache: { - // type: "cache" - // dest: "/cache/yarn" - // } - } - outputDir: "/build" - shell: { - path: "/bin/bash" + }, + op.#Exec & { args: [ + "/bin/bash", "--noprofile", "--norc", - "-eo", "pipefail", + "-eo", + "pipefail", "-c", + """ + [ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME" + cat .env + yarn install --production false + yarn run "$YARN_BUILD_SCRIPT" + mv "$YARN_BUILD_DIRECTORY" /build + """, ] - } - env: { - YARN_BUILD_SCRIPT: yarn.script - YARN_CACHE_FOLDER: "/cache/yarn" - YARN_BUILD_DIRECTORY: yarn.buildDir - } - } - + if env != _|_ { + "env": env + } + "env": { + YARN_BUILD_SCRIPT: yarn.script + YARN_CACHE_FOLDER: "/cache/yarn" + YARN_BUILD_DIRECTORY: yarn.buildDir + if writeEnvFile != "" { + ENVFILE_NAME: writeEnvFile + ENVFILE: strings.Join([ for k, v in env {"\(k)=\(v)"}], "\n") + } + } + dir: "/src" + mount: { + "/src": from: source + "/cache/yarn": "cache" + } + }, + op.#Subdir & { + dir: "/build" + }, + ] } diff --git a/stdlib/netlify/netlify.cue b/stdlib/netlify/netlify.cue index 012bb8df..b9410867 100644 --- a/stdlib/netlify/netlify.cue +++ b/stdlib/netlify/netlify.cue @@ -3,7 +3,7 @@ package netlify import ( "dagger.io/dagger" "dagger.io/alpine" - "dagger.io/docker" + "dagger.io/dagger/op" ) // A Netlify account @@ -42,52 +42,45 @@ import ( // Logs URL for this deployment logsUrl: string - // Deployment container - #deploy: docker.#Container & { - image: alpine.#Image & { - package: { - bash: "=~5.1" - jq: "=~1.6" - curl: "=~7.74" - yarn: "=~1.22" + #up: [ + op.#Load & { + from: alpine.#Image & { + package: bash: "=~5.1" + package: jq: "=~1.6" + package: curl: "=~7.74" + package: yarn: "=~1.22" } - } - setup: [ - "yarn global add netlify-cli@2.47.0", - ] - shell: { - path: "/bin/bash" + }, + op.#Exec & { + args: ["yarn", "global", "add", "netlify-cli@2.47.0"] + }, + op.#Exec & { args: [ + "/bin/bash", "--noprofile", "--norc", "-eo", "pipefail", "-c", + #code, ] - } - dir: "/src" - volume: "contents": { - dest: "/src" - from: contents - } - env: { - NETLIFY_SITE_NAME: name - if (create) { - NETLIFY_SITE_CREATE: "1" + env: { + NETLIFY_SITE_NAME: name + if (create) { + NETLIFY_SITE_CREATE: "1" + } + if customDomain != _|_ { + NETLIFY_DOMAIN: customDomain + } + NETLIFY_ACCOUNT: account.name + NETLIFY_AUTH_TOKEN: account.token } - if customDomain != _|_ { - NETLIFY_DOMAIN: customDomain - } - NETLIFY_ACCOUNT: account.name - NETLIFY_AUTH_TOKEN: account.token - } - export: { + dir: "/src" + mount: "/src": from: contents + }, + op.#Export & { source: "/output.json" format: "json" - } - } - - // FIXME: this is a hack to use docker.#Container while exporting - // values. - #up: #deploy.#up + }, + ] } diff --git a/stdlib/netlify/netlify.sh.cue b/stdlib/netlify/netlify.sh.cue index 604fa743..34d89ff1 100644 --- a/stdlib/netlify/netlify.sh.cue +++ b/stdlib/netlify/netlify.sh.cue @@ -1,6 +1,6 @@ package netlify -#Site: #deploy: command: #""" +#code: #""" create_site() { url="https://api.netlify.com/api/v1/${NETLIFY_ACCOUNT:-}/sites"