Skip to content

Instantly share code, notes, and snippets.

View raykipkorir's full-sized avatar
👨‍💻
Progress, not perfection!

Raymond Kipkorir raykipkorir

👨‍💻
Progress, not perfection!
View GitHub Profile
@raykipkorir
raykipkorir / docker-compose.yml
Created January 16, 2024 07:46
Docker compose file - for production
version: "3.8"
services:
app:
build:
context: .
dockerfile: ./compose/production/django/Dockerfile
command: ["sh", "-c", "/start-app.sh"]
image: django_prod
container_name: django_prod
# project/settings.py
import os
from pathlib import Path
from decouple import config
BASE_DIR = Path(__file__).resolve().parent.parent
DATABASES = {
@raykipkorir
raykipkorir / django_aws_settings.py
Created December 1, 2023 13:04
Example configuration for AWS s3 bucket which serves Django static and media files.
"""
Dependencies:
pip install django
pip install django-storages[s3]
pip install python-decouple
"""
# proj/settings.py
from decouple import config
@raykipkorir
raykipkorir / uwsgi_params
Created September 5, 2023 03:26
This is the default example configuration of uwsgi_params provided by nginx. It is located under: /etc/nginx/uwsgi_params
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
@raykipkorir
raykipkorir / proxy_params
Created September 5, 2023 03:23
This is the default example configuration of proxy_params provided by nginx. It is located under: /etc/nginx/proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
@raykipkorir
raykipkorir / .dockerignore
Created August 30, 2023 07:07
Sample .dockerignore file
# git
**/.git
**/.gitignore
# vscode
**/.vscode
# docker
Dockerfile
docker-compose-deploy.yml
@raykipkorir
raykipkorir / .docker-compose-local.yml
Created August 7, 2023 07:07
Django and PostgreSQL services in docker compose - for local development
version: "3.8"
services:
django:
build:
context: .
dockerfile: Dockerfile
image: local_django
container_name: local_django
command: python manage.py runserver 0.0.0.0:8000
@raykipkorir
raykipkorir / Dockerfile
Last active March 28, 2024 01:18
Dockerfile for Django app
FROM python:3.11.4-slim-bullseye
WORKDIR /app
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
# install system dependencies
RUN apt-get update
# install dependencies
@raykipkorir
raykipkorir / unique_slug.py
Created May 3, 2023 04:54
Unique slug generator.
import random
import string
from django.utils.text import slugify
# generate a rondom string to be appended to slug if the slug queried already exists
def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
@raykipkorir
raykipkorir / custom_user_manager_no_username.py
Last active June 7, 2023 05:04
Custom user manager in Django to get rid of username field.
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.contrib.auth.models import PermissionsMixin
from django.db import models
from django.utils import timezone
class UserManager(BaseUserManager):
"""Custom user manager"""
use_in_migrations = True
def _create_user(self, email, password, **extra_fields):