From 3911c25803cd9c6692a6f5b7e49be59ccd60fe62 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 13 Apr 2021 14:12:40 -0700 Subject: [PATCH] examples/jamstack: added support for frontend (netlify) Signed-off-by: Sam Alba --- examples/jamstack/frontend.cue | 52 ++++++++++++++++++++++++++++++++++ examples/jamstack/infra.cue | 4 +++ examples/jamstack/main.cue | 8 +++--- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 examples/jamstack/frontend.cue diff --git a/examples/jamstack/frontend.cue b/examples/jamstack/frontend.cue new file mode 100644 index 00000000..7e052f99 --- /dev/null +++ b/examples/jamstack/frontend.cue @@ -0,0 +1,52 @@ +package main + +import ( + "dagger.io/dagger" + "dagger.io/netlify" + "dagger.io/js/react" +) + +frontend: { + // Source code to build the app + source: dagger.#Artifact + + writeEnvFile?: string + + // Yarn Build + yarn: { + // Run this yarn script + script: string | *"build" + + // Read build output from this directory + // (path must be relative to working directory). + buildDir: string | *"build" + } + + // Build environment variables + environment: [string]: string + environment: NODE_ENV: string | *"production" + environment: APP_URL: "https://\(name).netlify.app/" +} + +frontend: { + app: react.#App & { + source: frontend.source + env: frontend.environment + + if frontend.writeEnvFile != _|_ { + writeEnvFile: frontend.writeEnvFile + } + + yarn: { + script: frontend.yarn.script + buildDir: frontend.yarn.buildDir + } + } + + // Host the application with Netlify + site: netlify.#Site & { + "name": name + account: infra.netlifyAccount + contents: app.build + } +} diff --git a/examples/jamstack/infra.cue b/examples/jamstack/infra.cue index e0c3bd07..9b04eccc 100644 --- a/examples/jamstack/infra.cue +++ b/examples/jamstack/infra.cue @@ -2,6 +2,7 @@ package main import ( "dagger.io/aws" + "dagger.io/netlify" ) infra: { @@ -28,4 +29,7 @@ infra: { // ARN of the RDS Instance rdsInstanceArn: string + + // Netlify credentials + netlifyAccount: netlify.#Account } diff --git a/examples/jamstack/main.cue b/examples/jamstack/main.cue index e495aa2b..e9e4d2ab 100644 --- a/examples/jamstack/main.cue +++ b/examples/jamstack/main.cue @@ -3,9 +3,6 @@ package main // Name of the application name: string & =~"[a-z0-9-]+" -// FIXME: temporary workaround (GH issue #142) - image metadata is lost after build -backend: container: command: ["/bin/hello-go"] - // Inject db info in the container environment backend: environment: { DB_USERNAME: database.username @@ -16,7 +13,10 @@ backend: environment: { DB_TYPE: database.dbType } +// Configure the frontend with the API URL +frontend: environment: APP_URL_API: url.backendURL + url: { - frontendURL: "FIXME" + frontendURL: frontend.site.url backendURL: "https://\(backend.hostname)/" }