Skip to content

Commit

Permalink
Merge pull request #55 from ossf/scovetta/add-triage-portal
Browse files Browse the repository at this point in the history
Migrate code from ossf/omega-triage-portal to alpha-omega.
  • Loading branch information
Cyber-JiuJiteria authored Jan 4, 2023
2 parents 50f93dc + 9736427 commit 407ffdd
Show file tree
Hide file tree
Showing 125 changed files with 8,995 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .devcontainer/triage-portal/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
ARG VARIANT=3-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

ENV PYTHONUNBUFFERED 1

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# Install OSS Gadget
# License: MIT
ARG OSSGADGET_VERSION="0.1.307"
RUN cd /opt && \
wget -q https://github.com/microsoft/OSSGadget/releases/download/v${OSSGADGET_VERSION}/OSSGadget_linux_${OSSGADGET_VERSION}.tar.gz -O OSSGadget.tar.gz && \
tar zxvf OSSGadget.tar.gz && \
rm OSSGadget.tar.gz && \
mv OSSGadget_linux_${OSSGADGET_VERSION} OSSGadget

# [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 <your-package-list-here>



68 changes: 68 additions & 0 deletions .devcontainer/triage-portal/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.203.0/containers/python-3-postgres
// 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",
// Set *default* container specific settings.json values on container create.
"settings": {
"sqltools.connections": [
{
"name": "Container database",
"driver": "PostgreSQL",
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"database": "triage",
"username": "triage_user",
"password": "triage_password"
}
],
"python.pythonPath": "/usr/local/bin/python",
"python.languageServer": "Pylance",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest",
"python.defaultInterpreterPath": "${workspaceFolder}/alpha-omega/omega/triage-portal/.venv/bin/python"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"GitHub.copilot"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
8000
],
"portsAttributes": {
"8000": {
"label": "Triage Portal (Django)",
"protocol": "http",
"onAutoForward": "notify",
"requireLocalPort": false,
"elevateIfNeeded": false
}
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bash alpha-omega/.devcontainer/triage-portal/postcreate-initialize.sh",
"remoteEnv": {
"DJANGO_SETTINGS_MODULE": "core.settings",
"PYTHONPATH": "/workspaces/alpha-omega/omega/triage-portal/src"
},
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
54 changes: 54 additions & 0 deletions .devcontainer/triage-portal/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '3.8'

services:
app:
build:
context: ..
dockerfile: triage-portal/Dockerfile
args:
# Update 'VARIANT' to pick a version of Python: 3, 3.10, 3.9, 3.8, 3.7, 3.6
# Append -bullseye or -buster to pin to an OS version.
# Use -bullseye variants on local arm64/Apple Silicon.
VARIANT: 3-bullseye
# Optional Node.js version to install
NODE_VERSION: "lts/*"

volumes:
- ..:/workspace:cached
init: true

# 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: triage_user
POSTGRES_DB: triage
POSTGRES_PASSWORD: triage_password

redis:
image: redis:latest
restart: unless-stopped
network_mode: service:db
volumes:
- redis-data:/data

# 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:
redis-data:
49 changes: 49 additions & 0 deletions .devcontainer/triage-portal/postcreate-initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

ROOT="/workspaces/alpha-omega/omega/triage-portal"
cd "$ROOT"

# Create and activate the virtual environment
echo "Creating virtual environment."
python -mvenv .venv
source .venv/bin/activate

# Install Python dependencies
echo "Installing Python (back-end) dependencies."
cd $ROOT/src
python -m pip install --upgrade pip
pip install wheel
pip install -r ./requirements.txt

# Install JavaScript dependencies
echo "Installing JavaScript (front-end) dependencies."
cd $ROOT/src
npm i -g yarn
yarn

# Update default environment
echo "Creating development environment."
cd $ROOT/src
cp .env-template .env
SECRET_KEY=$(python -c "import secrets; print(secrets.token_hex(64))")
sed -i "s/%RANDOM_STRING%/$SECRET_KEY/" .env
unset SECRET_KEY

# Create working directories
echo "Creating working directories."
mkdir $ROOT/logs

# Set up database
echo "Setting up datatbase."
cd $ROOT/src
python manage.py migrate
python manage.py makemigrations
python manage.py migrate triage

# Create superuser
DJANGO_SUPERUSER_USERNAME="admin" \
DJANGO_SUPERUSER_PASSWORD="admin" \
DJANGO_SUPERUSER_EMAIL="nobody@localhost" \
python manage.py createsuperuser --noinput

echo "Initialization completed."
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/.vs
*.env
*.pyc
**/.mypy_cache
/omega/analyzer/worker/results
/venv/*
**/.venv
**/venv/
*.db
*.pem
oss-gadget.log
*.pem
**/.idea/workspace.xml
**/.idea/tasks.xml
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Triage Portal - Start Server (Debug)",
"type": "python",
"request": "launch",
"program": "src/manage.py",
"cwd": "${workspaceFolder}/omega/triage-portal",
"args": [
"runserver",
"0.0.0.0:8001"
],
"django": true
}
]
}
11 changes: 11 additions & 0 deletions .vscode/project.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"folders": [
{
"name": "triage-portal",
"path": "/workspaces/alpha-omega/omega/triage-portal"
},
{
"path": "../.devcontainer"
}
]
}
Loading

0 comments on commit 407ffdd

Please sign in to comment.