Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Relocate render.yaml to project root with rootDir: backend (#14278)

Damian Legawiec30162415b1e7
diff --git a/packages/create-spree-app/CHANGELOG.md b/packages/create-spree-app/CHANGELOG.md
index bd5cc778e2..0416e08600 100644
--- a/packages/create-spree-app/CHANGELOG.md
+++ b/packages/create-spree-app/CHANGELOG.md
@@ -1,5 +1,11 @@
# create-spree-app
+## 1.0.8
+
+### Patch Changes
+
+- Relocate the generated project's Render Blueprint (`render.yaml`) to the repository root and add `rootDir: backend` to every buildable service. In the wrapper layout the Rails app lives under `backend/`, so a Blueprint left in that subdirectory is invisible to Render and, without `rootDir`, its services build from the wrong directory — the deploy fails. The commented-out worker template is adjusted too, so uncommenting it still deploys correctly. Managed services (Redis, database) are left untouched.
+
## 1.0.7
### Patch Changes
diff --git a/packages/create-spree-app/package.json b/packages/create-spree-app/package.json
index c6b6322ad2..a4d229d66a 100644
--- a/packages/create-spree-app/package.json
+++ b/packages/create-spree-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-spree-app",
- "version": "1.0.7",
+ "version": "1.0.8",
"description": "Create a new Spree Commerce project with a single command",
"type": "module",
"bin": "./dist/index.js",
diff --git a/packages/create-spree-app/src/backend.ts b/packages/create-spree-app/src/backend.ts
index 1c04a81a18..aa1732bace 100644
--- a/packages/create-spree-app/src/backend.ts
+++ b/packages/create-spree-app/src/backend.ts
@@ -27,8 +27,10 @@ export async function downloadBackend(projectDir: string): Promise<void> {
/**
* Tidy the freshly-cloned starter for the nested `backend/` layout: drop files
- * the wrapper project supplies itself, and relocate the CI workflow to the repo
- * root (where GitHub Actions runs it) adapted to run against backend/.
+ * the wrapper project supplies itself, relocate the CI workflow to the repo
+ * root (where GitHub Actions runs it) adapted to run against backend/, and
+ * relocate the Render Blueprint likewise (adapted so each service builds from
+ * backend/).
*/
export function prepareBackendTemplate(projectDir: string): void {
const backendDir = path.join(projectDir, 'backend')
@@ -53,6 +55,18 @@ export function prepareBackendTemplate(projectDir: string): void {
// and the storefront). Keeping it would leave a stale, duplicate config.
fs.rmSync(path.join(backendDir, '.github'), { recursive: true, force: true })
}
+
+ // Render reads a single Blueprint from the repository root. The starter ships
+ // render.yaml authored for a repo where the Rails app *is* the root; left in
+ // backend/ it is invisible to Render, and even at the root its services would
+ // build from the wrong directory. Relocate it to the project root with
+ // `rootDir: backend` on every buildable service.
+ const srcRenderYaml = path.join(backendDir, 'render.yaml')
+ if (fs.existsSync(srcRenderYaml)) {
+ const content = fs.readFileSync(srcRenderYaml, 'utf-8')
+ fs.writeFileSync(path.join(projectDir, 'render.yaml'), adaptRenderYamlForNestedBackend(content))
+ fs.rmSync(srcRenderYaml, { force: true })
+ }
}
/**
@@ -86,3 +100,23 @@ export function adaptWorkflowForNestedBackend(content: string): string {
return result
}
+
+/**
+ * Rewrite the starter's Render Blueprint so each service that builds from source
+ * deploys the `backend/` subdirectory instead of the repo root. The starter
+ * authors render.yaml for a repo where the Rails app *is* the root; in the
+ * wrapper project the app lives under backend/, so without `rootDir: backend`
+ * Render runs `bundle install` at the root (no Gemfile) and the build fails.
+ *
+ * `rootDir` is added after every `runtime:` line — the marker of a
+ * build-from-source service (web, worker) — while managed services (redis,
+ * databases) have no runtime and are left untouched. The commented-out worker
+ * template is handled too: its `runtime:` line keeps its `#` prefix, so
+ * uncommenting the block yields a correctly-rooted worker.
+ */
+export function adaptRenderYamlForNestedBackend(content: string): string {
+ return content.replace(
+ /^([ \t]*(?:#[ \t]*)?)runtime:.*$/gm,
+ (line, prefix) => `${line}\n${prefix}rootDir: backend`,
+ )
+}
diff --git a/packages/create-spree-app/tests/backend.test.ts b/packages/create-spree-app/tests/backend.test.ts
index 690b2d1333..49cc909435 100644
--- a/packages/create-spree-app/tests/backend.test.ts
+++ b/packages/create-spree-app/tests/backend.test.ts
@@ -2,7 +2,11 @@ import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
-import { adaptWorkflowForNestedBackend, prepareBackendTemplate } from '../src/backend'
+import {
+ adaptRenderYamlForNestedBackend,
+ adaptWorkflowForNestedBackend,
+ prepareBackendTemplate,
+} from '../src/backend'
// Mirrors spree-starter's .github/workflows/backend-ci.yml (the workflow that
// create-spree-app relocates to the generated project root).
@@ -56,6 +60,23 @@ jobs:
context: .
`
+// A trimmed render.yaml covering the three shapes the transform distinguishes:
+// a buildable service (has `runtime:`), the commented-out worker template
+// (`runtime:` behind a `#`), and a managed service (no `runtime:`).
+const RENDER_YAML = `services:
+ - type: web
+ runtime: ruby
+ plan: free
+
+ # - type: worker
+ # runtime: ruby
+ # plan: standard
+
+ - type: redis
+ name: spree-redis
+ plan: free
+`
+
describe('adaptWorkflowForNestedBackend', () => {
it('points ruby/setup-ruby at the backend/ subdirectory', () => {
const result = adaptWorkflowForNestedBackend(BACKEND_CI)
@@ -94,6 +115,26 @@ describe('adaptWorkflowForNestedBackend', () => {
})
})
+describe('adaptRenderYamlForNestedBackend', () => {
+ it('adds rootDir: backend to the buildable web service', () => {
+ const result = adaptRenderYamlForNestedBackend(RENDER_YAML)
+ expect(result).toContain(' runtime: ruby\n rootDir: backend\n')
+ })
+
+ it('adds a commented rootDir to the commented worker so uncommenting still deploys', () => {
+ const result = adaptRenderYamlForNestedBackend(RENDER_YAML)
+ expect(result).toContain(' # runtime: ruby\n # rootDir: backend\n')
+ })
+
+ it('leaves managed services (no runtime) untouched', () => {
+ const result = adaptRenderYamlForNestedBackend(RENDER_YAML)
+ // Only web + the commented worker have a runtime, so exactly two rootDirs;
+ // redis has none and is left verbatim.
+ expect(result.match(/rootDir: backend/g)).toHaveLength(2)
+ expect(result).toContain(' - type: redis\n name: spree-redis\n plan: free')
+ })
+})
+
describe('prepareBackendTemplate', () => {
const tempDirs: string[] = []
@@ -106,6 +147,7 @@ describe('prepareBackendTemplate', () => {
fs.writeFileSync(path.join(workflows, 'backend-ci.yml'), BACKEND_CI)
fs.writeFileSync(path.join(workflows, 'release.yml'), RELEASE)
fs.writeFileSync(path.join(projectDir, 'backend', 'README.md'), '# Spree starter')
+ fs.writeFileSync(path.join(projectDir, 'backend', 'render.yaml'), RENDER_YAML)
return projectDir
}
@@ -138,4 +180,15 @@ describe('prepareBackendTemplate', () => {
expect(fs.existsSync(path.join(projectDir, 'backend', 'README.md'))).toBe(false)
})
+
+ it('relocates render.yaml to the project root with rootDir: backend', () => {
+ const projectDir = seedClonedBackend()
+ prepareBackendTemplate(projectDir)
+
+ const moved = path.join(projectDir, 'render.yaml')
+ expect(fs.existsSync(moved)).toBe(true)
+ expect(fs.readFileSync(moved, 'utf-8')).toContain(' runtime: ruby\n rootDir: backend\n')
+ // The original in backend/ is removed so Render never reads a stale copy.
+ expect(fs.existsSync(path.join(projectDir, 'backend', 'render.yaml'))).toBe(false)
+ })
})