Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ci, build): Simplify build process and developer workflow for running tests and container builds #125

Merged
merged 17 commits into from
Jan 12, 2022

Conversation

m3mike
Copy link
Contributor

@m3mike m3mike commented Dec 30, 2021

What Changed

PR adds some automation and shortcuts to simplify common developer/user usage scenarios and best practices.

  • Release Process

    • When a release on the github repository is created, the container will automatically be built and pushed to the Github Container Registry with the version set to the tag, in addition to a latest tag.
  • Linting

    • Adds automatic linting locally (via pre-commit), in CI (via super-linter).
    • Adds pre-commit configuration for local running of standard linting tasks (see .pre-commit-config.yaml for details)
    • CI will report on each individual linter separately to easily identify any linting failures (Dockerfiles, shell scripts, python, etc.)
  • Makefile

    • Adds Makefile to simplify/standardize setup, build, and usage of product
    • Targets for the following
      • container build (make build-container, automatically adds OCI label with git hash to built image),
      • venv creation (make venv),
      • test execution (make test, via tox),
      • list all make targets and description (either make help or make with no arguments will print summary of make targets available)
  • Container

    • Adds check for existing user from entrypoint script, to avoid cycle of overwriting user credentials on subsequent container restarts
    • Django superuser is created on first start
    • Uses module syntax of downloading nltk data (no functional changes)
    • Moves nltk download to dockerfile (from entrypoint)
    • Adds industry-standard OCI labels to Dockerfile, includes reference URL for info, repo URL, description, license, and git hash when built via Makefile
    • Adds .dockerignore
    • Updates Dockerfile to use buildkit
    • Use cache volumes in Dockerfile for apt/pip to speed up subsequent builds
  • Docs

    • Adds Add Makefile usage notes to README
    • Update CONTRIBUTING.md doc to reference master branch (develop branch does not exist on repo)
    • Updates docker-compose.yml link in README to point to specific release within git (ties to specific release of file, and makes file location independent from repository structure and branch)
  • Misc

    • add tox to test-requirements file
    • alphabetize python requirements, a sort a day keeps the ocd away
    • pin version of django-rest-framework to allow scanning by safety
    • Update ignore files to add coverage files and other standard git ignores

Limitations

  • Training data still duplicated on subsequent startups. If not desired, may want to consider ome of the following to resolve:
    • Bundle attackdata loading and initial train into Dockerfile, or
    • Modify pipeline command to add an option/alternative command to only load data if not previously loaded
    • Add standalone database to Docker compose configuration, and do training in separate container instance, so training can be controlled/scaled/modified independent of the web application

* add check for existing user from entrypoint script, to avoid cycle of overwriting user credentials on subsequent container restarts
* superuser is created on first start
* use module syntax of downloading nltk data (no functional changes)
* Update Dockerfile to use buildkit
* Add OCI labels to Dockerfile, includes reference URL for info, repo URL, description, license, and git hash when built via Makefile
* Use cache volumes in Dockerfile for apt/pip to speed up subsequent builds
* Add Makefile to simplify common tasks for users
* TODO: Add Makefile usage notes to README
* Add Github super-linter configuration for CI to lint python code, shell scripts, and dockerfiles
* Add pre-commit to run standard lint checks on git commit
…use master

* Update `docker-compose.yml` link in README to point to specific release within git (ties to specific release of file, and makes file location independent from repository structure and branch)
* Update references to `develop` branch in CONTRIBUTING.md guide to reference `master` as `develop` branch does not exist on this repo
* Update branch references in new CI lint check
* loosen python version in Makefile to python3 (project supports 3.7+)
* Move default venv to .venv to simplify makefile
* Explicitly specify python3 in dockerfile during build
* add install-dev as dep of test target
* alphabetize python requirements, a sort a day keeps the ocd away
* pin version of `django-rest-framework` to allow scanning by safety
* add coverage files and other standard git ignores to `.gitignore`
@codecov
Copy link

codecov bot commented Dec 30, 2021

Codecov Report

Merging #125 (298266e) into master (435e501) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #125   +/-   ##
=======================================
  Coverage   94.43%   94.43%           
=======================================
  Files          20       20           
  Lines         827      827           
=======================================
  Hits          781      781           
  Misses         46       46           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 435e501...298266e. Read the comment docs.

@m3mike m3mike marked this pull request as ready for review December 30, 2021 20:25
@m3mike m3mike changed the title WIP refactor(ci, build): Simplify build process and developer workflow for running tests and container builds refactor(ci, build): Simplify build process and developer workflow for running tests and container builds Dec 30, 2021
.github/workflows/linter.yml Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
docker/entrypoint.sh Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Jan 12, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@markeaimark markeaimark self-requested a review January 12, 2022 17:06
@markeaimark markeaimark merged commit d9492ff into master Jan 12, 2022
@markeaimark markeaimark deleted the refactor/docker_tweaks branch January 12, 2022 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants