Skip to content
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

upstream merge template repository #180

Open
wants to merge 1 commit into
base: main
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
12 changes: 8 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
"name": "CFC - Devenv",
// You can get the sha256 here https://github.com/codersforcauses/automated-setups/pkgs/container/cfc-devenv
// Pin it to a specific version to avoid unnecessary breaking changes
"image": "ghcr.io/codersforcauses/cfc-devenv@sha256:5f061666489f9023c4cf7eb95cfd67bebccdfacdc0a0bc6607c185e9c3d65fe1",
// "image": "ghcr.io/codersforcauses/cfc-devenv@sha256:a739aeff96bdb2b9beb09f9dd14ca8cb5d84045e0896841535114481a59760c7",
"dockerComposeFile": "./docker-compose.yml",
"service": "app",
// ! Always make sure that if you change this, change all other mentions of it in this file
"workspaceFolder": "/workspace",

"features": {},

// Use this environment variable if you need to bind mount your local source code into a new container.
"remoteEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder:-.}"
"WORKSPACE_FOLDER": "${workspaceFolder:/workspace}"
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [3000, 8000, 8080],
"forwardPorts": [3000, 8000, 5432],

// Use 'postCreateCommand' to run commands after the container is created.
// Note: Useful for when they open it and want everything to just start
"postCreateCommand": "./.devcontainer/setup.sh"
"postCreateCommand": "git config --global --add safe.directory /workspace && ./.devcontainer/setup.sh"
}
25 changes: 25 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
app:
image: ghcr.io/codersforcauses/cfc-devenv@sha256:a739aeff96bdb2b9beb09f9dd14ca8cb5d84045e0896841535114481a59760c7
volumes:
- ..:/workspace:cached
# Gives access to host's Docker, but requires sudo for everything
# - /var/run/docker.sock:/var/run/docker.sock

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
network_mode: service:db
user: vscode

db:
image: postgres
restart: unless-stopped
volumes:
- ./data/db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 3s
timeout: 3s
retries: 5
ports:
- 5432:5432
10 changes: 6 additions & 4 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ if [ ! -f ./server/.env ]; then
cp ./server/.env.example ./server/.env
fi

# Give editor intellisense
# Make the Django static folder to remove the annoying warning
(cd server && mkdir -p static)

# Install dependencies
(cd server && POETRY_VIRTUALENVS_CREATE=false poetry install)
(cd client && npm install)

# Build containers so less waiting
docker compose pull
docker compose build --no-cache
# Nuke and migrate db
(cd server && ./nuke.sh)
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
* text=auto eol=lf

*.png binary
*.jpg binary
18 changes: 1 addition & 17 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,4 @@ dist
# misc
.DS_Store

opt/


# Test page for visualising components, don't actually push to main
test_sandbox.tsx
signin-test.tsx

.idea/
pyproject.toml
.vscode/*
.vscode/settings.json

# Folder for avatar images, don't push
media/

# Custom docker compose file, don't push
docker-compose-copy.yml
opt/
45 changes: 45 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Django",
"type": "debugpy",
"request": "launch",
"args": ["runserver"],
"django": true,
"autoStartBrowser": false,
"program": "${workspaceFolder}/server/manage.py"
},
{
"name": "Next.js: Run frontend server",
"type": "node-terminal",
"request": "launch",
"cwd": "${workspaceFolder}/client",
"command": "npm run dev"
},
{
"name": "Next.js: debug browser",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000"
}
],
"compounds": [
{
"name": "Run Server/Client",
"configurations": [
"Python Debugger: Django",
"Next.js: Run frontend server"
],
"stopAll": true,
"presentation": {
"hidden": false,
"group": "runtime",
"order": 1
}
}
]
}
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"python.analysis.extraPaths": ["./server"],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
},
"editor.formatOnSave": true,
"python.analysis.extraPaths": ["./server"],
"flake8.cwd": "${workspaceFolder}/server",
"eslint.validate": ["javascript", "typescript"],
"typescript.tsdk": "./client/node_modules/typescript/lib",
"typescript.tsdk": "${workspaceFolder}/client/node_modules/typescript/lib",
"shellcheck.ignorePatterns": {
"**/.env*": true
}
Expand Down
52 changes: 52 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "lint:fix",
"path": "client",
"group": "none",
"problemMatcher": ["$eslint-stylish"],
"label": "npm run lint:fix - client",
"detail": "eslint --fix"
},
{
"type": "npm",
"script": "typecheck",
"path": "client",
"group": "none",
"problemMatcher": ["$tsc"],
"label": "npm run typecheck - client",
"detail": "tsc --noEmit"
},
{
"type": "shell",
"command": "cd server && flake8",
"label": "flake8 - server",
"detail": "cd server && flake8",
// https://github.com/aslafy-z/problem-matchers/blob/master/src/flake8.json
"problemMatcher": [
{
"owner": "flake8",
"pattern": [
{
"regexp": "^([^:]*):(\\d+):(\\d+): (error|warning): (\\w\\d\\d\\d) (.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 6
}
]
}
]
},
{
"type": "shell",
"command": "cd server && ./nuke.sh",
"label": "nuke db - server",
"detail": "cd server && nuke.sh",
"problemMatcher": []
}
]
}
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Django + Nextjs Template: Standardised CFC Tech Stack
## Get started

0. Activate the dev container in VSCode
1. Start the db, server and client with `docker compose up`
2. Server is at `localhost:8000`, client at `localhost:3000`
1. In the `client` folder, run `npm run dev` to start the frontend on port at `localhost:3000`
2. In the `server` folder, run `python manage.py runserver` to start the server at `localhost:8000`

## Server

Expand All @@ -15,20 +15,24 @@ Django + Nextjs Template: Standardised CFC Tech Stack
If the models are updated, be sure to create a migration:

```bash
docker container exec server python manage.py makemigrations # create a new migration OR
dxc server python manage.py makemigrations
python manage.py makemigrations # create migration
python manage.py migrate # apply migrations
```

### Nuke the DB

If you run into migration conflicts that you can't be bothered to fix, run `nuke.sh` to clear your database. Then, run migrations again.

## Other

### Get Intellisense
### Update Dependencies

If you're in the dev container, this should be done already. You can run `poetry install` and `npm install` in the correct folders to get the latest dependencies.
You can run `npm install` and `poetry install` in the respective `client` and `server` folders to install the newest dependencies.

### Editing Docker stuff

If you modify anything in the `docker` folder, you need to add the `--build` flag or Docker won't give you the latest changes.

### Custom env vars
### Changing env vars

Edit the `.env` file in the respective directory (client or server).
3 changes: 1 addition & 2 deletions client/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"simple-import-sort/exports": "warn",
"import/first": "warn",
"import/newline-after-import": "warn",
"import/no-duplicates": "warn",
"@next/next/no-html-link-for-pages": ["error", "client/src/pages"]
"import/no-duplicates": "warn"
}
}
2 changes: 1 addition & 1 deletion client/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"components": "@/components",
"utils": "@/lib/utils"
}
}
}
Loading