diff --git a/.ddev/commands/host/setup-drupal b/.ddev/commands/host/setup-drupal index bec1357..8fa9734 100755 --- a/.ddev/commands/host/setup-drupal +++ b/.ddev/commands/host/setup-drupal @@ -1,9 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bash ## Description: Set up project for headless Drupal ## Usage: setup-drupal ## Example: "ddev setup-drupal" +if [ -d "/${DDEV_APPROOT}/frontend" ]; then + cd "/${DDEV_APPROOT}/frontend" || exit ; +fi + if [ -e ./codegen.ts ] || [ -d ./app/api ]; then echo "Drupal setup can only be run once." echo "If you need the starter files, copy them from the /starterkits directory." @@ -22,8 +26,10 @@ rm -rf ./types cp -r ./starterkits/drupal/types ./ # Block until file changes are in the web container... -ddev mutagen sync || true +if [ ${DDEV_MUTAGEN_ENABLED} ]; then + ddev mutagen sync || true +fi -ddev exec npm install --package-lock-only -ddev exec npm ci -ddev exec pm2 restart all +ddev exec -s=frontend "npm install --package-lock-only" || ddev exec "npm install --package-lock-only" +ddev exec -s=frontend "npm ci" || ddev exec "npm ci" +ddev exec -s=frontend "pm2 restart all" || ddev exec "pm2 restart all" diff --git a/.ddev/commands/host/setup-wp b/.ddev/commands/host/setup-wp index 2242a64..f64557f 100755 --- a/.ddev/commands/host/setup-wp +++ b/.ddev/commands/host/setup-wp @@ -1,9 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bash ## Description: Set up project for headless WordPress ## Usage: setup-wp ## Example: "ddev setup-wp" +if [ -d "/${DDEV_APPROOT}/frontend" ]; then + cd "/${DDEV_APPROOT}/frontend" || exit ; +fi + if [ -e ./codegen.ts ] || [ -d ./app/api ]; then echo "WordPress setup can only be run once." echo "If you need the starter files, copy them from the /starterkits directory." @@ -28,8 +32,10 @@ cp -r ./starterkits/wp/next.config.mjs ./ cp -r ./starterkits/wp/possibleTypes.json ./ # Block until file changes are in the web container... -ddev mutagen sync || true +if [ ${DDEV_MUTAGEN_ENABLED} ]; then + ddev mutagen sync || true +fi -ddev exec npm install --package-lock-only -ddev exec npm ci -ddev exec pm2 restart all +ddev exec -s=frontend "npm install --package-lock-only" || ddev exec "npm install --package-lock-only" +ddev exec -s=frontend "npm ci" || ddev exec "npm ci" +ddev exec -s=frontend "pm2 restart all" || ddev exec "pm2 restart all" diff --git a/.ddev/config.hooks.yaml b/.ddev/config.hooks.yaml new file mode 100644 index 0000000..4b83301 --- /dev/null +++ b/.ddev/config.hooks.yaml @@ -0,0 +1,11 @@ +hooks: + post-start: + # Detects to see if the node_modules folder exists + - exec: 'sh -c "[ ! -d node_modules ] && npm ci || return"' + service: web + # pm2 does not live in the node path, so have to call binary directly + - exec: pm2 start --name next node_modules/.bin/next -- dev + service: web + # pm2 does not live in the node path, so have to call binary directly + - exec: pm2 start --name storybook node_modules/.bin/storybook -- dev --no-open -p 6006 + service: web diff --git a/.ddev/config.yaml b/.ddev/config.yaml index 3d75953..00e48a5 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -1,7 +1,7 @@ name: nextjs-project type: php docroot: public -php_version: "8.0" +php_version: "8.3" webserver_type: nginx-fpm router_http_port: "80" router_https_port: "443" @@ -15,17 +15,6 @@ use_dns_when_possible: true composer_version: "2" web_environment: [] nodejs_version: "20" -hooks: - post-start: - # Detects to see if the node_modules folder exists - - exec: 'sh -c "[ ! -d node_modules ] && npm ci || echo 0"' - service: web - # pm2 does not live in the node path, so have to call binary directly - - exec: pm2 start --name frontend node_modules/.bin/next -- dev - service: web - # pm2 does not live in the node path, so have to call binary directly - - exec: pm2 start --name storybook node_modules/.bin/storybook -- dev --no-open -p 6006 - service: web # Key features of ddev's config.yaml: diff --git a/README.project.md b/README.project.md index 62a0064..5531cd6 100644 --- a/README.project.md +++ b/README.project.md @@ -87,14 +87,14 @@ ddev nextjs icons ## Helpful commands ### Monitoring the applications -If you want to monitor the status of `app` or `storybook`. Please use `ddev frontend monit` +If you want to monitor the status of `next` or `storybook`. Please use `ddev frontend monit` ### Restarting a specific service -If you want to restart `storybook` or `app`, please use the following: +If you want to restart `storybook` or `next`, please use the following: `app` ```bash -ddev frontend restart frontend +ddev frontend restart next ``` `storybook` ```bash diff --git a/starterkits/drupal/.env.drupal b/starterkits/drupal/.env.drupal index 1b777a6..050d5a5 100644 --- a/starterkits/drupal/.env.drupal +++ b/starterkits/drupal/.env.drupal @@ -1,4 +1,4 @@ -NEXT_PUBLIC_DRUPAL_BASE_URL=http://web/drupal +NEXT_PUBLIC_DRUPAL_BASE_URL=http://web NEXT_IMAGE_DOMAIN=web # Authentication diff --git a/starterkits/drupal/docker-compose.frontend.yaml b/starterkits/drupal/docker-compose.frontend.yaml new file mode 100644 index 0000000..a437075 --- /dev/null +++ b/starterkits/drupal/docker-compose.frontend.yaml @@ -0,0 +1,22 @@ +services: + frontend: + container_name: ddev-${DDEV_SITENAME}-frontend + build: + context: frontend + command: "sleep infinity" + expose: + - 3000 + - 6006 + volumes: + - ./../frontend:/var/www/html/frontend:cached + - ".:/mnt/ddev_config" + - ddev-global-cache:/mnt/ddev-global-cache + working_dir: /var/www/html/frontend + labels: + com.ddev.site-name: ${DDEV_SITENAME} + com.ddev.approot: $DDEV_APPROOT + environment: + - VIRTUAL_HOST=$DDEV_HOSTNAME + - HTTP_EXPOSE=3001:3000,8025:8025,6007:6006 + - HTTPS_EXPOSE=3000:3000,8026:8025,6006:6006 + networks: [default, ddev_default]