Skip to content

Commit

Permalink
Update code to mirror mason repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ddahan committed Oct 8, 2023
1 parent 5a46c1a commit fd891a1
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 643 deletions.
3 changes: 0 additions & 3 deletions .devcontainer/.env_db

This file was deleted.

18 changes: 13 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Template Django/PostgreSQL",
"name": "🧱 masonkid-dj",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"service": "srv_django",
"workspaceFolder": "/workspace",
"containerEnv": {
"PYTHONUNBUFFERED": "1",
Expand Down Expand Up @@ -55,14 +55,15 @@
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 90,
"editor.defaultFormatter": null, // overrided per language
"editor.tabSize": 2,
"editor.tabSize": 4,
"editor.indentSize": "tabSize",
"editor.formatOnSave": true,
//*********************************************************************
// color customizations
//*********************************************************************
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#0f3e2e",
"titleBar.activeForeground": "#ffffff"
"titleBar.activeBackground": "#9b543d",
"titleBar.activeForeground": "#ffd242"
},
//*********************************************************************
// python
Expand All @@ -87,6 +88,13 @@
"${workspaceFolder}/dj_apps"
// TODO: add "${workspaceFolder}/dj_apps/<my_app>" for any new app,
],
//*********************************************************************
// black
//*********************************************************************
"black-formatter.args": [
"--config",
"pyproject.toml"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
Expand Down
30 changes: 16 additions & 14 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
version: '3'

services:
# -- Django container --
app:
# vars are injected at runtime, so no need to specify env_var value here.
image: 'python:3.11.5-bookworm'

srv_django:
container_name: "ctn_django"
# vars are injected at runtime, so no need to specify env_var value here.
image: 'python:3.11.6-bookworm'
volumes:
- ..:/workspaces:delegated

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
expose:
- 8000

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db

# -- PostgreSQL container --
db:
env_file: .env_db # var created at build-time, so we need an env_file
srv_postgres:
container_name: "ctn_postgres"
environment:
- POSTGRES_DB=mydb
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypassword
image: 'postgres:15-bookworm'
restart: unless-stopped

volumes:
- postgres-data-somename:/var/lib/postgresql/data
- postgres-data-masonkid:/var/lib/postgresql/data
expose:
- 5432

volumes:
postgres-data-somename:
postgres-data-masonkid:
3 changes: 0 additions & 3 deletions .env

This file was deleted.

3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DJ_SECRET_KEY="secret-key"
DJ_DEBUG="true"
DJ_DATABASE_URL="postgres://myuser:mypassword@srv_postgres:5432/mydb"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
__pycache__
staticfiles/
*.db
.env
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# template-devcontainer-django-pg
# Django Mason Kid Starter

This is a starter template to get ready-to-use Django/PostgreSQL project in a local Dev Container.
A minimal Django Starter Template for quick SaaS.


### Specifications
Expand All @@ -22,9 +22,6 @@ This is a starter template to get ready-to-use Django/PostgreSQL project in a lo

#### Once the container has been created:
- Reload the container once (running the `reload window` VS Code command ) to ensure there is no error with extension activation due to a Dev Container bug.
- Create a `.env` file based on `.env.example` file.
- Run `./manage.py migrate`
- Run `./manage.py runserver` and go to "http://localhost:8000/" to ensure everything works.

### About .env file

- .env file is currently versionned because it's required to create the container without error. Once the container is created, you should un-version it by adding it to `.gitignore` file, and running `git rm --cached .env`
File renamed without changes.
7 changes: 0 additions & 7 deletions dj_config/asgi.py

This file was deleted.

2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dj_config.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
Loading

0 comments on commit fd891a1

Please sign in to comment.