From 700aa717892fa36656693087c171be36ec308659 Mon Sep 17 00:00:00 2001 From: PraaneshSelvaraj Date: Sat, 31 May 2025 11:45:02 +0530 Subject: [PATCH 1/5] feat: devcontainer --- .devcontainer/devcontainer.json | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..2aebc3985 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,76 @@ +{ + "name": "PokeAPI", + + // Use multiple docker-compose files for development and overrides + "dockerComposeFile": [ + "../docker-compose.yml", + "../docker-compose-dev.yml" + ], + + // Target container service to attach VS Code workspace + "service": "app", + + // Folder inside container where workspace is mounted + "workspaceFolder": "/code", + + "customizations": { + "vscode": { + "settings": { + "python.defaultInterpreterPath": "/usr/local/bin/python", + + // Use bash as the default shell in the integrated terminal + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash" + } + }, + "terminal.integrated.defaultProfile.linux": "bash", + + // Enable automatic formatting on save with Black for Python files + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.formatOnSave": true + } + }, + + // Extensions to install automatically in the container's VS Code instance + "extensions": [ + "ms-python.python", + "ms-python.black-formatter" + ] + } + }, + + // Post-create commands: + // - Install essential tools (bash, git, make) + // - Set Git line endings to input (avoid Windows-style CRLF issues) + // - Run Django migrations with custom settings + // - Run build data inside Django shell + "postCreateCommand": "apk add --no-cache bash git make && git config --global core.autocrlf input && pip install black && python manage.py migrate --settings=config.docker-compose && echo \"from data.v2.build import build_all; build_all()\" | python manage.py shell --settings=config.docker-compose", + + "remoteUser": "root", + "overrideCommand": false, + + // Ports to forward from container to host for easy access + "forwardPorts": [80, 443, 8000, 8080], + + // Custom port labels and auto-forward notification settings + "portsAttributes": { + "8000": { + "label": "App", + "onAutoForward": "notify" + }, + "80": { + "label": "Web HTTP", + "onAutoForward": "notify" + }, + "443": { + "label": "Web HTTPS", + "onAutoForward": "notify" + }, + "8080": { + "label": "GraphQL", + "onAutoForward": "notify" + } + } +} From efd6da1770e0233da57535ce017969ac48d49a6e Mon Sep 17 00:00:00 2001 From: PraaneshSelvaraj Date: Mon, 2 Jun 2025 15:18:52 +0530 Subject: [PATCH 2/5] fixed devcontainer --- .devcontainer/devcontainer.json | 20 ++++++++++++-------- .devcontainer/docker-compose.override.yml | 6 ++++++ 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 .devcontainer/docker-compose.override.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2aebc3985..070cb2c69 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,7 @@ // Use multiple docker-compose files for development and overrides "dockerComposeFile": [ "../docker-compose.yml", - "../docker-compose-dev.yml" + "./docker-compose.override.yml" ], // Target container service to attach VS Code workspace @@ -41,15 +41,19 @@ } }, + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "false", + "installOhMyZsh": "false", + "configureZshAsDefaultShell": "false" + }, + "ghcr.io/devcontainers/features/git:1": {} + }, + // Post-create commands: - // - Install essential tools (bash, git, make) - // - Set Git line endings to input (avoid Windows-style CRLF issues) - // - Run Django migrations with custom settings - // - Run build data inside Django shell - "postCreateCommand": "apk add --no-cache bash git make && git config --global core.autocrlf input && pip install black && python manage.py migrate --settings=config.docker-compose && echo \"from data.v2.build import build_all; build_all()\" | python manage.py shell --settings=config.docker-compose", - + "postCreateCommand": "apk add --no-cache make && git config --global core.autocrlf input", + "remoteUser": "root", - "overrideCommand": false, // Ports to forward from container to host for easy access "forwardPorts": [80, 443, 8000, 8080], diff --git a/.devcontainer/docker-compose.override.yml b/.devcontainer/docker-compose.override.yml new file mode 100644 index 000000000..ce8cc5701 --- /dev/null +++ b/.devcontainer/docker-compose.override.yml @@ -0,0 +1,6 @@ +version: '2.4' + +services: + app: + image: pokeapi/pokeapi:master + command: [] \ No newline at end of file From aba472cc672cef3efae5cfdf9eee258f6d4b12b8 Mon Sep 17 00:00:00 2001 From: PraaneshSelvaraj Date: Mon, 2 Jun 2025 15:19:50 +0530 Subject: [PATCH 3/5] Added devcontainer commands --- Makefile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Makefile b/Makefile index 2beb3553a..7fe8b3b2a 100755 --- a/Makefile +++ b/Makefile @@ -27,6 +27,9 @@ wipe-sqlite-db: # Delete's the project database serve: # Run the project locally python manage.py runserver ${local_config} +serve-gunicorn: # Run the project using Gunicorn + gunicorn config.wsgi:application -c gunicorn.conf.py + test: # Run tests python manage.py test ${local_config} @@ -81,6 +84,23 @@ docker-prod: docker-setup: docker-up docker-migrate docker-build-db # (Docker) Start services, prepare the latest DB schema, populate the DB +devcontainer-migrate: # (Dev Container) Run any pending migrations + python manage.py migrate ${docker_config} + +devcontainer-build-db: # (Dev Container) Build the database + sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell ${docker_config}' + +devcontainer-make-migrations: # (Dev Container) Create migrations files if schema has changed + python manage.py makemigrations ${docker_config} + +devcontainer-flush-db: # (Dev Container) Removes all the data present in the database but preserves tables and migrations + python manage.py flush --no-input ${docker_config} + +devcontainer-shell: # (Dev Container) Launch an interative Django shell for the pokeapi app + python manage.py shell ${docker_config} + +devcontainer-setup: dev-install devcontainer-migrate devcontainer-build-db # (Dev Container) Install requirements, prepare the latest DB schema, populate the DB + format: # Format the source code black . From 42672eedb32b2e9c8e5b79d6587d962aad423561 Mon Sep 17 00:00:00 2001 From: PraaneshSelvaraj Date: Mon, 2 Jun 2025 15:44:27 +0530 Subject: [PATCH 4/5] devcontainer instructions --- CONTRIBUTING.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0d1efe63b..05bd41b52 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,37 @@ git checkout -b my_new_branch Simple! +## Development Environment +Want to get started quickly? Use [Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers). They provide a consistent, pre-configured development environment, ensuring you're ready to go without lengthy setup. + +### Prerequisites: + +* [**Docker**](https://www.docker.com/) (ensure Docker Desktop or your Docker daemon is running) +* [**Visual Studio Code**](https://code.visualstudio.com/) +* [**VS Code Dev Containers Extension**]() + +### Getting Started: + +1. **Open in Dev Container:** Open the project folder in VS Code. Click "Reopen in Container" when prompted (or use the Command Palette). + +2. **Initial Setup:** Once the container is ready, open a terminal and run: + ```bash + make devcontainer-setup + ``` + This command installs requirements, runs migrations, and populates the database. + +### Running Server (Inside the Dev Container): + +* Run Development Server (Django's built-in): + ```bash + make serve + ``` + +* Run Development Server (Gunicorn): + ```bash + make serve-gunicorn + ``` + ## Financial contributions We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/pokeapi). From ae80aa6e78b592aff9dbff0e7b2286e65fa883ee Mon Sep 17 00:00:00 2001 From: PraaneshSelvaraj Date: Tue, 3 Jun 2025 17:14:53 +0530 Subject: [PATCH 5/5] devcontainer dockerfile --- .devcontainer/Dockerfile | 31 +++++++++++++++++++++++ .devcontainer/devcontainer.json | 7 ++--- .devcontainer/docker-compose.override.yml | 6 +++-- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..1e3b946ff --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,31 @@ +ARG PYTHON_VERSION=3.12-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/python:${PYTHON_VERSION} + +ENV PYTHONUNBUFFERED=1 +ENV DJANGO_SETTINGS_MODULE='config.docker-compose' + +RUN mkdir /code +WORKDIR /code + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + libpq-dev \ + build-essential \ + rustc \ + cargo && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN addgroup --gid 1001 --system pokeapi && \ + adduser --uid 1001 --system --ingroup pokeapi --shell /bin/bash pokeapi + +RUN chown -R pokeapi:pokeapi /code + +USER pokeapi + +ADD requirements.txt /code/ +ADD test-requirements.txt /code/ +RUN python3 -m pip install -r test-requirements.txt --no-cache-dir + +ADD . /code/ + +CMD ["sleep", "infinity"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 070cb2c69..f15599fbe 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -47,13 +47,14 @@ "installOhMyZsh": "false", "configureZshAsDefaultShell": "false" }, - "ghcr.io/devcontainers/features/git:1": {} + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/docker-outside-of-docker": {} }, // Post-create commands: - "postCreateCommand": "apk add --no-cache make && git config --global core.autocrlf input", + "postCreateCommand": "git config --global core.autocrlf input && git config --global --add safe.directory /code", - "remoteUser": "root", + "remoteUser": "pokeapi", // Ports to forward from container to host for easy access "forwardPorts": [80, 443, 8000, 8080], diff --git a/.devcontainer/docker-compose.override.yml b/.devcontainer/docker-compose.override.yml index ce8cc5701..861bdb289 100644 --- a/.devcontainer/docker-compose.override.yml +++ b/.devcontainer/docker-compose.override.yml @@ -2,5 +2,7 @@ version: '2.4' services: app: - image: pokeapi/pokeapi:master - command: [] \ No newline at end of file + build: + context: . + dockerfile: ./.devcontainer/Dockerfile + user: pokeapi \ No newline at end of file