diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 8627d06..0000000 --- a/.env.sample +++ /dev/null @@ -1,5 +0,0 @@ -export TEAM_ID=$(cs list workspaces | grep $WORKSPACE_ID | awk '{print $2}') -export UV_PYTHON_INSTALL_DIR=/home/user/app/.codesphere-internal/.uv-python-install -export UV_PYTHON_BIN_DIR=/home/user/app/.codesphere-internal/.uv-python-bin -export UV_CACHE_DIR=/home/user/app/.codesphere-internal/.uv -export UV_PYTHON_CACHE_DIR=/home/user/app/.codesphere-internal/.uv-python \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 09138ab..c6558c4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,7 +18,6 @@ codesphere-deploy: PLAN: 'Micro' ON_DEMAND: 'false' ENV: | - CS_TOKEN=$CODESPHERE_TOKEN environment: name: 'Preview Deployment Python MR_$CI_MERGE_REQUEST_IID' on_stop: codesphere-teardown diff --git a/README.md b/README.md index bfcc8f0..76fe946 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # python-demo test -before running any stage you will need to set up a 'CS_TOKEN' env var containing an Codesphere API key. +This is a Python demo application with a Streamlit frontend and FastAPI backend. # open backend api docs diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..aca0a52 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,10 @@ +# Main dependencies +fastapi[all]>=0.115.12 +numpy>=2.3.0 +pandas>=2.3.0 +pytest-cov>=6.1.1 +pytest-profiling>=1.8.1 + +# Dev dependencies (for testing and security checks) +bandit>=1.8.3 +pytest>=8.4.0 diff --git a/ci.DEV.yml b/ci.DEV.yml new file mode 100644 index 0000000..ed6fa2e --- /dev/null +++ b/ci.DEV.yml @@ -0,0 +1,52 @@ +schemaVersion: v0.2 +prepare: + steps: + - name: install frontend dependencies + command: cd frontend && virtualenv .venv && .venv/bin/pip install -r requirements.txt + - name: install backend dependencies + command: cd backend && virtualenv .venv && .venv/bin/pip install -r requirements.txt +test: + steps: + - name: test frontend + command: cd frontend && .venv/bin/python -m pytest + - name: test backend + command: cd backend && .venv/bin/python -m pytest + - name: security check frontend + command: 'cd frontend && .venv/bin/python -m bandit -r . -c pyproject.toml + --format=custom --msg-template "{abspath}:{line}: {test_id}[{severity}]: + {msg}" -o bandit-results.txt' + - name: security check backend + command: 'cd backend && .venv/bin/python -m bandit -r . -c pyproject.toml + --format=custom --msg-template "{abspath}:{line}: {test_id}[{severity}]: + {msg}" -o bandit-results.txt' +run: + frontend: + steps: + - name: start frontend application + command: cd frontend && .venv/bin/python -m streamlit run --server.address 0.0.0.0 + --server.port 3000 main.py + plan: 20 + replicas: 1 + isPublic: true + network: + path: / + stripPath: false + backend: + steps: + - name: start backend application + command: cd backend && .venv/bin/python -m uvicorn app:app --reload --port 3000 + --host 0.0.0.0 + plan: 20 + replicas: 1 + isPublic: false + api-docs: + steps: + - name: deploy docs + command: cd backend && .venv/bin/python -m uvicorn doc:app_docs --host 0.0.0.0 + --port 3000 + plan: 20 + replicas: 1 + isPublic: true + network: + path: /api + stripPath: false \ No newline at end of file diff --git a/ci.PROD.yml b/ci.PROD.yml new file mode 100644 index 0000000..3af153b --- /dev/null +++ b/ci.PROD.yml @@ -0,0 +1,45 @@ +schemaVersion: v0.2 +prepare: + steps: + - name: install frontend dependencies + command: cd frontend && virtualenv .venv && .venv/bin/pip install -r requirements.txt + - name: install backend dependencies + command: cd backend && virtualenv .venv && .venv/bin/pip install -r requirements.txt + - name: optimize python bytecode + command: cd frontend && .venv/bin/python -m compileall -b . + - name: optimize backend bytecode + command: cd backend && .venv/bin/python -m compileall -b . +test: + steps: [] +run: + frontend: + steps: + - name: start frontend application + command: "cd frontend && .venv/bin/python -m streamlit run main.py --server.headless true + --server.address 0.0.0.0 --server.port 3000 --browser.gatherUsageStats + false --logger.level warning --server.enableCORS false --server.enableXsrfProtection true" + plan: 8 + replicas: 2 + isPublic: true + network: + path: / + stripPath: false + backend: + steps: + - name: start backend application + command: cd backend && .venv/bin/python -m uvicorn app:app --port 3000 --host 0.0.0.0 + --workers 4 --worker-class uvicorn.workers.UvicornWorker --access-log --no-use-colors + plan: 8 + replicas: 2 + isPublic: false + api-docs: + steps: + - name: deploy docs + command: cd backend && .venv/bin/python -m uvicorn doc:app_docs --host 0.0.0.0 --port 3000 + --workers 2 --access-log --no-use-colors + plan: 8 + replicas: 1 + isPublic: true + network: + path: /api + stripPath: false \ No newline at end of file diff --git a/ci.QA.yml b/ci.QA.yml new file mode 100644 index 0000000..6ff661d --- /dev/null +++ b/ci.QA.yml @@ -0,0 +1,41 @@ +schemaVersion: v0.2 +prepare: + steps: + - name: install frontend dependencies + command: cd frontend && virtualenv .venv && .venv/bin/pip install -r requirements.txt + - name: install backend dependencies + command: cd backend && virtualenv .venv && .venv/bin/pip install -r requirements.txt +test: + steps: [] +run: + frontend: + steps: + - name: start frontend application + command: "cd frontend && .venv/bin/python -m streamlit run main.py + --server.headless true --server.address 0.0.0.0 --server.port 3000 + --browser.gatherUsageStats false --logger.level info" + plan: 20 + replicas: 1 + isPublic: true + network: + path: / + stripPath: false + backend: + steps: + - name: start backend application + command: cd backend && .venv/bin/python -m uvicorn app:app --port 3000 --host + 0.0.0.0 --workers 2 + plan: 20 + replicas: 1 + isPublic: false + api-docs: + steps: + - name: deploy docs + command: cd backend && .venv/bin/python -m uvicorn doc:app_docs --host 0.0.0.0 + --port 3000 --workers 2 + plan: 20 + replicas: 1 + isPublic: true + network: + path: /api + stripPath: false diff --git a/ci.Qa.yml b/ci.Qa.yml deleted file mode 100644 index 3d0f976..0000000 --- a/ci.Qa.yml +++ /dev/null @@ -1,59 +0,0 @@ -schemaVersion: v0.2 -prepare: - steps: - - name: install Codesphere cli tool - command: mkdir -p $HOME/.local/bin && wget -qO- - 'https://api.github.com/repos/codesphere-cloud/cs-go/releases/latest' | - grep linux_amd64 | grep browser_download_url | sed s/.*https/https/ | - sed s/\".*$// | xargs wget -O $HOME/.local/bin/cs && chmod +x - $HOME/.local/bin/cs - - name: install uv standalone version - command: curl -LsSf https://astral.sh/uv/install.sh | env - UV_INSTALL_DIR="$HOME/app" sh && chmod +x $HOME/app/uv - - command: cp -n .env.sample .env - - name: "set ev vars " - command: . .env && cs set-env -w $WORKSPACE_ID -t $TEAM_ID --env-var - UV_PYTHON_INSTALL_DIR=$PWD/.codesphere-internal/.uv-python-install - --env-var UV_PYTHON_BIN_DIR=$PWD/.codesphere-internal/.uv-python-bin - --env-var UV_CACHE_DIR=$PWD/.codesphere-internal/.uv --env-var - UV_PYTHON_CACHE_DIR=$PWD/.codesphere-internal/.uv-python - - name: install frontend environment - command: . ./env && cd frontend && { [ ! -d ".venv" ] && uv venv; uv sync - --no-dev; } - - name: install backend environment - command: . ./env && cd backend && { [ ! -d ".venv" ] && uv venv; uv sync - --no-dev; } -test: - steps: [] -run: - frontend: - steps: - - name: start frontend application - command: ". ./env && cd frontend && uv run streamlit run main.py - --server.headless true --server.address 0.0.0.0 --server.port 3000 - --browser.gatherUsageStats false --logger.level info " - plan: 20 - replicas: 1 - isPublic: true - network: - path: / - stripPath: false - backend: - steps: - - name: start backend application - command: . ./env && cd backend && uv run uvicorn app:app --port 3000 --host - 0.0.0.0 --workers 2 - plan: 20 - replicas: 1 - isPublic: false - api-docs: - steps: - - name: deploy docs - command: . ./env && cd backend && uv run uvicorn doc:app_docs --host 0.0.0.0 - --port 3000 --workers 2 - plan: 20 - replicas: 1 - isPublic: true - network: - path: /api - stripPath: false diff --git a/ci.dev.yml b/ci.dev.yml deleted file mode 100644 index b82cf69..0000000 --- a/ci.dev.yml +++ /dev/null @@ -1,69 +0,0 @@ -schemaVersion: v0.2 -prepare: - steps: - - name: install Codesphere cli tool - command: mkdir -p $HOME/.local/bin && wget -qO- - 'https://api.github.com/repos/codesphere-cloud/cs-go/releases/latest' | - grep linux_amd64 | grep browser_download_url | sed s/.*https/https/ | - sed s/\".*$// | xargs wget -O $HOME/.local/bin/cs && chmod +x - $HOME/.local/bin/cs - - name: install uv standalone version - command: curl -LsSf https://astral.sh/uv/install.sh | env - UV_INSTALL_DIR="$HOME/app" sh && chmod +x $HOME/app/uv - - name: copy template .env file - command: cp -n .env.sample .env - - name: "set ev vars " - command: . .env && cs set-env -w $WORKSPACE_ID -t $TEAM_ID --env-var - UV_PYTHON_INSTALL_DIR=$PWD/.codesphere-internal/.uv-python-install - --env-var UV_PYTHON_BIN_DIR=$PWD/.codesphere-internal/.uv-python-bin - --env-var UV_CACHE_DIR=$PWD/.codesphere-internal/.uv --env-var - UV_PYTHON_CACHE_DIR=$PWD/.codesphere-internal/.uv-python - - name: install frontend environment - command: . ./env && cd frontend && { [ ! -d ".venv" ] && uv venv; uv sync; } - - name: install backend environment - command: . ./env && cd backend && { [ ! -d ".venv" ] && uv venv; uv sync; } -test: - steps: - - name: test frontend - command: . ./env && cd frontend && uv run pytest - - name: test backend - command: ". ./env && cd backend && uv run pytest " - - name: security check frontend - command: '. ./env && cd frontend && uv run bandit -r . -c pyproject.toml - --format=custom --msg-template "{abspath}:{line}: {test_id}[{severity}]: - {msg}" -o bandit-results.txt' - - name: security check backend - command: '. ./env && cd backend && uv run bandit -r . -c pyproject.toml - --format=custom --msg-template "{abspath}:{line}: {test_id}[{severity}]: - {msg}" -o bandit-results.txt' -run: - frontend: - steps: - - name: start frontend application - command: . ./env && cd frontend && uv run streamlit run --server.address 0.0.0.0 - --server.port 3000 main.py - plan: 20 - replicas: 1 - isPublic: true - network: - path: / - stripPath: false - backend: - steps: - - name: start backend application - command: . ./env && cd backend && uv run uvicorn app:app --reload --port 3000 - --host 0.0.0.0 - plan: 20 - replicas: 1 - isPublic: false - api-docs: - steps: - - name: deploy docs - command: . ./env && cd backend && uv run uvicorn doc:app_docs --host 0.0.0.0 - --port 3000 - plan: 20 - replicas: 1 - isPublic: true - network: - path: /api - stripPath: false diff --git a/ci.prod.yml b/ci.prod.yml deleted file mode 100644 index 2f51ae9..0000000 --- a/ci.prod.yml +++ /dev/null @@ -1,55 +0,0 @@ -schemaVersion: v0.2 -prepare: - steps: - - name: install Codesphere cli tool - command: mkdir -p $HOME/.local/bin && wget -qO- - 'https://api.github.com/repos/codesphere-cloud/cs-go/releases/latest' | - grep linux_amd64 | grep browser_download_url | sed s/.*https/https/ | - sed s/\".*$// | xargs wget -O $HOME/.local/bin/cs && chmod +x - $HOME/.local/bin/cs - - name: install uv standalone version - command: nix-env -iA nixpkgs.uv - - name: "set ev vars " - command: . .env && cs set-env -w $WORKSPACE_ID -t $TEAM_ID --env-var - UV_PYTHON_INSTALL_DIR=$PWD/.codesphere-internal/.uv-python-install - --env-var UV_PYTHON_BIN_DIR=$PWD/.codesphere-internal/.uv-python-bin - --env-var UV_CACHE_DIR=$PWD/.codesphere-internal/.uv --env-var - UV_PYTHON_CACHE_DIR=$PWD/.codesphere-internal/.uv-python - - name: install frontend environment - command: cd frontend && { [ ! -d ".venv" ] && uv venv; uv sync --no-dev; } - - name: install backend environment - command: cd backend && { [ ! -d ".venv" ] && uv venv; uv sync --no-dev; } -test: - steps: [] -run: - frontend: - steps: - - name: start frontend application - command: "cd frontend && uv run streamlit run main.py --server.headless true - --server.address 0.0.0.0 --server.port 3000 --browser.gatherUsageStats - false --logger.level info " - plan: 8 - replicas: 1 - isPublic: true - network: - path: / - stripPath: false - backend: - steps: - - name: start backend application - command: cd backend && uv run uvicorn app:app --port 3000 --host 0.0.0.0 - --workers 2 - plan: 8 - replicas: 1 - isPublic: false - api-docs: - steps: - - name: deploy docs - command: cd backend && uv run uvicorn doc:app_docs --host 0.0.0.0 --port 3000 - --workers 2 - plan: 8 - replicas: 1 - isPublic: true - network: - path: /api - stripPath: false diff --git a/ci.yml b/ci.yml index 80289cc..1f5c590 100644 --- a/ci.yml +++ b/ci.yml @@ -1,31 +1,19 @@ schemaVersion: v0.2 prepare: steps: - - name: install Codesphere cli tool - command: mkdir -p $HOME/.local/bin && wget -qO- - 'https://api.github.com/repos/codesphere-cloud/cs-go/releases/latest' | - grep linux_amd64 | grep browser_download_url | sed s/.*https/https/ | - sed s/\".*$// | xargs wget -O $HOME/.local/bin/cs && chmod +x - $HOME/.local/bin/cs - - name: install uv standalone version - command: curl -LsSf https://astral.sh/uv/install.sh | env - UV_INSTALL_DIR="$HOME/app" sh && chmod +x $HOME/app/uv - - command: cp -n .env.sample .env - - name: install frontend environment - command: . ./env && cd frontend && { [ ! -d ".venv" ] && uv venv; uv sync - --no-dev; } - - name: install backend environment - command: . ./env && cd backend && { [ ! -d ".venv" ] && uv venv; uv sync - --no-dev; } + - name: install frontend dependencies + command: cd frontend && virtualenv .venv && .venv/bin/pip install -r requirements.txt + - name: install backend dependencies + command: cd backend && virtualenv .venv && .venv/bin/pip install -r requirements.txt test: steps: [] run: frontend: steps: - name: start frontend application - command: ". ./env && cd frontend && uv run streamlit run main.py + command: "cd frontend && .venv/bin/python -m streamlit run main.py --server.headless true --server.address 0.0.0.0 --server.port 3000 - --browser.gatherUsageStats false --logger.level info " + --browser.gatherUsageStats false --logger.level info" plan: 8 replicas: 1 isPublic: true @@ -35,7 +23,7 @@ run: backend: steps: - name: start backend application - command: . ./env && cd backend && uv run uvicorn app:app --port 3000 --host + command: cd backend && .venv/bin/python -m uvicorn app:app --port 3000 --host 0.0.0.0 --workers 2 plan: 8 replicas: 1 @@ -43,7 +31,7 @@ run: api-docs: steps: - name: deploy docs - command: . ./env && cd backend && uv run uvicorn doc:app_docs --host 0.0.0.0 + command: cd backend && .venv/bin/python -m uvicorn doc:app_docs --host 0.0.0.0 --port 3000 --workers 2 plan: 8 replicas: 1 diff --git a/frontend/requirements.txt b/frontend/requirements.txt new file mode 100644 index 0000000..2f6d724 --- /dev/null +++ b/frontend/requirements.txt @@ -0,0 +1,12 @@ +# Main dependencies +numpy>=2.2.6 +pandas>=2.3.0 +plotly>=6.1.2 +pytest-cov>=6.1.1 +pytest-profiling>=1.8.1 +requests>=2.32.4 +streamlit>=1.45.1 + +# Dev dependencies (for testing and security checks) +bandit>=1.8.3 +pytest>=8.4.0