stdlib/js/react, stdlib/netlify: removed docker.#Container abstraction (gh issue #319)

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-04-13 14:10:14 -07:00
parent e972863be6
commit 89882dbe81
3 changed files with 81 additions and 76 deletions

View File

@ -1,9 +1,11 @@
package react package react
import ( import (
"strings"
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/dagger/op"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/docker"
) )
// A ReactJS application // A ReactJS application
@ -11,6 +13,13 @@ import (
// Application source code // Application source code
source: dagger.#Artifact 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-specific settings
yarn: { yarn: {
// Read build output from this directory // Read build output from this directory
@ -20,47 +29,50 @@ import (
// Run this yarn script // Run this yarn script
script: string | *"build" script: string | *"build"
} }
setup: [
"mkdir -p /cache/yarn",
]
// Build the application in a container, using yarn build: #up: [
build: docker.#Container & { op.#Load & {
image: alpine.#Image & { from: alpine.#Image & {
package: bash: "=~5.1" package: bash: "=~5.1"
package: yarn: "=~1.22" package: yarn: "=~1.22"
} }
dir: "/src" },
command: """ op.#Exec & {
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: [ args: [
"/bin/bash",
"--noprofile", "--noprofile",
"--norc", "--norc",
"-eo", "pipefail", "-eo",
"pipefail",
"-c", "-c",
"""
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
cat .env
yarn install --production false
yarn run "$YARN_BUILD_SCRIPT"
mv "$YARN_BUILD_DIRECTORY" /build
""",
] ]
if env != _|_ {
"env": env
} }
env: { "env": {
YARN_BUILD_SCRIPT: yarn.script YARN_BUILD_SCRIPT: yarn.script
YARN_CACHE_FOLDER: "/cache/yarn" YARN_CACHE_FOLDER: "/cache/yarn"
YARN_BUILD_DIRECTORY: yarn.buildDir 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"
},
]
} }

View File

@ -3,7 +3,7 @@ package netlify
import ( import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/docker" "dagger.io/dagger/op"
) )
// A Netlify account // A Netlify account
@ -42,34 +42,28 @@ import (
// Logs URL for this deployment // Logs URL for this deployment
logsUrl: string logsUrl: string
// Deployment container #up: [
#deploy: docker.#Container & { op.#Load & {
image: alpine.#Image & { from: alpine.#Image & {
package: { package: bash: "=~5.1"
bash: "=~5.1" package: jq: "=~1.6"
jq: "=~1.6" package: curl: "=~7.74"
curl: "=~7.74" package: yarn: "=~1.22"
yarn: "=~1.22"
} }
} },
setup: [ op.#Exec & {
"yarn global add netlify-cli@2.47.0", args: ["yarn", "global", "add", "netlify-cli@2.47.0"]
] },
shell: { op.#Exec & {
path: "/bin/bash"
args: [ args: [
"/bin/bash",
"--noprofile", "--noprofile",
"--norc", "--norc",
"-eo", "-eo",
"pipefail", "pipefail",
"-c", "-c",
#code,
] ]
}
dir: "/src"
volume: "contents": {
dest: "/src"
from: contents
}
env: { env: {
NETLIFY_SITE_NAME: name NETLIFY_SITE_NAME: name
if (create) { if (create) {
@ -81,13 +75,12 @@ import (
NETLIFY_ACCOUNT: account.name NETLIFY_ACCOUNT: account.name
NETLIFY_AUTH_TOKEN: account.token NETLIFY_AUTH_TOKEN: account.token
} }
export: { dir: "/src"
mount: "/src": from: contents
},
op.#Export & {
source: "/output.json" source: "/output.json"
format: "json" format: "json"
} },
} ]
// FIXME: this is a hack to use docker.#Container while exporting
// values.
#up: #deploy.#up
} }

View File

@ -1,6 +1,6 @@
package netlify package netlify
#Site: #deploy: command: #""" #code: #"""
create_site() { create_site() {
url="https://api.netlify.com/api/v1/${NETLIFY_ACCOUNT:-}/sites" url="https://api.netlify.com/api/v1/${NETLIFY_ACCOUNT:-}/sites"