forked from OWASP-BLT/BLT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
546 additions
and
314 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
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,47 @@ | ||
|
||
name: Pre-commit fix | ||
on: | ||
workflow_dispatch: | ||
permissions: | ||
contents: write | ||
jobs: | ||
run-pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.ref_name }} | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Install pre-commit | ||
run: | | ||
python -m venv venv | ||
. venv/bin/activate | ||
pip install --upgrade pip | ||
pip install pre-commit | ||
- name: Run pre-commit | ||
run: | | ||
. venv/bin/activate | ||
pre-commit run --all-files | ||
continue-on-error: true | ||
- name: Check for changes | ||
id: check_changes | ||
run: | | ||
if [ -n "$(git status --porcelain)" ]; then | ||
echo "Changes detected by pre-commit." | ||
echo "::set-output name=changes_detected::true" | ||
else | ||
echo "No changes made by pre-commit." | ||
echo "::set-output name=changes_detected::false" | ||
fi | ||
- name: Commit and push changes | ||
if: steps.check_changes.outputs.changes_detected == 'true' | ||
run: | | ||
git config user.name "github-actions[bot]" | ||
git config user.email "github-actions[bot]@users.noreply.github.com" | ||
git add . | ||
git commit -m "Apply pre-commit fixes" | ||
git push origin HEAD:${{ github.ref_name }} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 @@ | ||
poetry export -f requirements.txt --output requirements.txt --without-hashes |
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,127 @@ | ||
#!/bin/bash | ||
|
||
# Function to check if Poetry is installed | ||
check_poetry() { | ||
if command -v poetry &> /dev/null | ||
then | ||
echo "Poetry is installed." | ||
return 0 | ||
else | ||
echo "Poetry is not installed. Please install it first: https://python-poetry.org/docs/#installation" | ||
return 1 | ||
fi | ||
} | ||
|
||
# Function to check if Docker is installed | ||
check_docker() { | ||
if command -v docker &> /dev/null | ||
then | ||
echo "Docker is installed." | ||
return 0 | ||
else | ||
echo "Docker is not installed. Please install it first: https://docs.docker.com/get-docker/" | ||
return 1 | ||
fi | ||
} | ||
|
||
# Function to set up the project using Poetry | ||
setup_poetry() { | ||
|
||
check_poetry || exit 1 | ||
|
||
echo "Setting up the project using Poetry..." | ||
|
||
echo "Updating Poetry to the latest version..." | ||
poetry self update | ||
|
||
|
||
echo "Installing project dependencies..." | ||
poetry install | ||
|
||
echo "Running migrations..." | ||
poetry run python manage.py migrate | ||
|
||
|
||
echo "Collecting static files..." | ||
poetry run python manage.py collectstatic --noinput | ||
|
||
echo "Poetry setup complete!" | ||
echo "To start the Django server, use:" | ||
echo "poetry run python manage.py runserver" | ||
} | ||
|
||
# Function to set up the project using Docker | ||
setup_docker() { | ||
echo "Setting up the project using Docker..." | ||
|
||
# Make sure Docker is running | ||
if ! docker info &> /dev/null; then | ||
echo "Docker is not running. Please start Docker first." | ||
exit 1 | ||
fi | ||
|
||
|
||
echo "Building Docker container..." | ||
sudo docker-compose up --build -d | ||
|
||
container_id=$(sudo docker ps -q --filter "name=owasp-blt_app") | ||
|
||
if [ -z "$container_id" ]; then | ||
echo "Container 'owasp-blt_app' not running. Starting container..." | ||
sudo docker-compose up -d | ||
container_id=$(sudo docker ps -q --filter "name=owasp-blt_app") | ||
else | ||
echo "Container 'owasp-blt_app' is already running." | ||
fi | ||
|
||
echo "Running migrations in Docker..." | ||
sudo docker exec -it "$container_id" python manage.py migrate | ||
|
||
echo "Running collectstatic in Docker..." | ||
sudo docker exec -it "$container_id" python manage.py collectstatic --noinput | ||
|
||
mapped_port=$(sudo docker port "$container_id" 8000 | cut -d ':' -f 2) | ||
|
||
if [ -z "$mapped_port" ]; then | ||
mapped_port=8000 | ||
fi | ||
|
||
echo "Docker setup complete!" | ||
echo "To access the Django application, visit the following URL in your browser:" | ||
echo "http://localhost:$mapped_port" | ||
} | ||
|
||
# Main function to choose setup method | ||
main() { | ||
echo "Setting up the Django project..." | ||
|
||
|
||
if check_poetry; then | ||
read -p "Do you want to proceed with Poetry setup? (y/n): " choice | ||
if [[ "$choice" == "y" ]]; then | ||
setup_poetry | ||
else | ||
echo "Skipping Poetry setup." | ||
fi | ||
else | ||
echo "Poetry is not installed, moving to Docker setup." | ||
fi | ||
|
||
if ! check_poetry || [[ "$choice" == "n" ]]; then | ||
if check_docker; then | ||
read -p "Do you want to proceed with Docker setup? (y/n): " choice | ||
if [[ "$choice" == "y" ]]; then | ||
setup_docker | ||
else | ||
echo "Setup aborted. Please install Poetry or Docker and rerun the script." | ||
exit 1 | ||
fi | ||
else | ||
echo "Neither Poetry nor Docker is installed. Setup cannot continue." | ||
exit 1 | ||
fi | ||
fi | ||
} | ||
|
||
main | ||
|
Oops, something went wrong.