This project provides a Docker-based setup for building a Views REST export of the Drupal core API, specifically designed for creating vector databases or generating training datasets for machine learning models.
- Docker
- Docker Compose
- Clone the repository:
git clone git@github.com:npacker/drupal-api-docker.git
cd drupal-api-docker- Configure the
.envfile with appropriate values for your environment:
# Database configuration
DRUPAL_DB_HOST=mariadb
DRUPAL_DB_PORT=3306
DRUPAL_DB_NAME=drupal
DRUPAL_DB_USER=drupal
DRUPAL_DB_PASS=drupal
# Drupal site configuration
DRUPAL_SITE_NAME="Drupal API Export"
DRUPAL_ADMIN_USER=admin
DRUPAL_ADMIN_PASS=admin
3. Start the services:
```bash
docker-compose up -d- Wait for the services to initialize (this may take a few minutes). You can check the logs with:
docker-compose logs -f.env: Environment variables for the Docker Compose setupdocker-compose.yml: Configuration for Docker services (Drupal and MariaDB)drupal/Dockerfile: Custom Dockerfile for the Drupal servicedrupal/drush-site-precreate: Script for initializing the Drupal site and processing the APIdrupal/config/views.view.drupal_api_export.yml: Drupal view configuration for the REST export
The project includes a pre-configured Views REST export at /export/api/drupal/11.x. To access the API:
- Ensure the Drupal service is running
- Navigate to
http://localhost:8383/export/api/drupal/11.xin your browser or use a tool likecurl:
curl http://localhost:8383/export/api/drupal/11.xThe Views configuration is stored in drupal/config/views.view.drupal_api_export.yml. To modify the API output:
- Edit the configuration file
- Import the configuration:
docker-compose exec drupal drush config:import --partial --source=/opt/drupal/configTo update the API data:
- Ensure the Drupal service is running
- Run the following command to reprocess the API:
docker-compose exec drupal /opt/drupal/web/drush-site-precreate- The project is designed to work with version 11.x of Drupal core
- The
drush-site-precreatescript handles site installation, module configuration, and API processing - For development, you can modify files in the
drupal/configdirectory and re-import them usingdrush config:import