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
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"
},
]
}

View File

@ -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
},
]
}

View File

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