Skip to content

A Dockerized Strapi Boilerplate set-up with Node.js and MySQL, featuring migrations and seeding to automatically generate tables populated with mock data.

Notifications You must be signed in to change notification settings

EbodShojaei/strapi_boilerplate

Repository files navigation

Test-Cog Strapi MySQL Project

A development setup for Strapi with MySQL, using Docker for containerization and including migration and seeding capabilities.

Prerequisites

  • Docker and Docker Compose
  • Node.js
  • npm or yarn
  • Git

Quick Start

  1. Clone the repository:
cd test-cog
  1. Install dependencies:
npm install
  1. Start the development environment:
make setup

This will:

  • Build and start all Docker containers
  • Run database migrations
  • Seed the database with test data

Development Environment

Available Commands

# Start the development environment
make setup

# Start containers
make up

# Stop containers
make down

# View logs
make logs

# Access Strapi container shell
make shell

# Access MySQL shell
make mysql

# Restart containers
make restart

# Run migrations
make migrate

# Run seeds
make seed

Accessing Services

Database Migrations

Create a new migration:

npm run migrate:make migration_name

Run migrations:

make migrate

Rollback migrations:

npm run migrate:rollback

Database Seeding

Create a new seed file:

npm run seed:make seed_name

Run seeds:

make seed

Docker Configuration

Development Environment

  • Strapi: Node.js 14 Alpine
  • MySQL: 8.0
  • phpMyAdmin: Latest

Default ports:

  • Strapi: 1337
  • MySQL: 3306
  • phpMyAdmin: 8080

Environment Variables

Create a .env file in the root directory:

HOST=0.0.0.0
PORT=1337
DATABASE_HOST=mysql
DATABASE_PORT=3306
DATABASE_NAME=test_cog
DATABASE_USERNAME=strapi
DATABASE_PASSWORD=strapi_password

Common Issues and Solutions

  1. MySQL connection issues:
# Check MySQL container status
docker compose ps

# View MySQL logs
docker compose logs mysql
  1. Strapi startup issues:
# Check Strapi logs
docker compose logs strapi

# Access Strapi container
make shell
  1. Migration/Seed failures:
# Reset database and run migrations again
make migrate
make seed

Development Workflow

  1. Make changes to your code
  2. Test locally using the development environment
  3. Create migrations for database changes
  4. Update seeds if necessary
  5. Commit your changes
  6. Push to repository

Testing

To run tests:

npm run test

Useful Docker Commands

# View running containers
docker compose ps

# View container logs
docker compose logs -f [service_name]

# Rebuild containers
docker compose build --no-cache

# Remove all containers and volumes
docker compose down -v

# Clean up Docker system
docker system prune -af

Database Backup and Restore

Backup database:

make backup

Restore database:

make restore

Maintenance

Regular maintenance tasks:

  1. Update dependencies
  2. Backup database
  3. Check logs for errors
  4. Monitor disk space
  5. Update Docker images

Troubleshooting

  1. Container won't start:

    • Check logs: docker compose logs [service_name]
    • Verify environment variables
    • Check port conflicts
  2. Database connection issues:

    • Verify MySQL is running: docker compose ps
    • Check database credentials
    • Ensure migrations have run
  3. Permission issues:

    • Check file ownership in containers
    • Verify volume permissions

Additional Resources

Acknowledgements

AI used for reviewing and testing this project.

About

A Dockerized Strapi Boilerplate set-up with Node.js and MySQL, featuring migrations and seeding to automatically generate tables populated with mock data.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published