Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Local recipe starters): Create Repeatable Local Environment enhancement #840

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,28 @@ BREAKING CHANGE:
Dropped support for Next.js 11 and React 16. Users
requiring these older versions should stick to v1.6.
```

## Local Drupal Environment (Experimental)

Requires [DDEV](https://ddev.readthedocs.io/en/latest/users/install/ddev-installation/)

Create a local instance by running:

```
yarn ddev:init
```

This will create a local Drupal instance in local-next-drupal which will be ignored by git.

Destroy the local instance by running:

```
yarn ddev:destroy
```

Things that should work out of the box after running this script:

- basic starter
- pages starter
- module tests (run from local-next-drupal directory)
- `SIMPLETEST_DB=sqlite://localhost/:memory: ./vendor/bin/phpunit -c ./web/core modules/next`
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
"test": "yarn workspace next-drupal test",
"pretest": "yarn format:check && yarn lint",
"test:e2e": "turbo run test:e2e --parallel",
"test:e2e:ci": "turbo run test:e2e:ci --parallel"
"test:e2e:ci": "turbo run test:e2e:ci --parallel",
"ddev:init": "./scripts/init-drupal.sh",
"ddev:init:basic": "./scripts/init-drupal.sh --starter basic-starter",
"ddev:init:pages": "./scripts/init-drupal.sh --starter pages-starter",
"ddev:init:graphql": "./scripts/init-drupal.sh --starter graphql-starter",
"ddev:destroy": "./scripts/destroy-drupal.sh"
},
"devDependencies": {
"@actions/core": "^1.10.1",
Expand Down
15 changes: 15 additions & 0 deletions recipes/next_drupal_base/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "drupal/next_drupal_base",
"description": "Common dependencies and configuration for all Next Drupal projects.",
"type": "drupal-recipe",
"license": "GPL-2.0-or-later",
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"drupal/next": "*"
}
}
23 changes: 23 additions & 0 deletions recipes/next_drupal_base/config/pathauto.pattern.content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
uuid: a5900cb4-ec2f-4788-9e17-73ab49bfcb83
langcode: en
status: true
dependencies:
module:
- node
id: content
label: Content
type: 'canonical_entities:node'
pattern: '[node:title]'
selection_criteria:
c0c92c0f-9ee6-4b53-8270-198bd024c071:
id: 'entity_bundle:node'
negate: false
uuid: c0c92c0f-9ee6-4b53-8270-198bd024c071
context_mapping:
node: node
bundles:
article: article
page: page
selection_logic: and
weight: -5
relationships: { }
7 changes: 7 additions & 0 deletions recipes/next_drupal_base/recipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: "Next Drupal Base"
description: "Common dependencies and configuration for all Next Drupal projects"
type: "Site"

install:
- jsonapi
- next
17 changes: 17 additions & 0 deletions recipes/next_drupal_graphql/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "drupal/next_drupal_graphql",
"description": "Common dependencies and configuration for Next Drupal GraphQL projects.",
"type": "drupal-recipe",
"license": "GPL-2.0-or-later",
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"drupal/next": "*",
"drupal/graphql": "^4.6",
"drupal/graphql_compose": "^2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
uuid: 3954a200-86f3-499b-914e-99a6dac58861
langcode: en
status: true
dependencies: { }
name: graphql_schema
label: 'Graphql Schema'
endpoint: /graphql
debug_flag: 0
schema: graphql_compose
caching: true
batching: true
disable_introspection: false
query_depth: null
query_complexity: null
schema_configuration:
graphql_compose:
enabled: true
persisted_queries_settings: { }
50 changes: 50 additions & 0 deletions recipes/next_drupal_graphql/config/graphql_compose.settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
entity_config:
node:
article:
enabled: true
query_load_enabled: true
edges_enabled: true
routes_enabled: true
page:
enabled: true
query_load_enabled: true
edges_enabled: true
routes_enabled: true
taxonomy_term:
tags:
enabled: false
user:
user:
enabled: true
query_load_enabled: true
edges_enabled: true
routes_enabled: true
field_config:
node:
article:
body:
enabled: true
field_image:
enabled: true
field_tags:
enabled: true
page:
body:
enabled: true
user:
user:
user_picture:
enabled: true
settings:
exclude_unpublished: true
expose_entity_ids: false
field_required_override: false
schema_description: "GraphQL Compose"
schema_version: "1"
simple_queries: true
simple_unions: true
site_name: false
site_slogan: false
site_front: true
inflector_langcode: en
inflector_singularize: true
23 changes: 23 additions & 0 deletions recipes/next_drupal_graphql/config/pathauto.pattern.content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
uuid: a5900cb4-ec2f-4788-9e17-73ab49bfcb83
langcode: en
status: true
dependencies:
module:
- node
id: content
label: Content
type: 'canonical_entities:node'
pattern: '[node:title]'
selection_criteria:
c0c92c0f-9ee6-4b53-8270-198bd024c071:
id: 'entity_bundle:node'
negate: false
uuid: c0c92c0f-9ee6-4b53-8270-198bd024c071
context_mapping:
node: node
bundles:
article: article
page: page
selection_logic: and
weight: -5
relationships: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
uuid: a5bd2fda-4983-4e8d-8019-1c2695b15a42
langcode: en
status: true
dependencies: {}
id: nextjs_site
name: nextjs_site
description: "Next.js Site"
grant_types:
refresh_token:
status: false
description: ""
client_credentials:
status: true
description: ""
authorization_code:
status: false
description: ""
umbrella: false
parent: _none
granularity_id: role
granularity_configuration:
role: next_js_site
5 changes: 5 additions & 0 deletions recipes/next_drupal_graphql/config/simple_oauth.settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scope_provider: dynamic
token_cron_batch_size: 0
public_key: ../keys/public.key
private_key: ../keys/private.key
disable_openid_connect: false
11 changes: 11 additions & 0 deletions recipes/next_drupal_graphql/config/user.role.next_js_site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
uuid: 9082be18-8b66-4bfa-8d54-e703ef2c7e2d
langcode: en
status: true
dependencies: {}
id: next_js_site
label: "Next.js Site"
weight: 4
is_admin: false
permissions:
- "execute graphql_schema arbitrary graphql requests"
- "execute graphql_schema persisted graphql requests"
11 changes: 11 additions & 0 deletions recipes/next_drupal_graphql/recipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Next Drupal GraphQL"
description: "Common dependencies and configuration for Next Drupal GraphQL projects"
type: "Site"

install:
- next
- next_graphql
- graphql
- graphql_compose_edges
- graphql_compose_routes
- graphql_compose_users
31 changes: 31 additions & 0 deletions scripts/config/.ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: local-next-drupal
type: drupal
docroot: drupal/web
php_version: "8.3"
webserver_type: nginx-fpm
xdebug_enabled: false
additional_hostnames:
- frontend
additional_fqdns: []
database:
type: mariadb
version: "10.11"
use_dns_when_possible: true
hooks:
post-start:
- exec: |
composer create drupal/recommended-project tmp
mv -n tmp/* drupal
rm -rf tmp
cd starters/${STARTER_NAME} && npm install && pm2 start "npm run dev --experimental-https"
composer_version: "2"
composer_root: drupal
web_environment:
- STARTER_NAME=@STARTER_NAME
corepack_enable: true
web_extra_exposed_ports:
- name: frontend
container_port: 3000
http_port: 3080
https_port: 3433
nodejs_version: "22"
1 change: 1 addition & 0 deletions scripts/config/.ddev/web-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUN npm install -g pm2
14 changes: 14 additions & 0 deletions scripts/config/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# See https://next-drupal.org/docs/environment-variables

# Required
NEXT_PUBLIC_DRUPAL_BASE_URL=https://local-next-drupal.ddev.site
NEXT_IMAGE_DOMAIN=local-next-drupal.ddev.site

# Authentication
DRUPAL_CLIENT_ID=next_consumer
DRUPAL_CLIENT_SECRET=secret

# Required for On-demand Revalidation
# DRUPAL_REVALIDATE_SECRET=Retrieve this from /admin/config/services/next

NODE_TLS_REJECT_UNAUTHORIZED=0
49 changes: 49 additions & 0 deletions scripts/config/consumers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* Borrowed with kudos from
* https://github.com/octahedroid/drupal-decoupled-project/blob/10.3.x/scripts/consumers.php
*
* Very liberal with permissions/secrets here - only intended for local development
*/

use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Random;
use Drupal\Core\File\FileSystemInterface;

$random = new Random();
$consumerStorage = \Drupal::entityTypeManager()->getStorage('consumer');

$previewerClientId = Crypt::randomBytesBase64();
$previewerClientSecret = $random->word(8);
$consumerStorage->create([
'client_id' => 'next_consumer',
'client_secret ' => 'secret',
'label' => 'Next Consumer',
'user_id' => 1,
'third_party' => TRUE,
'is_default' => FALSE,
])->save();

$directory = '../keys';

if (create_directory($directory)) {
echo 'Keys dir created succesfully' . PHP_EOL;
} else {
echo 'Failed to create directory' . PHP_EOL;
}

\Drupal::service('simple_oauth.key.generator')->generateKeys($directory);

function create_directory($directory)
{
// Get the file system service.
$file_system = \Drupal::service('file_system');

// Check if the directory exists and create it if it doesn't.
if (!$file_system->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
return FALSE;
}

return TRUE;
}
Loading