"mix-blog" uses only one container which has 5 tools, this app, ubuntu:20.04, gunicorn, supervisor and nginx in one container.
You can only deploy this app with "docker-compose".
Run "docker-compose up -d --build" (mix-blog/docker-compose.yml)
Default super user name is 'admin'.
Default super user password is 'adminpw'.
*Run "docker-compose down -v --rmi" to remove all containers, networks, volumes and images.
mix-blog/django_project/settings.py
*The email setting is for "Gmail". You may need different setup for other emails.
##### Email setting for "Reset password" function #####
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com' # Change to yours
EMAIL_PORT = 587 # Change to yours
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'example@gmail.com' # Change to yours
EMAIL_HOST_PASSWORD = 'abcdefg' # Change to yours
########################################################
mix-blog/nginx/default.conf
*Put your hostname there.
server {
listen 80;
server_name 10.156.58.203; # Change to yours
location /static/ {
alias /blog/static/;
}
location /media/ {
alias /blog/media/;
}
location / {
include proxy_params;
proxy_pass http://unix:/gunicorn.sock;
}
}
mix-blog/django_project/settings.py
===
SECRET_KEY = 'abcdefg' # Change to yours
===
If you use postgresql rather than default sqlite, comment out the sqlite setting and uncomment the postgresql setting then change 4 lines(# Change to yours).
*You need to install and configure postgresql yourself.
'''
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db_sqlite3',
}
}
'''
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb', # Change to yours
'USER': 'myuser', # Change to yours
'PASSWORD': 'mypw', # Change to yours
'HOST': '10.156.58.93', # Change to yours
'PORT': '5432',
}
}
===
If you use aws s3 bucket rather than default app file system, uncomment the aws s3 bucket setting then change 3 lines(# Change to yours).
##### AWS s3 bucket setting #####
AWS_ACCESS_KEY_ID = 'example' # Change to yours
AWS_SECRET_ACCESS_KEY = 'example' # Change to yours
AWS_STORAGE_BUCKET_NAME = 'example-bucket' # Change to yours
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
STATICFILES_STORAGE = 'django_project.s3utils.StaticRootS3Boto3Storage'
DEFAULT_FILE_STORAGE = 'django_project.s3utils.MediaRootS3Boto3Storage'
##################################
*I commented out the code in "mix-blog/users/models.py" to enable this app to work with "AWS s3 bucket" properly.
Otherwise, this app doesn't work with "AWS s3 bucket" properly.
'''
def save(self, *args, **kawrgs):
super().save(*args, **kawrgs)
img = Image.open(self.image.path)
if img.height > 300 or img.width > 300:
output_size = (300, 300)
img.thumbnail(output_size)
img.save(self.image.path)
'''
===
-
Allow less secure apps: ON ---> https://myaccount.google.com/lesssecureapps
-
Allow access to your Google account: ON (Tap "Continue") ---> https://accounts.google.com/DisplayUnlockCaptcha
===
===
mix-blog/docker-compose.yml, mix-blog/Dockerfile
There are "docker-compose.yml" and "Dockerfile".
*Run "docker-compose down -v --rmi" to remove all containers, volumes and images.
===
mix-blog/createsuperuser.py
- Change two 'admin' for your super user name:
- Change an 'admin@admin.com' for your email address:
- Change an 'adminpw' for your super user password:
User.objects.filter(username='admin').exists() or \
User.objects.create_superuser('admin', 'admin@admin.com', 'adminpw')
*It works properly with default setting so you don't need to change it if you don't want.
===