Skip to content

Commit

Permalink
feat: add create_dev_env script and update devcontainer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfredinni committed Nov 30, 2024
1 parent a8bf41c commit 3f56950
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip install --user -r requirements.txt",
// Configure tool-specific properties.
"postCreateCommand": "poetry install && poetry run python manage.py migrate",
"postCreateCommand": "poetry install && poetry run create_dev_env && poetry run python manage.py migrate",
"customizations": {
"vscode": {
"extensions": [
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ A comprehensive and easy-to-use starting point for your new API with **Django**

## How to use

1. Clone the repo or use it as a template to start a new project.
![use](/static/USE.png)
1. [Create a new project with this template](https://github.com/new?template_name=django-starter-template&template_owner=wilfredinni) (recommended) or clone the repository and delete the `.git` folder.
1. Open the project in VS Code.
1. If you installed the recommended extensions, open `Todo Tree` in the sidebar. It will guide you trough the first steps setting up your project, like changing the name of the container, adjusting your URLS, etc.
![todo](/static/TODO.png)
1. ⚠️ Use `env.example` to create a `.env` file.
1. If you installed the recommended extensions, open `Todo Tree` in the sidebar. It will [guide you trough the first steps](/static/TODO.png) setting up your project, like changing the name of the container, adjusting your URLS, etc.
1. Hit `CTL/CMD + Shift + p` and select `Reopen in container`. This will:
- Create a dev container.
- Setup a Redis server.
- Setup your PostgreSQL database.
- Add a development `.env` file.
- Install the dependencies.
- Migrate the database.
1. Create your super user with `python manage.py createsuperuser`.
Expand All @@ -71,6 +69,7 @@ You can also use:
- `poetry run server` instead of `python manage.py runserver`
- `poetry run makemigrations` instead of `python manage.py makemigrations`
- `poetry run migrate` instead of `python manage.py migrate`
- `poetry run create_dev_env` to create a development `.env` file


## Todo
Expand Down
9 changes: 9 additions & 0 deletions scripts/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ def makemigrations():

def migrate():
check_call(["python", "manage.py", "migrate"])


def create_dev_env():
with open(".env", "w") as f:
f.write(
"DEBUG=True\n"
"DJANGO_SECRET_KEY=django-insecure-wlgjuo53y49%-4y5(!%ksylle_ud%b=7%__@9hh+@$d%_^y3s!\n" # noqa
"DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres\n"
)

0 comments on commit 3f56950

Please sign in to comment.