Skip to content

Dockerize and use mysql #33

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

Open
wants to merge 3 commits into
base: master
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.8-buster
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
RUN cp .env.dev.sample .env
EXPOSE 8000
CMD ["sh","entrypoint.sh"]
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "2.1"
services:
mysql_database:
image: mysql:5.7
ports:
- "33061:3306"
command: --init-file /data/application/init.sql
volumes:
- ./docker/init.sql:/data/application/init.sql
environment:
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: toor
MYSQL_DATABASE: jobdb
MYSQL_USER: jobs_user
MYSQL_PASSWORD: jobs@123
healthcheck:
test: ["CMD","mysqladmin","ping","-h","localhost"]
timeout: 20s
retries: 10
portal:
build: .
ports:
- 8000:8000
depends_on:
mysql_database:
condition: service_healthy
links:
- mysql_database

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 if not exists jobdb;
GRANT ALL PRIVILEGES ON `jobdb`.* To 'jobs_user'@'%';
FLUSH PRIVILEGES;
3 changes: 3 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
python manage.py migrate
python manage.py loaddata fixtures/app_name_initial_data.json --app app.model_name
python manage.py runserver 0.0.0.0:8000
13 changes: 10 additions & 3 deletions jobs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,16 @@
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
# "default": {
# "ENGINE": "django.db.backends.sqlite3",
# "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
# },
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'jobdb',
'HOST': 'mysql_database', #docker db service container
'USER': 'jobs_user',
'PASSWORD': 'jobs@123'
},
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
Expand Down
2 changes: 2 additions & 0 deletions jobsapp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import pymysql
pymysql.install_as_MySQLdb()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ urllib3==1.25.8
virtualenv==20.4.7
webencodings==0.5.1
whitenoise==5.0.1
PyMySQL==1.0.2