From 7fb0069b0a0174c3ee31333cb5f1d66a55c76b34 Mon Sep 17 00:00:00 2001 From: Carlos Holguera Date: Sun, 14 Jul 2024 18:37:25 +0200 Subject: [PATCH] Add Dockerfile and .devcontainer to run website locally (#2814) * Add Dockerfile to run website locally and to run as devcontainer --- .devcontainer/devcontainer.json | 35 +++++++++++++++++++++++++++++++++ .dockerignore | 6 ++++++ Dockerfile | 26 ++++++++++++++++++++++++ run_web.sh | 4 +++- src/scripts/structure_masvs.sh | 2 ++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..08b0d1f956 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +{ + "name": "MkDocs-VSCode", + "build": { + "context": "..", + "dockerfile": "../Dockerfile" + }, + "customizations": { + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "debug.javascript.usePreview": false + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "yzhang.markdown-all-in-one", + "redhat.vscode-yaml", + "shardulm94.trailing-spaces", + "oderwat.indent-rainbow", + "msjsdiag.debugger-for-chrome", + "ms-python.python", + "ms-python.debugpy", + "davidanson.vscode-markdownlint", + "timonwong.shellcheck", + "ms-python.vscode-pylance" + ] + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 8000 + ] + // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. + //"remoteUser": "vscode" +} \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..96066cdcf3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +dist +build +.git +Dockerfile +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..3521fcfb6d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Use the latest Python image +FROM python:3-slim + +# Install dependencies +RUN apt-get update && \ + apt-get install -y git jq curl && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +COPY src/scripts/requirements.txt . +RUN python -m pip install --no-cache-dir -r requirements.txt + +# Clone the OWASP MASVS as required by the website build +RUN git clone --depth 1 https://github.com/OWASP/owasp-masvs.git /workspaces/owasp-masvs + +# Set the working directory this way to be compatible with devcontainers and also run independently +WORKDIR /workspaces/owasp-mastg + +# Expose port 8000 +EXPOSE 8000 + +# Start the container with a shell +CMD ["bash"] + +# If running manually: docker run -it --rm -p 8000:8000 -v $(pwd):/workspaces/owasp-mastg mastg diff --git a/run_web.sh b/run_web.sh index f78893a73f..5303045ea1 100755 --- a/run_web.sh +++ b/run_web.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # rm -rf docs/MASTG # rm -rf docs/MASWE rm -rf docs/MASTG/tests-beta @@ -9,4 +11,4 @@ python3 src/scripts/transform_files.py python3 src/scripts/populate_dynamic_pages.py python3 src/scripts/generate_cross_references.py # python3 src/scripts/generate_redirects.py -mkdocs serve -a localhost:8002 +mkdocs serve -a 0.0.0.0:8000 diff --git a/src/scripts/structure_masvs.sh b/src/scripts/structure_masvs.sh index 2c5dfbadea..cf5a5b6eca 100755 --- a/src/scripts/structure_masvs.sh +++ b/src/scripts/structure_masvs.sh @@ -1,3 +1,5 @@ +#!/bin/bash + if [ -d "../owasp-masvs/" ] ; then MASVS_DIR=../owasp-masvs elif [ -d "./owasp-masvs/" ] ; then