@webship.co/workspace-laravel 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -71,6 +71,7 @@ Everything the builder runs for an app runs in the app's own container, through
71
71
  | `ai/prompts/laravel-build-and-test.md`, `laravel-scenarios-for-an-account.md` | Two prompts: whole launch commands for a new session |
72
72
  | `src/index.ts` | `register(api)`: what the assistant is told about Laravel here |
73
73
  | `features/laravel.feature` | Scenarios for the dashboard's own browser suite |
74
+ | `features/laravel-runtimes.feature` | The row, the test users and the pages of an app built on Docker Compose and on Kubernetes |
74
75
 
75
76
  The `workspacePlugin` block in `package.json` is the manifest the installer reads.
76
77
 
@@ -92,15 +93,69 @@ bash cmd-laravel-project.sh myapp --install --add-users
92
93
  | `--add-users` | With `--install`: add the default accounts |
93
94
  | `--production` | Run the app as a live app runs: `APP_ENV=production`, `APP_DEBUG=false` (error pages instead of the debug page, the stricter password rules) |
94
95
  | `--php-version <x>` | The PHP of the project container |
96
+ | `--runtime <name>` | The container runtime to build on: `ddev` (the default), `docker`, `kubernetes`, `podman`, `lando` or `docksal`. See [Runtimes](#runtimes) |
95
97
  | `--launch` | Open the app when it is ready |
96
98
 
97
- The app answers at `https://myapp.ddev.site`, the login at `/login`, its mail catcher at
99
+ On DDEV the app answers at `https://myapp.ddev.site`, the login at `/login`, its mail catcher at
98
100
  `https://myapp.ddev.site:8026`. The build runs `ddev config --project-type=laravel` with the
99
101
  Node.js of the workspace (24), makes the app with the official installer in the web container
100
102
  (`laravel new --livewire`, `--react` or `--vue`), the way the DDEV quickstart for Laravel does, and
101
103
  leaves the database settings to the container tool (it writes them into `.env`): it writes none.
102
104
  A project of the same name is deleted first.
103
105
 
106
+
107
+ ### Runtimes
108
+
109
+ ```bash
110
+ bash cmd-laravel-project.sh myapp --install --add-users # DDEV, the default
111
+ bash cmd-laravel-project.sh myapp --install --add-users --runtime docker # Docker Compose
112
+ bash cmd-laravel-project.sh myapp --install --add-users --runtime kubernetes # a Kubernetes cluster
113
+ bash cmd-laravel-project.sh myapp --install --add-users --runtime lando # Lando
114
+ bash cmd-laravel-project.sh myapp --install --add-users --runtime docksal # Docksal
115
+ ```
116
+
117
+ Without `--runtime` a build takes `container.runtime` of the workspace's `settings.yml`, then DDEV.
118
+ It needs a Webship Workspace with the container runtimes
119
+ ([webship/workspace#694](https://github.com/webship/workspace/issues/694)); on an older one the
120
+ builder refuses `--runtime` and builds on DDEV only. Lando and Docksal need a Workspace whose runtime
121
+ layer has them ([webship/workspace#729](https://github.com/webship/workspace/issues/729),
122
+ [#730](https://github.com/webship/workspace/issues/730)).
123
+
124
+ | | DDEV | Docker Compose | Kubernetes | Podman | Lando | Docksal |
125
+ | --- | --- | --- | --- | --- | --- | --- |
126
+ | Build with `--install --add-users --production` | Yes | Yes | Yes | Not yet run | Yes | Yes |
127
+ | The pages, and a login as the workspace account and the default accounts | Yes | Yes | Yes | Not yet run | Yes | Yes |
128
+ | `cmd-tools-laravel-artisan.sh`: status, `--run`, the accounts | Yes | Yes | Yes | Not yet run | Yes | Yes |
129
+ | Test users, added and cancelled | Yes | Yes | Yes | Not yet run | Yes | Yes |
130
+ | Mail caught by Mailpit (a password reset) | Yes | Yes | Yes | Not yet run | Yes | Yes |
131
+ | The testing setup and the first feature | Yes | Yes | Yes | Not yet run | Yes | Yes |
132
+ | The step pack's examples (48 scenarios) | Yes | Yes | Yes | Not yet run | Yes | Yes |
133
+ | Export and import the database | Yes | Yes | Yes | Not yet run | Yes | Yes |
134
+ | The row in the dashboard, and remove | Yes | Yes | Yes | Not yet run | Yes | Yes |
135
+
136
+ "Yes" means it was run on a real app of that runtime. Podman runs the same code as Docker Compose
137
+ and was not run yet.
138
+
139
+ | Runtime | The app's address | What the project carries |
140
+ | --- | --- | --- |
141
+ | DDEV | `https://myapp.ddev.site` | `.ddev/config.yaml` |
142
+ | Docker Compose | `http://127.0.0.1:<port>`, printed by the build | `compose.yaml`, `.webship/runtime/Dockerfile` |
143
+ | Kubernetes | `http://<node address>:<port>`, printed by the build | The same, and `k8s/` (the namespace `ws-myapp`) |
144
+ | Lando | `http://127.0.0.1:<port>`, printed by the build | `.lando.yml` (Lando's proxy stays off) |
145
+ | Docksal | `http://myapp.docksal.site`, on Docksal's own proxy | `.docksal/docksal.env`, `.docksal/docksal.yml` |
146
+
147
+ What differs on Docker Compose, Kubernetes, Lando and Docksal:
148
+
149
+ - **`.env`** is written by the builder, as DDEV writes it on start: the address (`APP_URL`), the database of the project's own stack (`DB_CONNECTION=mariadb`, `db`/`db`/`db` on the host `db`) and its mail catcher (`MAIL_HOST=mail`, `mailpit` on Lando, port 1025). Nothing personal. On DDEV the builder still writes none.
150
+ - **The official installer** runs from Composer's own folder of the web container, without the front end (`LARAVEL_INSTALLER_NO_NODE`): the web container there has no Node.js. `npm install` and `npm run build` run in the Workspace's tests container, as `laravel new --npm` runs them on DDEV.
151
+ - **Artisan** runs as `php artisan` in the web container (`ddev exec`), and `.env` keys are set by the plugin (`laravel_dotenv_set`): DDEV's `ddev artisan` and `ddev dotenv` are DDEV's own. The tool, the test users and the testing hook use them on every runtime.
152
+ - **On Kubernetes** a site's mail needs the Workspace's webship/workspace#748 (the cluster's service links set `MAIL_PORT` in the pod, which Laravel reads before `.env`).
153
+ - **HTTPS and a host name** are DDEV's: a runtime's address is plain HTTP.
154
+
155
+ The same commands work on every runtime: `cmd-tools-laravel-artisan.sh`, `cmd-tools-add-users.sh`,
156
+ `cmd-tools-testing.sh`. The pattern is the Workspace's
157
+ [`core/docs/plugins-on-runtimes.md`](https://github.com/webship/workspace/blob/1.0.x/core/docs/plugins-on-runtimes.md).
158
+
104
159
  ### Work on an app
105
160
 
106
161
  ```bash
@@ -191,6 +246,6 @@ npm run lint
191
246
  npm test # the manifest, the commands, the AI items, the functions against a scaffolded project
192
247
  ```
193
248
 
194
- CI runs the same on Node.js 20 and 24, parses every shell script, and runs the plugin's
249
+ CI runs the same on Node.js 24 and 26, parses every shell script, and runs the plugin's
195
250
  `features/laravel.feature` against a dashboard with this plugin installed
196
251
  (`webship/workspace/.github/workflows/plugin-browser-suite.yml`).
@@ -39,13 +39,15 @@ bash cmd-laravel-project.sh myapp --install --add-users
39
39
  | `--php-version <x>` | The PHP of the project container. |
40
40
  | `--launch` | Opens the app when it is ready. |
41
41
 
42
- The app answers at `https://<name>.ddev.site`, the login at `/login`. The build makes the app the
42
+ On DDEV the app answers at `https://<name>.ddev.site`, the login at `/login`. The build makes the app the
43
43
  way the official installer does (`laravel new` with the starter kit, in the web container), with
44
44
  the Node.js of the workspace (24) for its assets; the container tool writes the database settings
45
45
  into `.env`. The builder **deletes a project of the same name first**: a build is a clean slate,
46
46
  so never point it at an app somebody still needs. The name is a folder, a container project and a
47
47
  host name: short, lowercase, letters and digits.
48
48
 
49
+ With `--runtime docker`, `podman`, `kubernetes`, `lando` or `docksal` the app is built on that runtime instead, at the address the build prints (`http://127.0.0.1:<port>`, the node's address and a port, or `http://<name>.docksal.site`): never write a `ddev.site` address for such an app. Its mailbox is at the address `rt_mail_url` gives, and the same commands work on it.
50
+
49
51
  ## Work on an app
50
52
 
51
53
  ```bash
@@ -61,7 +63,7 @@ bash cmd-tools-laravel-artisan.sh myapp --cancel-users # and
61
63
 
62
64
  Inside the project folder, `ddev artisan <command>` is the same Artisan, and `ddev composer`,
63
65
  `ddev npm`, `ddev export-db --file=…`, `ddev import-db --file=…` are the tools for everything else.
64
- The mail the app sends lands in the project's mail catcher at `https://<name>.ddev.site:8026`.
66
+ The mail the app sends lands in the project's mail catcher (on DDEV at `https://<name>.ddev.site:8026`).
65
67
 
66
68
  The rest is the workspace's, the same for every project: `ddev start -y` and `ddev stop` in the
67
69
  project (`stop` takes no `-y`), `bash cmd-tools-backup-<folder>.sh <name>`,
@@ -5,7 +5,9 @@
5
5
  # Installed by the Laravel plugin (plugins.sh --install laravel); __WORKSPACE__ is the workspace it was installed into.
6
6
  #
7
7
  # Build a Laravel app in a container with the official installer and an official starter kit
8
- # (Livewire by default, React or Vue with --starter-kit), at https://<name>.ddev.site. With --install
8
+ # (Livewire by default, React or Vue with --starter-kit): on DDEV (the default) at
9
+ # https://<name>.ddev.site, and with --runtime docker, podman, kubernetes, lando or docksal on that
10
+ # runtime, at the address the build prints. With --install
9
11
  # its database is migrated and the workspace account is its first account; with --add-users it also
10
12
  # gets the default accounts.
11
13
 
package/dist/src/index.js CHANGED
@@ -34,7 +34,8 @@ function assistantContext() {
34
34
  'Laravel (a plugin, @webship.co/workspace-laravel): a Laravel app is built with',
35
35
  '`bash cmd-laravel-project.sh <name> --install --add-users` from a sites folder (dev, test, sandboxes, demos),',
36
36
  'with the official installer and an official starter kit (`--starter-kit livewire|react|vue`, Livewire by default),',
37
- 'in a container like every other project, at https://<name>.ddev.site; `--production` runs it as a live app runs.',
37
+ 'in a container like every other project: on DDEV by default, at https://<name>.ddev.site, or with `--runtime docker|podman|kubernetes|lando|docksal`',
38
+ 'on that runtime, at the address the build prints (never write a ddev.site address for such an app); `--production` runs it as a live app runs.',
38
39
  '`bash cmd-tools-laravel-artisan.sh <name>` says what the app is; `--run "<artisan command>"` runs Artisan in it,',
39
40
  '`--update` updates its packages, `--down --secret <s>` and `--up` put it in and out of maintenance mode,',
40
41
  '`--add-users` adds the default accounts (member, verified; unverified).',
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAuBH,4CAeC;AAED,4BAEC;AAtCD,4FAA4F;AAC/E,QAAA,QAAQ,GAAG,SAAS,CAAC;AAElC,+DAA+D;AAClD,QAAA,QAAQ,GAAG,CAAC,wBAAwB,EAAE,8BAA8B,CAAC,CAAC;AAEnF,+DAA+D;AAClD,QAAA,MAAM,GAAG,CAAC,sBAAsB,EAAE,gBAAgB,CAAC,CAAC;AAEjE,iGAAiG;AACpF,QAAA,MAAM,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAE5C,wE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runtime on Docker Compose, Podman, Kubernetes, Lando or
3
+ Docksal. An app built on Docker Compose or Kubernetes has the row a DDEV site has: its state, its own address,
4
+ the runtime's menu, and the test users of the plugin in its Tests menu.
5
+
6
+ # Each scenario drives a real app of that runtime, built with cmd-laravel-project.sh --runtime: the first running
7
+ # one the workspace holds of this platform. Without one it is skipped, with the reason. In the plugin's CI the
8
+ # Docker Compose app is the one the manifest's featuresSite builds.
9
+
10
+ @needs-runtime-docker @needs-platform-laravel
11
+ Scenario: An app built on Docker Compose runs at its own address, with the DOCKER menu
12
+ Given I am on the folder of the "docker" site
13
+ Then the row of the "docker" site should show "Running"
14
+ And the row of the "docker" site should link to the address of its runtime
15
+ And the address of the "docker" site should answer
16
+ And the row of the "docker" site should carry the "DOCKER" menu and no DDEV menu
17
+
18
+ @needs-runtime-docker @needs-platform-laravel
19
+ Scenario: The Tests menu of an app on Docker Compose offers the test users
20
+ Given I am on the folder of the "docker" site
21
+ When I open the "tests" menu of the "docker" site
22
+ Then the open menu should offer "Add the test users"
23
+ And the open menu should offer "Cancel the test users"
24
+
25
+ @needs-runtime-docker @needs-platform-laravel
26
+ Scenario: The app on Docker Compose is installed: its front page and its login page
27
+ Given I am on the folder of the "docker" site
28
+ When I open "/" on the "docker" site
29
+ Then I should see "Log in"
30
+ When I open "/login" on the "docker" site
31
+ Then I should see "Log in to your account"
32
+
33
+ @needs-runtime-kubernetes @needs-platform-laravel
34
+ Scenario: An app built on Kubernetes runs at the address of its node, with the K8S menu
35
+ Given I am on the folder of the "kubernetes" site
36
+ Then the row of the "kubernetes" site should show "Running"
37
+ And the row of the "kubernetes" site should link to the address of its runtime
38
+ And the address of the "kubernetes" site should answer
39
+ And the row of the "kubernetes" site should carry the "K8S" menu and no DDEV menu
40
+
41
+ @needs-runtime-kubernetes @needs-platform-laravel
42
+ Scenario: The Tests menu of an app on Kubernetes offers the test users
43
+ Given I am on the folder of the "kubernetes" site
44
+ When I open the "tests" menu of the "kubernetes" site
45
+ Then the open menu should offer "Add the test users"
46
+ And the open menu should offer "Cancel the test users"
47
+
48
+ @needs-runtime-kubernetes @needs-platform-laravel
49
+ Scenario: The app on Kubernetes is installed: its front page and its login page
50
+ Given I am on the folder of the "kubernetes" site
51
+ When I open "/" on the "kubernetes" site
52
+ Then I should see "Log in"
53
+ When I open "/login" on the "kubernetes" site
54
+ Then I should see "Log in to your account"
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@webship.co/workspace-laravel",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Laravel for Webship Workspace: the builder (`cmd-laravel-project.sh`, the official installer and an official starter kit) and the Artisan tool in every sites folder, the default accounts, the Laravel step pack wired into the testing setup, and its AI items in their folders: two agents, a skill, a command and two prompts.",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "license": "ISC",
8
+ "engines": {
9
+ "node": ">=24"
10
+ },
8
11
  "repository": {
9
12
  "type": "git",
10
13
  "url": "https://github.com/webship/workspace-laravel.git"
@@ -83,8 +86,10 @@
83
86
  ]
84
87
  },
85
88
  "features": [
86
- "features/laravel.feature"
87
- ]
89
+ "features/laravel.feature",
90
+ "features/laravel-runtimes.feature"
91
+ ],
92
+ "featuresSite": "cmd-laravel-project.sh ci-laravel --install --add-users --runtime docker"
88
93
  },
89
94
  "devDependencies": {
90
95
  "@types/node": "^24.0.0",
@@ -16,7 +16,7 @@ parser.add_argument('-d', '--down',
16
16
  help='Put the app into maintenance mode. With --secret, that address lets a browser past the maintenance page.')
17
17
  parser.add_argument('-s', '--secret',
18
18
  default="",
19
- help='With --down: the secret that lets a browser past the maintenance page (https://<name>.ddev.site/<secret>). Example: --secret preview-2026')
19
+ help='With --down: the secret that lets a browser past the maintenance page (the address of the app, then /<secret>). Example: --secret preview-2026')
20
20
  parser.add_argument('-U', '--up',
21
21
  action='store_true',
22
22
  default=False,
@@ -2,7 +2,12 @@
2
2
 
3
3
  argparse "$@" <<ARGEOF || exit 1
4
4
  parser.add_argument('PROJECT_NAME',
5
- help='The name of the project: its folder, its DDEV project and its host name.')
5
+ help='The name of the project: its folder, and its name on the container runtime (on DDEV its host name too).')
6
+ parser.add_argument('--runtime',
7
+ dest='RUNTIME',
8
+ default="_none_",
9
+ choices=['ddev', 'docker', 'podman', 'kubernetes', 'lando', 'docksal'],
10
+ help='The container runtime to build on: ddev (the default, or container.runtime of settings.yml), docker (Docker Compose), podman, kubernetes, lando or docksal.')
6
11
  parser.add_argument('-k', '--starter-kit',
7
12
  default="${site_starter_kit}",
8
13
  choices=['livewire', 'react', 'vue'],
@@ -5,8 +5,17 @@
5
5
  #
6
6
  # Placed by `plugins.sh --install laravel` in core/scripts/plugins/laravel/functions/, where
7
7
  # bootstrap sources it after the core's own functions. Everything runs in the project's container
8
- # (DDEV by default: `ddev artisan …`, `ddev composer …`, `ddev npm …`), never on the host. The
9
- # container tool writes the database settings of the app into its .env, so nothing here writes any.
8
+ # (DDEV by default: `ddev artisan …`, `ddev composer …`, `ddev npm …`), never on the host. On DDEV
9
+ # the container tool writes the database settings of the app into its .env, so nothing here writes any.
10
+ #
11
+ # The runtimes: an app is built on DDEV, or with --runtime on Docker Compose, Podman, Kubernetes, Lando
12
+ # or Docksal. The commands are the same on each: `ddev <verb>` is DDEV itself on a DDEV project, and on
13
+ # another runtime the core's layer (fun-runtime.sh) gives the verb its meaning there. What differs is
14
+ # behind laravel_runtime: the address (laravel_url), Artisan and `.env` (laravel_artisan and
15
+ # laravel_dotenv_set: DDEV has verbs of its own for them, the layer has none), the official installer
16
+ # (DDEV adds it to its web image), the front end (npm runs in the tests container there: the web
17
+ # container of the php stack has no Node.js), and the .env DDEV writes on start (laravel_runtime_config:
18
+ # the address, the database of the project's own stack, db/db/db on the host db, and its mail catcher).
10
19
  #
11
20
  # Four names are the ones the core's tools look for, under the DDEV project type `laravel`:
12
21
  # set_laravel_users the default accounts (cmd-tools-add-users.sh <project> laravel)
@@ -35,9 +44,86 @@ function set_laravel_users() {
35
44
  user_unverified_role='unverified' ;
36
45
  }
37
46
 
38
- # Is this folder a Laravel project? Its DDEV project type says so.
47
+ # The runtime of the project in this folder, or of a new build (--runtime, else the workspace's
48
+ # setting, else DDEV). A core without the runtime layer has DDEV only.
49
+ function laravel_runtime() {
50
+ if declare -f runtime_of > /dev/null ; then runtime_of ; else echo 'ddev' ; fi
51
+ }
52
+
53
+ # The address of the app in this folder: https://<name>.ddev.site on DDEV, http://127.0.0.1:<port> on
54
+ # Docker Compose, Podman and Lando, the node's address and a port on Kubernetes, http://<name>.docksal.site
55
+ # on Docksal. Asked after `ddev config`.
56
+ function laravel_url() {
57
+ if declare -f rt_url > /dev/null ; then rt_url ; else echo "https://${PROJECT_NAME}.ddev.site" ; fi
58
+ }
59
+
60
+ # Artisan in the app of this folder: DDEV's own `ddev artisan`, and `php artisan` in the web container
61
+ # on another runtime (the core's layer has no artisan verb).
62
+ function laravel_artisan() {
63
+ if [ "$(laravel_runtime)" == 'ddev' ] ; then
64
+ ddev artisan "$@" ;
65
+ else
66
+ ddev exec php artisan "$@" ;
67
+ fi
68
+ }
69
+
70
+ # Set keys of a .env file: DDEV's own `ddev dotenv set <file> --a-key=value …`, and on another runtime
71
+ # the same keys (A_KEY=value), each where the file has it (commented out or not), else at the end.
72
+ function laravel_dotenv_set() {
73
+ if [ "$(laravel_runtime)" == 'ddev' ] ; then
74
+ ddev dotenv set "$@" ;
75
+ return $? ;
76
+ fi
77
+ python3 - "$@" <<'PYEOF'
78
+ import re, sys
79
+ path, pairs = sys.argv[1], []
80
+ for arg in sys.argv[2:]:
81
+ m = re.match(r'^--([a-z0-9][a-z0-9-]*)=(.*)$', arg, re.S)
82
+ if not m:
83
+ sys.exit('laravel_dotenv_set: --a-key=value, not ' + arg)
84
+ value = m.group(2)
85
+ if re.search(r'[\s#"\'$\\]', value):
86
+ value = '"' + value.replace('\\', '\\\\').replace('"', '\\"') + '"'
87
+ pairs.append((m.group(1).upper().replace('-', '_'), value))
88
+ try:
89
+ lines = open(path).read().split('\n')
90
+ except FileNotFoundError:
91
+ lines = []
92
+ if lines and lines[-1] == '':
93
+ lines.pop()
94
+ for key, value in pairs:
95
+ found = [i for i, l in enumerate(lines) if re.match(r'^\s*' + re.escape(key) + r'\s*=', l)] \
96
+ or [i for i, l in enumerate(lines) if re.match(r'^\s*#\s*' + re.escape(key) + r'\s*=', l)]
97
+ if found:
98
+ lines[found[0]] = key + '=' + value
99
+ else:
100
+ lines.append(key + '=' + value)
101
+ open(path, 'w').write('\n'.join(lines) + '\n')
102
+ PYEOF
103
+ }
104
+
105
+ # What DDEV writes into the .env of a laravel project when it starts, and the other runtimes do not:
106
+ # the address, the database of the project's own stack (db, db, db on the host db, as on every
107
+ # runtime) and its mail catcher (Mailpit on the host mail, Lando's on mailpit, port 1025). Only on a
108
+ # runtime that is not DDEV, in the project folder; a .env that is not there yet is made from the
109
+ # app's .env.example first.
110
+ function laravel_runtime_config() {
111
+ local base_url="$1" mail_host='mail' ;
112
+ [ "$(laravel_runtime)" == 'lando' ] && mail_host='mailpit' ;
113
+ [ -f .env ] || cp .env.example .env || return 1 ;
114
+ laravel_dotenv_set .env --app-url="${base_url}" \
115
+ --db-connection=mariadb --db-host=db --db-port=3306 --db-database=db --db-username=db --db-password=db \
116
+ --mail-mailer=smtp --mail-host="${mail_host}" --mail-port=1025 ;
117
+ }
118
+
119
+ # Is this folder a Laravel project? Its project type says so: on DDEV in .ddev/config.yaml, on another
120
+ # runtime in the x-webship block, both read by the core's rt_is_platform.
39
121
  function laravel_is_project() {
40
122
  local project_path="$1";
123
+ if declare -f rt_is_platform > /dev/null ; then
124
+ rt_is_platform "${project_path}" laravel ;
125
+ return $? ;
126
+ fi
41
127
  grep -qE '^type:[[:space:]]*"?laravel"?[[:space:]]*$' "${project_path}/.ddev/config.yaml" 2>/dev/null ;
42
128
  }
43
129
 
@@ -49,7 +135,7 @@ function laravel_enter_project() {
49
135
  return 1 ;
50
136
  fi
51
137
  if ! laravel_is_project "${project_path}" ; then
52
- echo "${doc_name}/${PROJECT_NAME} is not a Laravel project (its .ddev/config.yaml does not say type: laravel)." ;
138
+ echo "${doc_name}/${PROJECT_NAME} is not a Laravel project (its project type is not laravel)." ;
53
139
  return 1 ;
54
140
  fi
55
141
  cd "${project_path}" || return 1 ;
@@ -106,7 +192,12 @@ PHPEOF
106
192
  # official starter kit, and with --install its database and its first account.
107
193
  function laravel_build() {
108
194
  trim_project_name ;
109
- local base_url="https://${PROJECT_NAME}.ddev.site" ;
195
+ local base_url runtime ;
196
+ runtime="$(laravel_runtime)" ;
197
+ if [ "${RUNTIME:-_none_}" != '_none_' ] && [ "${RUNTIME}" != "${runtime}" ] ; then
198
+ echo "--runtime ${RUNTIME} needs a Webship Workspace with the container runtimes (webship/workspace#694): update the workspace, or build on DDEV." ;
199
+ exit 1 ;
200
+ fi
110
201
  local kit="${STARTER_KIT:-${site_starter_kit:-livewire}}" ;
111
202
  local php_version="${PHP_VERSION:-${site_php_version:-}}" ;
112
203
 
@@ -124,23 +215,42 @@ function laravel_build() {
124
215
 
125
216
  ddev config --project-type=laravel --docroot="${distribution_webroot}" --project-name=${PROJECT_NAME} \
126
217
  --nodejs-version=$(ddev_nodejs_version) ${php_version:+--php-version=${php_version}} --auto || exit 1 ;
127
-
128
- # The official installer, in the web container for the time of the build only (the DDEV quickstart
129
- # for Laravel does the same).
130
- mkdir -p .ddev/web-build ;
131
- cat > .ddev/web-build/Dockerfile.laravel-installer <<'DOCKERFILEEND'
218
+ # The address is the runtime's to say, once the project is configured: never a written ddev.site.
219
+ base_url="$(laravel_url)" ;
220
+
221
+ if [ "${runtime}" == 'ddev' ] ; then
222
+ # The official installer, in the web container for the time of the build only (the DDEV quickstart
223
+ # for Laravel does the same).
224
+ mkdir -p .ddev/web-build ;
225
+ cat > .ddev/web-build/Dockerfile.laravel-installer <<'DOCKERFILEEND'
132
226
  ARG COMPOSER_HOME=/usr/local/composer
133
227
  RUN composer global require laravel/installer
134
228
  RUN ln -s $COMPOSER_HOME/vendor/bin/laravel /usr/local/bin/laravel
135
229
  DOCKERFILEEND
230
+ fi
136
231
  ddev_up start -y || exit 1 ;
137
232
 
138
- ddev exec laravel new temp --${kit} --database=sqlite --pest --npm --no-boost --no-interaction \
139
- || { echo "laravel new failed." ; exit 1 ; } ;
140
- ddev exec 'rsync -rltgopD temp/ ./ && rm -rf temp' || exit 1 ;
141
- rm -f .ddev/web-build/Dockerfile.laravel-installer .env ;
142
- # The restart writes the database settings of the container into .env.
143
- ddev_up restart || exit 1 ;
233
+ if [ "${runtime}" == 'ddev' ] ; then
234
+ ddev exec laravel new temp --${kit} --database=sqlite --pest --npm --no-boost --no-interaction \
235
+ || { echo "laravel new failed." ; exit 1 ; } ;
236
+ ddev exec 'rsync -rltgopD temp/ ./ && rm -rf temp' || exit 1 ;
237
+ rm -f .ddev/web-build/Dockerfile.laravel-installer .env ;
238
+ # The restart writes the database settings of the container into .env.
239
+ ddev_up restart || exit 1 ;
240
+ else
241
+ # The official installer, in Composer's own folder of the web container for the time of the
242
+ # build, without the front end: the web container of this runtime has no Node.js, and the starter
243
+ # kit's own feature installer is told so (LARAVEL_INSTALLER_NO_NODE).
244
+ ddev exec "composer global require laravel/installer --no-interaction --quiet && LARAVEL_INSTALLER_NO_NODE=1 \"\$(composer global config bin-dir --absolute --quiet)/laravel\" new temp --${kit} --database=sqlite --pest --no-boost --no-interaction" \
245
+ || { echo "laravel new failed." ; exit 1 ; } ;
246
+ ddev exec 'cp -a temp/. ./ && rm -rf temp' || exit 1 ;
247
+ rm -f .env ;
248
+ # What DDEV's restart writes into .env: the address, the database and the mail of the container.
249
+ laravel_runtime_config "${base_url}" || { echo "The .env of the app could not be written." ; exit 1 ; } ;
250
+ # The front end, in the tests container (Node.js), as `laravel new --npm` builds it on DDEV.
251
+ ddev npm install --no-audit --no-fund || { echo "npm install failed." ; exit 1 ; } ;
252
+ ddev npm run build || { echo "npm run build failed." ; exit 1 ; } ;
253
+ fi
144
254
  ddev composer run-script post-root-package-install || exit 1 ;
145
255
 
146
256
  if [ "${INSTALL}" == 'yes' ] ; then
@@ -156,13 +266,13 @@ DOCKERFILEEND
156
266
  fi
157
267
 
158
268
  if [ "${PRODUCTION}" == 'yes' ] ; then
159
- ddev dotenv set .env --app-env=production --app-debug=false > /dev/null ;
269
+ laravel_dotenv_set .env --app-env=production --app-debug=false > /dev/null ;
160
270
  fi
161
271
 
162
- echo "${doc_name} ${PROJECT_NAME} has been installed: $(ddev artisan --version 2>/dev/null) with the ${kit} starter kit.";
272
+ echo "${doc_name} ${PROJECT_NAME} has been installed: $(laravel_artisan --version 2>/dev/null) with the ${kit} starter kit.";
163
273
  echo "Go to ${base_url}/login and log in as ${account_mail}";
164
274
  else
165
- ddev artisan key:generate --ansi > /dev/null ;
275
+ laravel_artisan key:generate --ansi > /dev/null ;
166
276
  [ "${ADD_USERS}" == 'yes' ] && echo "--add-users needs --install: there is no database to add accounts to yet." ;
167
277
  echo "${doc_name} ${PROJECT_NAME} is ready: migrate its database with bash cmd-tools-laravel-artisan.sh ${PROJECT_NAME} --run \"migrate\"";
168
278
  echo "Go to ${base_url}";
@@ -225,19 +335,19 @@ function laravel_artisan_tool() {
225
335
 
226
336
  if [ ! "${RUN}" == '_none_' ] ; then
227
337
  # Unquoted on purpose: --run "route:list --except-vendor" is a command and its arguments.
228
- ddev artisan ${RUN} ;
338
+ laravel_artisan ${RUN} ;
229
339
  exit $? ;
230
340
  fi
231
341
 
232
342
  if [ "${UPDATE}" == 'yes' ] ; then
233
343
  ddev composer update --no-interaction ;
234
- ddev artisan migrate --force ;
344
+ laravel_artisan migrate --force ;
235
345
  ddev npm install ;
236
346
  ddev npm run build ;
237
347
  elif [ "${DOWN}" == 'yes' ] ; then
238
- ddev artisan down ${SECRET:+--secret="${SECRET}"} ;
348
+ laravel_artisan down ${SECRET:+--secret="${SECRET}"} ;
239
349
  elif [ "${UP}" == 'yes' ] ; then
240
- ddev artisan up ;
350
+ laravel_artisan up ;
241
351
  elif [ "${ADD_USERS}" == 'yes' ] ; then
242
352
  set_laravel_users ;
243
353
  add_laravel_users ;
@@ -245,8 +355,8 @@ function laravel_artisan_tool() {
245
355
  set_laravel_users ;
246
356
  cancel_laravel_users ;
247
357
  else
248
- echo "${doc_name}/${PROJECT_NAME}: $(ddev artisan --version 2>/dev/null) at https://${PROJECT_NAME}.ddev.site" ;
249
- echo "" ; ddev artisan about --only=environment ;
358
+ echo "${doc_name}/${PROJECT_NAME}: $(laravel_artisan --version 2>/dev/null) at $(laravel_url)" ;
359
+ echo "" ; laravel_artisan about --only=environment ;
250
360
  echo "" ; echo "Accounts:" ;
251
361
  printf '' | laravel_write_accounts list ;
252
362
  fi
@@ -378,7 +488,7 @@ PYEOF
378
488
  fi
379
489
 
380
490
  # The scenarios log in as the default accounts: make sure a migrated app has them.
381
- if ddev artisan migrate:status > /dev/null 2>&1 ; then
491
+ if laravel_artisan migrate:status > /dev/null 2>&1 ; then
382
492
  ( add_laravel_users > /dev/null ) && echo " the default accounts are on the app (${users[*]})" ;
383
493
  fi
384
494
  }