make 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. cd "$( cd "$( dirname "$0" )"; pwd )"
  3. TARGET_PORT=9690
  4. PROJECT_NAME="acme"
  5. IMAGE_TAG="$PROJECT_NAME/$PROJECT_NAME:latest"
  6. export PIPENV_VERBOSITY=-1 # suppress warning if pipenv is started inside venv
  7. export PYTHONPATH=.
  8. function init {
  9. pip3 install pipenv --upgrade
  10. PIPENV_VENV_IN_PROJECT=1 pipenv install --dev --skip-lock
  11. }
  12. function run {
  13. FLASK_APP=$PROJECT_NAME.api FLASK_DEBUG=1 pipenv run flask run
  14. }
  15. function shell {
  16. init
  17. pipenv shell
  18. }
  19. function test {
  20. pipenv run py.test
  21. }
  22. function lint {
  23. pipenv run flake8 $PROJECT_NAME
  24. }
  25. function coverage {
  26. pipenv run py.test -c .coveragerc --verbose tests
  27. }
  28. function build {
  29. pipenv run python setup.py sdist bdist_wheel
  30. }
  31. function clean {
  32. rm -fr build dist .egg $PROJECT_NAME.egg-info .pytest_cache
  33. }
  34. function dockerbuild {
  35. docker build -t "$IMAGE_TAG" . || exit 1
  36. }
  37. function dockerrun {
  38. dockerbuild
  39. docker run --rm -it -p $TARGET_PORT:80 --name acme-nginx "$IMAGE_TAG"
  40. }
  41. function all {
  42. clean
  43. init
  44. test
  45. lint
  46. coverage
  47. build
  48. clean
  49. }
  50. # -----------------------------------------------------------------------------
  51. coms=$( cat $0 | egrep "^function" | awk '{print $2}' | tr "\n" " " )
  52. if [ -z "$1" ]; then
  53. echo "Select command: $coms"
  54. exit
  55. fi
  56. $1