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

Update installation and configuration guide with link to external MySQL Docker repo #140

Closed
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
26 changes: 26 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
db:
image: mysql:latest
container_name: mysql_dev
restart: always
environment:
MYSQL_DATABASE: 'crm_db'
# So you don't have to use root, but you can if you like
MYSQL_USER: 'crm_user'
# You can use whatever password you like
MYSQL_PASSWORD: 'crmpass'
# Password for root access
MYSQL_ROOT_PASSWORD: 'crmpass'
ports:
# <Port exposed> : <MySQL Port running inside container>
- '3306:3306'
expose:
# Opens port 3306 on the container
- '3306'
# Where our data will be persisted
volumes:
- my-db:/var/lib/mysql
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_general_ci']
# Names our volume
volumes:
my-db:
55 changes: 55 additions & 0 deletions docker/how_to_use.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# MySQL Container for Your Django CRM Database

In the project inside `docker` folder you can find files necessary to provide a streamlined approach to setting up a MySQL container for your Django CRM database, drawing inspiration from the well-regarded project.

### Key Benefits

- **Simplified Database Management:**
Benefit from the ease and efficiency of containerized databases. MySQL containers offer a self-contained environment, simplifying deployment and management.
- **Scalability and Flexibility:**
Scale your database resources effortlessly as your Django CRM application grows. Containers provide a lightweight and portable solution that adapts to your needs.
- **Improved Development Workflow:**
Streamline your development process with a readily available database environment. This setup facilitates rapid testing and iteration.
- **Clear and Concise Instructions:**
The repository includes clear instructions to guide you through the setup process, ensuring a smooth and successful deployment.

### Getting Started

- **Prerequisites:**
Docker: Ensure you have Docker installed on your system. Refer to the official [Docker documentation](https://docs.docker.com/get-docker/) for installation instructions.
- **Docker Compose:**
Install Docker Compose using the instructions provided [here](https://docs.docker.com/compose/install/).

- **Build and Run the Containers:**
copy the docker folder inside Django-CRM project folder.
Run `Bash:`
`./start_dev.sh`
This command will build the necessary Docker images and start the MySQL container in detached mode (-d).
It also:
- Install requirements
- Fill initial data into database
- Start the application

- **Check your Django CRM settings:**
Verify your Django-CRM application's database configuration settings to point to the MySQL container.
In `webcrm/settings.py` `'HOST'` should be `'127.0.0.1'`.
Refer to your Django project's documentation for specific instructions on configuring database connections.

### Additional Considerations

- **Security:**
Prioritize security by implementing appropriate authentication and authorization mechanisms for your MySQL container. Consider using environment variables to store sensitive database credentials.
- **Persistence:**
If you require data persistence beyond the container's lifecycle, explore volume mounting techniques to store database data on your host system.
- **Customization:**
This repository serves as a foundation. Feel free to customize the Dockerfile and docker-compose.yml files to tailor the setup to your specific requirements.

### Community and Support

For questions or assistance, feel free to raise issues on this repository or connect with the Django community for further guidance.

### Contributing

We welcome contributions to this project! If you have improvements or suggestions, please submit pull requests.

By following these steps and considerations, you can effectively leverage a MySQL container to manage your Django CRM database, enhancing your development experience and application's scalability.
3 changes: 3 additions & 0 deletions docker/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE DATABASE test_crm_db;
GRANT ALL PRIVILEGES ON test_crm_db.* TO 'crm_user'@'%';
FLUSH PRIVILEGES;
27 changes: 27 additions & 0 deletions docker/start_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Docker config
# clean up docker containers and images
docker compose down --volumes --remove-orphans --rmi all
docker system prune -a -f

# build and run docker containers
docker compose up -d

sleep 10
# run init.sql to grant privileges to the user for testing
docker exec -i mysql_dev mysql -u root -pcrmpass < init.sql

cd ..

# downlaod the dependencies
pip install -r requirements.txt

# populate the database
python manage.py setupdata

# run test
python manage.py test tests/ --noinput

# run the server
python manage.py runserver
2 changes: 1 addition & 1 deletion webcrm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'NAME': 'crm_db',
'USER': 'crm_user',
'PASSWORD': 'crmpass',
'HOST': 'localhost',
'HOST': '127.0.0.1',
}
}

Expand Down