Advertisement
VladNitu

GitLab CI/CD w/ Docker on backend_test

Jun 14th, 2023
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. stages:
  2. - build
  3. - check
  4. - test
  5.  
  6. services:
  7. - docker:dind
  8.  
  9. before_script:
  10. - docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
  11.  
  12. checkstyle-backend:
  13. image: ubuntu:20.04
  14. stage: check
  15. before_script:
  16. - apt -y update
  17. - apt -y install apt-utils
  18. - apt -y install net-tools python3.8 python3-pip mysql-client libmysqlclient-dev
  19. - apt -y upgrade
  20. script:
  21. - pip install --upgrade pip
  22. - pip install virtualenv
  23. - cd backend/
  24. - virtualenv venv # Create virutalenv name `venv`
  25. - source venv/bin/activate # activate virtual environment
  26. - pip install --upgrade pip
  27. - pip install --ignore-installed -r requirements.txt # update requirements
  28. - pycodestyle app/
  29. - deactivate
  30.  
  31.  
  32. backend-build:
  33. image: ubuntu:20.04
  34. stage: build
  35. before_script:
  36. - apt -y update
  37. - apt -y install apt-utils
  38. - apt -y install net-tools python3.8 python3-pip mysql-client libmysqlclient-dev
  39. - apt -y upgrade
  40. script:
  41. - pip install --upgrade pip
  42. - pip install virtualenv
  43. - cd backend/
  44. - virtualenv venv # Create virutalenv name `venv`
  45. - source venv/bin/activate # activate virtual environment
  46. - pip install --upgrade pip
  47. - pip install -r requirements.txt # update requirements
  48. - python3 manage.py makemigrations
  49. - python3 manage.py migrate
  50. - python3 manage.py check
  51. - deactivate
  52.  
  53.  
  54. backend-test:
  55. image: docker:stable
  56. stage: test
  57. before_script:
  58. - apk add --no-cache curl python3 py3-pip
  59. - pip install --ignore-installed virtualenv
  60. script:
  61. - docker pull python:3.8
  62. - docker run -v $(pwd)/backend:/backend -w /backend python:3.8 sh -c '
  63. pip install --upgrade pip &&
  64. pip install virtualenv &&
  65. virtualenv venv &&
  66. . venv/bin/activate &&
  67. pip install --upgrade pip &&
  68. pip install -r requirements.txt &&
  69. curl -i -u guest:guest http://rabbitmq:15672/api/whoami &&
  70. tmux new-session -d -s celery-session "celery -A app worker -l info" &&
  71. sleep 20 &&
  72. celery -A app status &&
  73. coverage run --omit="app/tests/*" manage.py test app/tests &&
  74. coverage html -d ./coverage/ &&
  75. coverage report'
  76. after_script:
  77. - docker stop rabbitmq
  78. only:
  79. refs:
  80. - merge_requests
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement