make 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. # Initialize virtualenv, i.e., install required packages etc.
  10. pip3 install pipenv --upgrade
  11. PIPENV_VENV_IN_PROJECT=1 pipenv install --dev --skip-lock
  12. }
  13. function shell {
  14. # Initialize virtualenv and open a new shell using it
  15. init
  16. pipenv shell
  17. }
  18. function clean {
  19. # Clean project base by deleting any non-VC files
  20. git clean -fdx
  21. }
  22. function run {
  23. # Run application / flask development server
  24. FLASK_APP=$PROJECT_NAME.api FLASK_DEBUG=1 pipenv run \
  25. flask run --host 0.0.0.0 --port $TARGET_PORT $@
  26. }
  27. function test {
  28. # Run all tests in default virtualenv
  29. pipenv run py.test $@
  30. }
  31. function testall {
  32. # Run all tests against all virtualenvs defined in tox.ini
  33. pipenv run detox $@
  34. }
  35. function coverage {
  36. # Run test coverage checks
  37. pipenv run py.test -c .coveragerc --verbose tests $@
  38. }
  39. function lint {
  40. # Run linter / code formatting checks against source code base
  41. pipenv run flake8 $PROJECT_NAME $@
  42. }
  43. function build {
  44. # Run setup.py-based build process to package application
  45. rm -fr build dist .egg *.egg-info
  46. pipenv run python setup.py bdist_wheel $@
  47. }
  48. function publish {
  49. build
  50. sudo -H pip install 'twine>=1.5.0'
  51. twine upload dist/*
  52. }
  53. function dockerbuild {
  54. # Run full build toolchain and create a docker image for publishing
  55. all
  56. docker build -t "$IMAGE_TAG" . || exit 1
  57. }
  58. function dockerrun {
  59. # Run docker build process and run a new container using the latest image
  60. dockerbuild
  61. docker run --rm -it -p $TARGET_PORT:80 --name acme-nginx "$IMAGE_TAG"
  62. }
  63. function commit {
  64. # Run full build toolchain before executing a git commit
  65. all
  66. git commit
  67. }
  68. function all {
  69. # Full build toolchain
  70. init
  71. test
  72. lint
  73. coverage
  74. build
  75. }
  76. # -----------------------------------------------------------------------------
  77. coms=$( cat $0 | egrep "^function" | awk '{print $2}' | tr "\n" " " )
  78. if [ -z "$1" ]; then
  79. echo "Select command: $coms"
  80. exit 1
  81. fi
  82. if [ -z "$( echo $coms | grep $1 )" ]; then
  83. echo "Unknown command. options: $coms"
  84. exit 1
  85. fi
  86. command=$1
  87. shift
  88. $command $@