-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from magicsword-io/feat/multi-sigma-versions
split into frontend and backend to support multiple sigma versions in parallel
- Loading branch information
Showing
20 changed files
with
957 additions
and
919 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ on: | |
push: | ||
branches: | ||
- main | ||
schedule: | ||
- cron: "0 0 * * 0" | ||
|
||
env: | ||
SERVICE_NAME: sigconverter | ||
|
@@ -14,23 +16,23 @@ jobs: | |
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Google Cloud SDK | ||
uses: google-github-actions/[email protected] | ||
with: | ||
project_id: ${{ secrets.PROJECT_ID }} | ||
service_account_key: ${{ secrets.GCLOUD_AUTH }} | ||
- name: Setup Google Cloud SDK | ||
uses: google-github-actions/[email protected] | ||
with: | ||
project_id: ${{ secrets.PROJECT_ID }} | ||
service_account_key: ${{ secrets.GCLOUD_AUTH }} | ||
|
||
- name: Configure Docker | ||
run: gcloud auth configure-docker | ||
- name: Configure Docker | ||
run: gcloud auth configure-docker | ||
|
||
- name: Build Docker image | ||
run: docker build -t ${{ env.IMAGE_NAME }} . | ||
- name: Build Docker image | ||
run: docker build -t ${{ env.IMAGE_NAME }} . | ||
|
||
- name: Push Docker image to Google Container Registry | ||
run: gcloud builds submit --tag gcr.io/${{ secrets.PROJECT_ID }}/${{ env.IMAGE_NAME }} | ||
- name: Push Docker image to Google Container Registry | ||
run: gcloud builds submit --tag gcr.io/${{ secrets.PROJECT_ID }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Deploy to Google Cloud Run | ||
run: gcloud run deploy ${{ env.SERVICE_NAME }} --image gcr.io/${{ secrets.PROJECT_ID }}/${{ env.IMAGE_NAME }} --platform managed --region us-central1 | ||
- name: Deploy to Google Cloud Run | ||
run: gcloud run deploy ${{ env.SERVICE_NAME }} --image gcr.io/${{ secrets.PROJECT_ID }}/${{ env.IMAGE_NAME }} --platform managed --region us-central1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Backend Packages Test | ||
name: Frontend Packages Test | ||
|
||
on: # yamllint disable-line rule:truthy | ||
push: | ||
|
@@ -12,18 +12,23 @@ on: # yamllint disable-line rule:truthy | |
- main | ||
|
||
jobs: | ||
test-poetry-package: | ||
pip-package: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
submodules: true | ||
- uses: actions/[email protected] | ||
with: | ||
submodules: true | ||
|
||
- name: Set up Python 3.11 | ||
uses: actions/[email protected] | ||
with: | ||
python-version: 3.11 | ||
- name: Set up Python 3.11 | ||
uses: actions/[email protected] | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: Test poetry package installation | ||
run: | | ||
python -m pip install poetry && poetry install | ||
- name: Install the latest version of uv | ||
uses: astral-sh/setup-uv@v3 | ||
with: | ||
version: "latest" | ||
|
||
- name: Test uv package installation | ||
run: uv venv && uv pip sync pyproject.toml | ||
working-directory: frontend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,17 @@ | ||
# Use the specified Python version | ||
FROM python:3.11.4-slim-buster | ||
|
||
# Configure Poetry | ||
ENV POETRY_VERSION=1.6.1 | ||
ENV POETRY_HOME=/opt/poetry | ||
ENV POETRY_VENV=/opt/poetry-venv | ||
ENV POETRY_CACHE_DIR=/opt/.cache | ||
# install dependencies | ||
RUN apt-get update | ||
RUN apt-get install -y git curl jq | ||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv | ||
|
||
# Install poetry separated from system interpreter | ||
RUN python3 -m venv $POETRY_VENV \ | ||
&& $POETRY_VENV/bin/pip install -U pip setuptools \ | ||
&& $POETRY_VENV/bin/pip install poetry==${POETRY_VERSION} | ||
|
||
# Add `poetry` to PATH | ||
ENV PATH="${PATH}:${POETRY_VENV}/bin" | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Install dependencies | ||
COPY poetry.lock pyproject.toml ./ | ||
RUN poetry install | ||
|
||
# Copy the flask app to the working directory | ||
# define work directory | ||
WORKDIR /app/ | ||
COPY . /app | ||
|
||
# Run the application | ||
# install backend | ||
RUN cd backend && ./setup-sigma-versions.sh | ||
|
||
# launch front- and backend | ||
EXPOSE 8000 | ||
CMD [ "poetry", "run", "python", "./run.py" ] | ||
ENTRYPOINT ["./entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# Specify the directory to search in (or use the current directory) | ||
directory="./" | ||
|
||
# Iterate over all subdirectories | ||
for dir in "$directory"/*/; do | ||
if [ -d "$dir" ]; then | ||
version=$(basename $dir) | ||
echo "Launching sigconverter backend for sigma version: $version" | ||
./$version/.venv/bin/python ./backend.py & | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[project] | ||
name = "sigconverter-backend" | ||
version = "1.0.0" | ||
description = "backend for the sigconverter projects" | ||
readme = "README.md" | ||
requires-python = ">=3.10" | ||
authors = [{ name = "Magic Sword", email = "[email protected]" }] | ||
dependencies = [ | ||
"flask>=3.0.3", | ||
"setuptools>=75.1.0", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# fetch 10 latest versions of sigma-cli | ||
SIGMA_VERSIONS=$(curl -s https://pypi.org/pypi/sigma-cli/json | jq -r '.releases | keys | .[-10:] | .[]') | ||
|
||
# prepare virtualenv for each version | ||
for VERSION in $SIGMA_VERSIONS; do | ||
# prepare folder to contain a single version | ||
mkdir $VERSION | ||
cp pyproject.toml uv.lock $VERSION | ||
cd $VERSION | ||
uv venv && uv -q pip sync pyproject.toml | ||
|
||
# fetch all plugins from plugin directory json and install latest compatible plugins available | ||
uv -q add sigma-cli==$VERSION | ||
curl https://raw.githubusercontent.com/SigmaHQ/pySigma-plugin-directory/refs/heads/main/pySigma-plugins-v1.json | jq '.plugins[].package' | xargs -n 1 uv add -q | ||
|
||
# remove if installed because of https://github.com/redsand/pySigma-backend-hawk/issues/1 | ||
uv -q remove pySigma-backend-hawk | ||
|
||
# TODO: some problems with kusto backend, disable for now | ||
uv -q remove pySigma-backend-kusto | ||
|
||
# remove unused pyparsing imports in older version, see https://github.com/SigmaHQ/pySigma/pull/289#issuecomment-2410153076 | ||
find ./ -iwholename "*sigma/conversion/base.py" -exec sed -i "/from pyparsing import Set/d" {} + | ||
find ./ -iwholename "*sigma/exceptions.py" -exec sed -i "/from pyparsing import List/d" {} + | ||
cd .. | ||
done |
Oops, something went wrong.