Skip to content
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
31 changes: 31 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
81 changes: 81 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "PokeAPI",

// Use multiple docker-compose files for development and overrides
"dockerComposeFile": [
"../docker-compose.yml",
"./docker-compose.override.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"
]
}
},

"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "false",
"installOhMyZsh": "false",
"configureZshAsDefaultShell": "false"
},
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/docker-outside-of-docker": {}
},

// Post-create commands:
"postCreateCommand": "git config --global core.autocrlf input && git config --global --add safe.directory /code",

"remoteUser": "pokeapi",

// 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"
}
}
}
8 changes: 8 additions & 0 deletions .devcontainer/docker-compose.override.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image from Docker Hub automatically starts the Gunicorn server, but for our Dev Container setup, we actually don't want it running by default. I've overridden the CMD to prevent that, as we use make commands to handle server startup.

To keep the main docker-compose.override.yml clean for its original purpose, I set up a separate override file just for the Dev Container here: .devcontainer/docker-compose-override.yml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Dev Container features like docker-outside-of-docker (and others), we typically need a Debian-based image for them to work properly.

Since our current image is built on Alpine Linux, I would suggest creating a separate Dockerfile inside the .devcontainers folder. This dedicated Dockerfile would then build our Dev Container image using a Debian base.

What do you think of this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, honestly I think it's too much work with few benefits :) If you like you could work on other issues.

Top two would be: helping @Indyandie with the new Astro website, polishing the openapi schema and make it available in the current website

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Naramsim,

Totally get where you're coming from on keeping things simple, and I completely agree that we shouldn't add complexity without good reason.

But, just wanted to quickly mention why I think Dev Containers could actually save us headaches long-term: it means anyone can jump in and contribute instantly, without wrestling with setup. It ensures everyone's development environment is the same, so we avoid "it works on my machine" issues. Plus, it works well with features like cloud development (like GitHub Codespaces).

It feels like a small upfront effort for a much smoother ride for all contributors, especially new ones.

If you still think this isn't required, I'll totally drop it and focus on other things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PraaneshSelvaraj sorry for coming back only now. I'm currently unable to fully review the devcontainer file honestly. Maybe I'll just merge it in and see if issues arise when people start using it. Still unsure. I have limited time currently

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Naramsim , Sounds good.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '2.4'

services:
app:
build:
context: .
dockerfile: ./.devcontainer/Dockerfile
user: pokeapi
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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 .

Expand Down
Loading