Skip to content

Commit 34bbce0

Browse files
author
Jose Hernandez
committed
overhaul for setup and build steps
1 parent 904f1ca commit 34bbce0

File tree

6 files changed

+125
-216
lines changed

6 files changed

+125
-216
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Project specific
2+
app/sigma/*
3+
poetry.lock
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

Dockerfile

+11-9
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@ RUN apt-get update && apt-get install -y \
1414
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
1515

1616
# define work directory
17-
WORKDIR /app/
17+
WORKDIR /repo/
1818

19-
# Copy pyproject.toml first
20-
COPY pyproject.toml uv.lock ./
19+
# Copy application files first
20+
COPY . .
21+
22+
# Ensure proper permissions
23+
RUN chown -R root:root /repo && \
24+
chmod -R 755 /repo
2125

2226
# Install main application dependencies with uv
2327
RUN uv venv && \
2428
. .venv/bin/activate && \
2529
uv pip install -e .
2630

27-
# Copy application files
28-
COPY app /app/app
29-
3031
# Make setup script executable
31-
RUN chmod +x /app/app/setup.py
32+
RUN chmod +x app/setup.py
3233

33-
# Setup Sigma versions using pip
34-
RUN cd /app/app && python setup.py
34+
# Setup Sigma versions using the virtual environment's Python
35+
RUN . .venv/bin/activate && \
36+
python app/setup.py
3537

3638
# launch application
3739
EXPOSE 8000

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ Welcome to sigconverter.io, a user-friendly converter for Sigma rules. This proj
1313

1414
## 🚀 Getting Started
1515

16-
### Without Docker:
16+
### Local Development:
1717

1818
```bash
19+
# Install Poetry if you haven't already
20+
curl -sSL https://install.python-poetry.org | python3 -
21+
22+
# Clone the repository
23+
git clone https://github.com/magicsword-io/sigconverter.io.git
24+
cd sigconverter.io
25+
1926
# Install dependencies
20-
cd backend
21-
pip install .
27+
poetry install
2228

2329
# Setup Sigma versions
24-
./setup-sigma-versions.sh
30+
poetry run python app/setup.py
2531

2632
# Run the application
27-
python backend.py
33+
poetry run python app/main.py
2834
```
2935

3036
### With Docker:

app/setup.py

+86-30
Original file line numberDiff line numberDiff line change
@@ -4,75 +4,128 @@
44
import subprocess
55
from pathlib import Path
66

7+
def get_sigma_versions():
8+
"""Fetch the 10 latest versions of sigma-cli from PyPI"""
9+
import requests
10+
response = requests.get("https://pypi.org/pypi/sigma-cli/json")
11+
versions = sorted(response.json()["releases"].keys())
12+
return versions[-10:] # Return 10 latest versions
13+
14+
def get_sigma_backends():
15+
"""Fetch all available Sigma backends from the plugin directory"""
16+
import requests
17+
try:
18+
response = requests.get("https://raw.githubusercontent.com/SigmaHQ/pySigma-plugin-directory/main/pySigma-plugins-v1.json")
19+
data = response.json()
20+
21+
# Skip problematic backends
22+
excluded_backends = {
23+
"pySigma-backend-hawk", # https://github.com/redsand/pySigma-backend-hawk/issues/1
24+
"pySigma-backend-kusto" # Known issues with kusto backend
25+
}
26+
27+
backends = []
28+
for plugin_id, plugin_info in data.get("plugins", {}).items():
29+
if "package" in plugin_info:
30+
package = plugin_info["package"]
31+
# Skip if package or its git URL is in excluded list
32+
if package not in excluded_backends and not any(excluded in package for excluded in excluded_backends):
33+
backends.append(package)
34+
35+
print(f"Found {len(backends)} backends to attempt installation")
36+
return backends
37+
except Exception as e:
38+
print(f"Error fetching backends: {e}")
39+
return ["pysigma-backend-splunk", "pysigma-backend-elasticsearch"]
40+
741
def install_core_backends(python_path, sigma_version):
842
"""Install core backends that are known to work"""
943
# First install required dependencies
1044
base_packages = [
1145
"pyyaml",
12-
f"sigma-cli=={sigma_version}",
13-
"pysigma>=0.9.0,<0.12.0", # Compatible with 1.0.x
1446
"setuptools",
15-
"wheel"
47+
"wheel",
48+
"requests",
49+
f"sigma-cli=={sigma_version}" # Install sigma-cli first
1650
]
1751

18-
# Install using pip instead of uv for better dependency resolution
52+
# Install base packages
1953
for package in base_packages:
2054
try:
2155
print(f"Installing {package}...")
2256
subprocess.run([
23-
python_path, "-m", "pip", "install", package
57+
str(python_path), "-m", "pip", "install", "--no-cache-dir", package
2458
], check=True)
2559
except subprocess.CalledProcessError as e:
26-
print(f"Warning: Failed to install {package}: {e}")
60+
print(f"Warning: Failed to install {package}")
2761
return False
2862

29-
# Install minimal set of backends
30-
backends = [
31-
"pysigma-backend-splunk>=0.9.0",
32-
"pysigma-backend-elasticsearch>=0.9.0"
33-
]
63+
# Install all available backends
64+
backends = get_sigma_backends()
65+
successful_installs = 0
3466

3567
for backend in backends:
3668
try:
37-
print(f"Installing {backend}...")
69+
print(f"Attempting to install backend: {backend}")
3870
subprocess.run([
39-
python_path, "-m", "pip", "install", backend
71+
str(python_path), "-m", "pip", "install", "--no-cache-dir", backend
4072
], check=True)
73+
successful_installs += 1
4174
except subprocess.CalledProcessError as e:
42-
print(f"Warning: Failed to install {backend}: {e}")
75+
print(f"Note: Backend {backend} failed to install - might be incompatible with sigma-cli {sigma_version}")
76+
continue
4377

44-
# Verify installation
45-
try:
46-
verify_cmd = [python_path, "-c", "import yaml; import sigma.backends"]
47-
subprocess.run(verify_cmd, check=True)
48-
return True
49-
except subprocess.CalledProcessError:
50-
print("Failed to verify package installation")
51-
return False
78+
print(f"Successfully installed {successful_installs} out of {len(backends)} backends")
79+
return successful_installs > 0 # Return True if at least one backend was installed
5280

5381
def setup_sigma_versions():
5482
"""Setup Sigma versions with their virtual environments"""
55-
versions = ["1.0.0", "1.0.1", "1.0.2", "1.0.3", "1.0.4"] # Hardcode versions for now
83+
versions = get_sigma_versions()
5684
installed_count = 0
5785
base_path = Path(__file__).parent / "sigma"
5886
base_path.mkdir(parents=True, exist_ok=True)
5987

88+
# Get the current Python executable
89+
import sys
90+
python_executable = sys.executable
91+
6092
for version in versions:
6193
print(f"\nSetting up Sigma version {version}")
6294
try:
6395
version_path = base_path / version
6496
version_path.mkdir(parents=True, exist_ok=True)
6597

66-
# Setup virtual environment using venv instead of uv
98+
# Setup virtual environment
6799
venv_path = version_path / "venv"
68-
subprocess.run([
69-
"python3", "-m", "venv", str(venv_path)
70-
], check=True)
100+
print(f"Creating virtual environment at: {venv_path}")
101+
102+
# Ensure the venv directory doesn't exist
103+
if venv_path.exists():
104+
import shutil
105+
shutil.rmtree(venv_path)
106+
107+
# Create venv using current Python executable
108+
try:
109+
subprocess.run([
110+
python_executable, "-m", "venv",
111+
"--clear", "--system-site-packages",
112+
str(venv_path)
113+
], check=True, capture_output=True, text=True)
114+
except subprocess.CalledProcessError as e:
115+
print(f"venv creation output: {e.stdout}")
116+
print(f"venv creation error: {e.stderr}")
117+
raise
118+
119+
# Verify venv creation
120+
python_path = venv_path / "bin" / "python"
121+
if not python_path.exists():
122+
raise Exception(f"Python executable not found at {python_path}")
71123

72-
python_path = str(venv_path / "bin" / "python")
124+
print(f"Virtual environment created at: {venv_path}")
125+
print(f"Python executable path: {python_path}")
73126

74127
# Install core backends and verify
75-
if install_core_backends(python_path, version):
128+
if install_core_backends(str(python_path), version):
76129
# Copy worker script to version directory
77130
worker_path = Path(__file__).parent / "worker.py"
78131
if worker_path.exists():
@@ -86,6 +139,8 @@ def setup_sigma_versions():
86139

87140
except Exception as e:
88141
print(f"Error setting up version {version}: {e}")
142+
import traceback
143+
traceback.print_exc()
89144
continue
90145

91146
return installed_count
@@ -95,4 +150,5 @@ def setup_sigma_versions():
95150
if count == 0:
96151
print("Error: No Sigma versions were installed successfully")
97152
exit(1)
98-
print(f"Successfully installed {count} Sigma versions")
153+
154+
print(f"Successfully installed {count} Sigma versions")

pyproject.toml

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
[project]
1+
[tool.poetry]
22
name = "sigconverter"
33
version = "1.0.0"
44
description = "SigConverter - Sigma rule converter web application"
5+
authors = ["Magic Sword <[email protected]>"]
56
readme = "README.md"
6-
requires-python = ">=3.10"
7-
authors = [{ name = "Magic Sword", email = "[email protected]" }]
8-
dependencies = [
9-
"flask>=3.0.3",
10-
"setuptools>=75.1.0",
11-
"requests>=2.32.3",
12-
"pyyaml>=6.0.1"
13-
]
7+
packages = [{include = "app"}]
8+
9+
[tool.poetry.dependencies]
10+
python = ">=3.10"
11+
flask = ">=3.0.3"
12+
setuptools = ">=75.1.0"
13+
requests = ">=2.32.3"
14+
pyyaml = ">=6.0.1"
15+
16+
[build-system]
17+
requires = ["poetry-core"]
18+
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)