Skip to content

Commit

Permalink
Enhancement/GitHub codespaces (#2686)
Browse files Browse the repository at this point in the history
* Adds devcontainer configuration
  • Loading branch information
kevgliss authored Nov 10, 2022
1 parent d48ec53 commit 722c689
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 141 deletions.
15 changes: 15 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
38 changes: 38 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
11 changes: 11 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions docker/.env.example → .env.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ ipython_config.py

# Environments
.env
!data/.env
.venv
env/
venv/
Expand Down
8 changes: 8 additions & 0 deletions bin/dispatch
Original file line number Diff line number Diff line change
@@ -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())
6 changes: 0 additions & 6 deletions data/.env

This file was deleted.

1 change: 0 additions & 1 deletion docker/.dockerignore

This file was deleted.

100 changes: 0 additions & 100 deletions docker/Dockerfile

This file was deleted.

28 changes: 0 additions & 28 deletions docker/docker-compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/dispatch/static/dispatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/dispatch/static/dispatch/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Components from "unplugin-vue-components/vite"

import path from "path"


export default defineConfig({
plugins: [
vue2(),
Expand All @@ -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,
},
Expand Down

0 comments on commit 722c689

Please sign in to comment.