diff --git a/scripts/lint/Dockerfile b/scripts/lint/Dockerfile index d1457a9..2c349a4 100644 --- a/scripts/lint/Dockerfile +++ b/scripts/lint/Dockerfile @@ -2,11 +2,12 @@ FROM python:3.8-slim-buster # RUN apt-get update && apt-get install -y \ + libpq-dev \ python3-dev \ - build-essential + build-essential \ + git RUN pip install pylint==2.15.9 pylint-django==2.5.3 pylint-plugin-utils==0.7 # Match the version of Django in your project - -RUN pip install backports.zoneinfo -RUN pip install Django==4.0.4 +COPY app/requirements.txt /tmp/requirements.txt +RUN pip install -r /tmp/requirements.txt diff --git a/scripts/lint/lint.sh b/scripts/lint/lint.sh index eba7efa..d30ec73 100755 --- a/scripts/lint/lint.sh +++ b/scripts/lint/lint.sh @@ -1,37 +1,7 @@ #!/bin/bash -# Loads necessaries -set -e # Exit on error -source ./scripts/utils/prettyecho.sh -source ./scripts/lint/setupenv.sh - -VERBOSE=false -KEEP_CONTAINER=false -# Parse options -while getopts "v" opt; do - case $opt in - v) - VERBOSE=true - ;; - d) - KEEP_CONTAINER=true - ;; - \?) - efatal "Lint" "Invalid option: -$OPTARG" >&2 - exit 1 - ;; - esac -done - -# Tearing down -spin_up -if [ $? -ne 0 ]; then - efatal 0 "Lint" "Failed to spin up container." - exit 1 -fi - -# Code -einfo 0 "Lint" "ERRORS ONLY MODE. Ignoring warnings and bad conventions.." +CLNORMAL=$(tput sgr0) +CLCYAN=$(tput setaf 6) component=$1 if [ component = "" ]; then @@ -39,19 +9,12 @@ if [ component = "" ]; then else component="app/$component" fi -einfo 1 "Lint" "Linting $component..." -docker exec -t $TMP_LINTER_NAME pylint --output-format=colorized \ - --django-settings-module=bkdnoj.settings \ - --load-plugins pylint_django \ - --ignore=migrations \ - --errors-only \ - $component +echo "${CLCYAN} * [ LINT ] Linting $component...${CLNORMAL}" -# Tearing down -if [ "$KEEP_CONTAINER" = "false" ]; then - einfo 0 "Lint" "Tearing down temporary container for lint..." - tear_down -else - einfo 0 "Lint" "Keeping container." -fi \ No newline at end of file +pylint --output-format=colorized \ + --django-settings-module=bkdnoj.settings \ + --load-plugins pylint_django \ + --ignore=migrations \ + --errors-only \ + $component \ No newline at end of file diff --git a/scripts/lint/lintdock.sh b/scripts/lint/lintdock.sh new file mode 100755 index 0000000..b8b427f --- /dev/null +++ b/scripts/lint/lintdock.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# Loads necessaries +set -e # Exit on error + +source ./scripts/utils/prettyecho.sh + +source ./scripts/lint/setupenv.sh +# Defines +# # $TMP_LINTER_NAME +# # $TMP_LINTER_IMAGE_NAME +# # $CONTAINER_WORKDIR + + +VERBOSE=false +KEEP_CONTAINER=false +LINT_TARGET="" +# Parse options +while getopts "vdt" opt; do + case $opt in + v) + VERBOSE=true + ;; + d) + KEEP_CONTAINER=true + ;; + t) + LINT_TARGET=$OPTARG + ;; + \?) + efatal "Lint" "Invalid option: -$OPTARG" >&2 + einfo "Usage $0 [-v] [-d]" + echo " -v: To enable verbose" + echo " -d: To keep container after linting" + exit 1 + ;; + esac +done + +einfo 0 "LINT OPTIONS" "VERBOSE=$VERBOSE, KEEP_CONTAINER=$KEEP_CONTAINER, LINT_TARGET='$LINT_TARGET'" + +# Tearing down +spin_up +if [ $? -ne 0 ]; then + efatal 0 "Lint" "Failed to spin up container." + exit 1 +fi + +# Code +einfo 0 "Lint" "ERRORS ONLY MODE. Ignoring warnings and bad conventions.." + +docker exec -t $TMP_LINTER_NAME bash $CONTAINER_WORKDIR/scripts/lint/lint.sh $LINT_TARGET + +# Tearing down +if [ "$KEEP_CONTAINER" = "false" ]; then + einfo 0 "Lint" "Tearing down temporary container for lint..." + tear_down +else + einfo 0 "Lint" "Keeping container." +fi \ No newline at end of file diff --git a/scripts/lint/setupenv.sh b/scripts/lint/setupenv.sh index 79ecd67..72fd257 100755 --- a/scripts/lint/setupenv.sh +++ b/scripts/lint/setupenv.sh @@ -7,39 +7,37 @@ TMP_LINTER_IMAGE_NAME="bkdnoj-lint-image:local" CONTAINER_WORKDIR="/usr/app" spin_up() { - set +e - - echo "" - einfo 1 "Lint | Setup" "Spinning up temporary container for lint..." + einfo 1 "SETUP" "Spinning up temporary container for lint..." # Check if container is already running - einfo 2 "Lint | Setup" "Checking if container is already running..." + einfo 2 "SETUP" "Checking if container is already running..." local msg=$(docker inspect $TMP_LINTER_NAME 2> /dev/null); if [ "$msg" != "[]" ]; then - ewarn 2 "Lint | Setup" "Container is already running. Skipping..." + ewarn 2 "SETUP" "Container is already running. Skipping..." return 0 else - einfo 2 "Lint | Setup" "Container is not running." + einfo 2 "SETUP" "Container is not running." fi # Container is not up, spin up a new one - einfo 2 "Lint | Setup" "Building image..." - docker build -t $TMP_LINTER_IMAGE_NAME -f ./scripts/lint/Dockerfile . + einfo 2 "SETUP" "Building image..." + set -e + docker build --progress=plain -t $TMP_LINTER_IMAGE_NAME -f ./scripts/lint/Dockerfile . + set +e - einfo 2 "Lint | Setup" "Running container in the background..." + einfo 2 "SETUP" "Running container in the background..." docker run -t -d --name $TMP_LINTER_NAME -v ".:$CONTAINER_WORKDIR" -w $CONTAINER_WORKDIR \ $TMP_LINTER_IMAGE_NAME bash - esucceed 2 "Lint | Setup" "Container is ready." + esucceed 2 "SETUP" "Container is ready." echo "" - set -e } tear_down() { echo "" - einfo 1 "Lint" "Tearing down temporary container for lint..." + einfo 1 "SETUP" "Tearing down temporary container for lint..." docker rm -f $TMP_LINTER_NAME echo "" }