diff --git a/.devcontainer/.env.example b/.devcontainer/.env.example new file mode 100644 index 000000000000..f86be870a11f --- /dev/null +++ b/.devcontainer/.env.example @@ -0,0 +1,6 @@ +LOG_LEVEL="ERROR" +STATIC_DIR="" +DATABASE_HOSTNAME="localhost" +DATABASE_CREDENTIALS="dispatch:dispatch" +DISPATCH_ENCRYPTION_KEY="NJHDWDJ3PbHT8h" +DISPATCH_JWT_SECRET="foo" diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000000..c79e86b29b59 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,15 @@ +FROM mcr.microsoft.com/devcontainers/python:3.9-bullseye + +ENV PYTHONUNBUFFERED 1 + +ARG NODE_VERSION="16" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] If your requirements rarely change, uncomment this section to add them to the image. +# COPY requirements.txt /tmp/pip-tmp/ +# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ +# && rm -rf /tmp/pip-tmp + +# [Optional] Uncomment this section to install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends postgresql postgresql-contrib diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000000..cd8f55d6e59c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +// Update the VARIANT arg in docker-compose.yml to pick a Python version +{ + "name": "Python 3 & PostgreSQL", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "features": { + "ghcr.io/devcontainers-contrib/features/black:1": {}, + "ghcr.io/devcontainers-contrib/features/coverage-py:1": {}, + }, + // Features to add to the dev container. More info: https://containers.dev/implementors/features. + // "features": {}, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // This can be used to network with other containers or the host. + "forwardPorts": [ + 8000, + 8080, + 5432, + 5555 + ], + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "./.devcontainer/postCreateCommand.sh" + // Configure tool-specific properties. + // "customizations": {}, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 000000000000..34ac06c574d6 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,45 @@ +version: '3.8' + +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Uncomment the next line to use a non-root user for all processes. + # user: vscode + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + admin: + image: dpage/pgadmin4 + environment: + PGADMIN_DEFAULT_EMAIL: dispatch@netflix.com + PGADMIN_DEFAULT_PASSWORD: admin + restart: unless-stopped + network_mode: service:db + + db: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_USER: dispatch + POSTGRES_DB: dispatch + POSTGRES_PASSWORD: dispatch + + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + postgres-data: diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100644 index 000000000000..891c4dfee9f6 --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,11 @@ +pip install -e /workspaces/dispatch +npm install --prefix /workspaces/dispatch/src/dispatch/static/dispatch + +export LOG_LEVEL="ERROR" +export STATIC_DIR="" +export DATABASE_HOSTNAME="localhost" +export DATABASE_CREDENTIALS="dispatch:dispatch" +export DISPATCH_ENCRYPTION_KEY="NJHDWDJ3PbHT8h" +export DISPATCH_JWT_SECRET="foo" +dispatch database restore --dump-file /workspaces/dispatch/data/dispatch-sample-data.dump +dispatch database upgrade diff --git a/src/dispatch/static/dispatch/package.json b/src/dispatch/static/dispatch/package.json index 33db248bf3bd..7d382d2b53c9 100644 --- a/src/dispatch/static/dispatch/package.json +++ b/src/dispatch/static/dispatch/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "serve": "cross-env NODE_ENV=dev NODE_OPTIONS='--max-http-header-size=100000' vite --open", + "serve": "cross-env NODE_ENV=dev NODE_OPTIONS='--max-http-header-size=100000' vite", "preview": "vite preview --open --port 8080", "build": "vite build --out-dir dist", "lint": "eslint src", diff --git a/src/dispatch/static/dispatch/vite.config.js b/src/dispatch/static/dispatch/vite.config.js index 17bcb17e251a..dd3489652f27 100644 --- a/src/dispatch/static/dispatch/vite.config.js +++ b/src/dispatch/static/dispatch/vite.config.js @@ -24,7 +24,7 @@ export default defineConfig({ port: 8080, proxy: { "^/api": { - target: "http://127.0.0.1:8000", + target: "http://localhost:8000", ws: false, changeOrigin: true, },