diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000000..d4c55498d59e --- /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..9344025dec50 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// 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 + ], + // 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..7282d63c2a97 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,38 @@ +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.) + + 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 100755 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/docker/.env.example b/.env.example similarity index 72% rename from docker/.env.example rename to .env.example index 815dbc9339e3..23cb414f7514 100644 --- a/docker/.env.example +++ b/.env.example @@ -1,9 +1,12 @@ # General DISPATCH_UI_URL="" -# Persistence -DATABASE_HOSTNAME="" -DATABASE_CREDENTIALS="" +LOG_LEVEL="ERROR" +STATIC_DIR="" +DATABASE_HOSTNAME="localhost" +DATABASE_CREDENTIALS="dispatch:dispatch" +DISPATCH_ENCRYPTION_KEY="NJHDWDJ3PbHT8h" +DISPATCH_JWT_SECRET="foo" # Authentication # For basic authentication see: https://hawkins.gitbook.io/dispatch/administration-guide/server#configuration-for-dispatch-auth-provider-basic diff --git a/.gitignore b/.gitignore index b4d80df646ff..893e6ad2210f 100644 --- a/.gitignore +++ b/.gitignore @@ -130,7 +130,6 @@ ipython_config.py # Environments .env -!data/.env .venv env/ venv/ diff --git a/bin/dispatch b/bin/dispatch new file mode 100755 index 000000000000..a6995ce46bc7 --- /dev/null +++ b/bin/dispatch @@ -0,0 +1,8 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from dispatch.cli import entrypoint +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(entrypoint()) diff --git a/data/.env b/data/.env deleted file mode 100644 index 2174b5360f5d..000000000000 --- a/data/.env +++ /dev/null @@ -1,6 +0,0 @@ -# General -LOG_LEVEL=ERROR -STATIC_DIR="" -DATABASE_HOSTNAME=localhost -DATABASE_CREDENTIALS=dispatch:dispatch -DISPATCH_ENCRYPTION_KEY=NJHDWDJ3PbHT8h diff --git a/docker/.dockerignore b/docker/.dockerignore deleted file mode 100644 index 3c3629e647f5..000000000000 --- a/docker/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index ecef9269f485..000000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,100 +0,0 @@ -FROM python:3.9.7-slim-buster as sdist - -LABEL maintainer="oss@netflix.com" -LABEL org.opencontainers.image.title="Dispatch PyPI Wheel" -LABEL org.opencontainers.image.description="PyPI Wheel Builder for Dispatch" -LABEL org.opencontainers.image.url="https://dispatch.io/" -LABEL org.opencontainers.image.source="https://github.com/netflix/dispatch" -LABEL org.opencontainers.image.vendor="Netflix, Inc." -LABEL org.opencontainers.image.authors="oss@netflix.com" - -# Get and set up Node for front-end asset building -RUN apt-get update && apt-get install -y --no-install-recommends \ - # Needed for fetching stuff - ca-certificates \ - wget \ - && rm -rf /var/lib/apt/lists/* - -RUN set -x \ - && wget --quiet -O - https://deb.nodesource.com/setup_16.x | bash - \ - && apt-get install -y nodejs - -ARG SOURCE_COMMIT -ENV DISPATCH_BUILD=${SOURCE_COMMIT:-unknown} -LABEL org.opencontainers.image.revision=$SOURCE_COMMIT -LABEL org.opencontainers.image.licenses="https://github.com/netflix/dispatch/blob/${SOURCE_COMMIT:-master}/LICENSE" - -ARG DISPATCH_LIGHT_BUILD -ENV DISPATCH_LIGHT_BUILD=${DISPATCH_LIGHT_BUILD} - -RUN echo "DISPATCH_LIGHT_BUILD=${DISPATCH_LIGHT_BUILD}" - -COPY . /usr/src/dispatch/ -RUN export YARN_CACHE_FOLDER="$(mktemp -d)" \ - && cd /usr/src/dispatch \ - && python setup.py bdist_wheel \ - && rm -r "$YARN_CACHE_FOLDER" \ - && mv /usr/src/dispatch/dist /dist - -# This is the image to be run -FROM python:3.9.7-slim-buster - -LABEL maintainer="oss@dispatch.io" -LABEL org.opencontainers.image.title="Dispatch" -LABEL org.opencontainers.image.description="Dispatch runtime image" -LABEL org.opencontainers.image.url="https://github.com/netflix/dispatch" -LABEL org.opencontainers.image.documentation="https://github.com/netflix/dispatch" -LABEL org.opencontainers.image.source="https://github.com/netflix/dispatch" -LABEL org.opencontainers.image.vendor="Netflix, Inc." -LABEL org.opencontainers.image.authors="oss@netflix.com" - - -# add our user and group first to make sure their IDs get assigned consistently -RUN groupadd -r dispatch && useradd -r -m -g dispatch dispatch - -# Sane defaults for pip -ENV PIP_NO_CACHE_DIR=off \ - PIP_DISABLE_PIP_VERSION_CHECK=1 \ - # Dispatch config params - DISPATCH_CONF=/etc/dispatch - -RUN apt-get update && apt-get install -y --no-install-recommends \ - # Needed for fetching stuff - ca-certificates \ - wget gnupg \ - && rm -rf /var/lib/apt/lists/* - -RUN set -x \ - && echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ - && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - - -RUN set -x \ - && wget --quiet -O - https://deb.nodesource.com/setup_12.x | bash - - -COPY --from=sdist /dist/*.whl /tmp/dist/ -RUN set -x \ - && buildDeps="" \ - && apt-get update \ - && apt-get install -y --no-install-recommends $buildDeps \ - # remove internal index when internal plugins are seperated - && pip install -U /tmp/dist/*.whl \ - && apt-get purge -y --auto-remove $buildDeps \ - # We install run-time dependencies strictly after - # build dependencies to prevent accidental collusion. - # These are also installed last as they are needed - # during container run and can have the same deps w/ - && apt-get install -y --no-install-recommends \ - pkg-config postgresql-client-12 nodejs \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && npm install mjml - -EXPOSE 8000 -VOLUME /var/lib/dispatch/files - -ENTRYPOINT ["dispatch"] -CMD ["server", "start", "dispatch.main:app", "--host=0.0.0.0"] - -ARG SOURCE_COMMIT -LABEL org.opencontainers.image.revision=$SOURCE_COMMIT -LABEL org.opencontainers.image.licenses="https://github.com/netflix/dispatch/blob/${SOURCE_COMMIT:-master}/LICENSE" diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml deleted file mode 100644 index 8e09724b2cb9..000000000000 --- a/docker/docker-compose.yml +++ /dev/null @@ -1,28 +0,0 @@ -version: "3.1" -services: - postgres: - image: postgres:12 - hostname: postgres - ports: - - "5432:5432" - environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: dispatch - POSTGRES_DB: dispatch - volumes: - - postgres-data:/var/lib/postgresql/data - restart: unless-stopped - - pgadmin: - image: dpage/pgadmin4 - depends_on: - - postgres - ports: - - "5555:80" - environment: - PGADMIN_DEFAULT_EMAIL: dispatch@netflix.com - PGADMIN_DEFAULT_PASSWORD: admin - restart: unless-stopped - -volumes: - postgres-data: diff --git a/src/dispatch/static/dispatch/package.json b/src/dispatch/static/dispatch/package.json index 86fd5537c384..b00cd63af541 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..4afc8d5387d4 100644 --- a/src/dispatch/static/dispatch/vite.config.js +++ b/src/dispatch/static/dispatch/vite.config.js @@ -8,6 +8,7 @@ import Components from "unplugin-vue-components/vite" import path from "path" + export default defineConfig({ plugins: [ vue2(), @@ -24,7 +25,7 @@ export default defineConfig({ port: 8080, proxy: { "^/api": { - target: "http://127.0.0.1:8000", + target: `http://localhost:8000`, ws: false, changeOrigin: true, },