From addab8bf416fffd60edc4b39b7a27078a0c81ee6 Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:09:09 +0000 Subject: [PATCH 01/13] Add new file --- .gitlab-ci.yml | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..216d6d4 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,49 @@ +variables: + SERVER_URL: "go.skillbox.ru" + DOMAIN: "$CI_BUILD_REF_SLUG.$SERVER_URL" + GIT_DEPTH: "1" + +types: + - deploy_branch + - deploy_production + +deploy_branch: + stage: deploy_branch + script: + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + - eval $(ssh-agent -s) + - ssh-add <(echo "$SSH_PRIVATE_KEY") + - mkdir -p ~/.ssh + - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' + - ~/.composer/vendor/bin/envoy run deploy --cleanup --branch="$CI_BUILD_REF_SLUG" + environment: + name: production + url: https://go.skillbox.ru + + variables: + GIT_DEPTH: "1" + +# when: manual + only: + - dev + - autodeploy + +deploy_production: + stage: deploy_production + script: + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + - eval $(ssh-agent -s) + - ssh-add <(echo "$SSH_PRIVATE_KEY") + - mkdir -p ~/.ssh + - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' + - ~/.composer/vendor/bin/envoy run deploy --cleanup --branch="$CI_BUILD_REF_SLUG" + environment: + name: production + url: https://go.skillbox.ru + + variables: + GIT_DEPTH: "1" + + when: manual + only: + - master \ No newline at end of file From b01a716a5ed4ea21d00ce4b65b77f380872eb0ca Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:15:03 +0000 Subject: [PATCH 02/13] Update Envoy.blade.php --- Envoy.blade.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Envoy.blade.php b/Envoy.blade.php index db4f6be..47765dd 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -10,6 +10,7 @@ @story('deploy', ['on' => 'localhost']) clone_repository + run_tests update_symlinks deployment_option_cleanup @endstory @@ -24,6 +25,13 @@ echo '{{ $new_release_dir }}' @endif @endtask +@task('run_tests', ['on' => 'localhost']) +echo '>> Запускаем тесты' +@if ($branch) + cd {{ $new_release_dir }} && source /www/servers/python-server/bin/activate && python manage.py test +@endif +@endtask + @task('update_symlinks', ['on' => 'localhost']) @if ($branch) echo '>> Создаем симлинк на папку текущего релиза' From ecfae665a1f60d41be5ecd639085ee81543386ed Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:17:40 +0000 Subject: [PATCH 03/13] Update Envoy.blade.php --- Envoy.blade.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Envoy.blade.php b/Envoy.blade.php index 47765dd..b2d1ab7 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -3,7 +3,7 @@ @setup $repository = 'ssh://git@g.skillbox.ru:22004/kor_a_m/lms-front.git'; $releases_dir = '/www/site/back_go.skillbox.ru/releases'; - $app_dir = '/www/site/back_go.skillbox.ru/'; + $app_dir = '/www/site/back_go.skillbox.ru'; $release = date('YmdHis'); $new_release_dir = $releases_dir .'/'. $release . '_' . $branch; @endsetup @@ -28,7 +28,8 @@ echo '{{ $new_release_dir }}' @task('run_tests', ['on' => 'localhost']) echo '>> Запускаем тесты' @if ($branch) - cd {{ $new_release_dir }} && source /www/servers/python-server/bin/activate && python manage.py test + cd {{ $new_release_dir }} + source /www/servers/python-server/bin/activate && python ./manage.py test @endif @endtask From c3cf82a4cc01b4e4c88ead20e9c3ab2b4db7ae38 Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:19:33 +0000 Subject: [PATCH 04/13] Update Envoy.blade.php --- Envoy.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Envoy.blade.php b/Envoy.blade.php index b2d1ab7..4678525 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -29,7 +29,7 @@ echo '{{ $new_release_dir }}' echo '>> Запускаем тесты' @if ($branch) cd {{ $new_release_dir }} - source /www/servers/python-server/bin/activate && python ./manage.py test + source /www/servers/python-server/bin/activate && python {{ $new_release_dir }}/manage.py test @endif @endtask From d0136e0179da28c6d6f60488e58e06fc5cf33903 Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:25:42 +0000 Subject: [PATCH 05/13] Update Envoy.blade.php --- Envoy.blade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Envoy.blade.php b/Envoy.blade.php index 4678525..2e0f864 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -10,7 +10,7 @@ @story('deploy', ['on' => 'localhost']) clone_repository - run_tests + update_symlinks deployment_option_cleanup @endstory @@ -35,8 +35,8 @@ echo '>> Запускаем тесты' @task('update_symlinks', ['on' => 'localhost']) @if ($branch) -echo '>> Создаем симлинк на папку текущего релиза' -ln -nfs {{ $new_release_dir }} {{ $app_dir }}/current_{{ $branch }} + echo '>> Создаем симлинк на папку текущего релиза' + ln -nfs {{ $new_release_dir }} {{ $app_dir }}/current_{{ $branch }} @endif @endtask From 84b008a0144d21d38b9ad208d146b67d4be82bd3 Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:26:17 +0000 Subject: [PATCH 06/13] Update Envoy.blade.php --- Envoy.blade.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Envoy.blade.php b/Envoy.blade.php index 2e0f864..e4deb32 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -10,7 +10,6 @@ @story('deploy', ['on' => 'localhost']) clone_repository - update_symlinks deployment_option_cleanup @endstory From c3b3686b16eb1acded5718e2db60247908f4e367 Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:27:04 +0000 Subject: [PATCH 07/13] Update Envoy.blade.php --- Envoy.blade.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Envoy.blade.php b/Envoy.blade.php index e4deb32..41326ec 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -10,6 +10,7 @@ @story('deploy', ['on' => 'localhost']) clone_repository + run_tests update_symlinks deployment_option_cleanup @endstory From 54430a8d63ab7d25581632a19239dd1cc8dd0971 Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:30:49 +0000 Subject: [PATCH 08/13] Update Envoy.blade.php --- Envoy.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Envoy.blade.php b/Envoy.blade.php index 41326ec..5aadadd 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -1,7 +1,7 @@ @servers(['localhost' => 'deployer@192.168.0.13']) @setup - $repository = 'ssh://git@g.skillbox.ru:22004/kor_a_m/lms-front.git'; + $repository = 'ssh://git@g.skillbox.ru:22004/kor_a_m/skill-back.git'; $releases_dir = '/www/site/back_go.skillbox.ru/releases'; $app_dir = '/www/site/back_go.skillbox.ru'; $release = date('YmdHis'); @@ -29,7 +29,7 @@ echo '{{ $new_release_dir }}' echo '>> Запускаем тесты' @if ($branch) cd {{ $new_release_dir }} - source /www/servers/python-server/bin/activate && python {{ $new_release_dir }}/manage.py test + source /www/servers/python-server/bin/activate && python manage.py test @endif @endtask From 2719b5935627ca80414ee5bf3ad6547e29f66979 Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:56:38 +0000 Subject: [PATCH 09/13] Delete wsgi.py --- lms/wsgi.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 lms/wsgi.py diff --git a/lms/wsgi.py b/lms/wsgi.py deleted file mode 100644 index 5e9e9dc..0000000 --- a/lms/wsgi.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") - -application = get_wsgi_application() From 605f8a7c5d5289c319c87e9e5cb46030b0d96fb4 Mon Sep 17 00:00:00 2001 From: Marat Date: Fri, 16 Feb 2018 20:58:48 +0000 Subject: [PATCH 10/13] Update Envoy.blade.php --- Envoy.blade.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Envoy.blade.php b/Envoy.blade.php index 5aadadd..c145808 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -35,6 +35,7 @@ echo '>> Запускаем тесты' @task('update_symlinks', ['on' => 'localhost']) @if ($branch) + ln -nfs {{ $new_release_dir }}/lms/wsgi.py {{ $app_dir }}/configs/{{ $branch }}/wsgi.py echo '>> Создаем симлинк на папку текущего релиза' ln -nfs {{ $new_release_dir }} {{ $app_dir }}/current_{{ $branch }} @endif From 520e44bb5c2dfee840c25922685b091025b66cdf Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 18 Feb 2018 13:02:00 +0300 Subject: [PATCH 11/13] readme update --- README.md | 2 +- access/urls.py | 4 ++-- access/views.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c392986..0b4e369 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ 4 cd skill-back 5 pip install -r requirements.txt 6 python manage.py test - +7 python manage.py runserver diff --git a/access/urls.py b/access/urls.py index 4e8aef6..75ef29a 100644 --- a/access/urls.py +++ b/access/urls.py @@ -4,6 +4,8 @@ import progress.views from access import views urlpatterns = [ + url(r'progress_detail/(?P[0-9A-Fa-f-]+)/$', progress.views.CourseProgressUserView.as_view()), + url(r'progress_dynamic/(?P[0-9A-Fa-f-]+)/$', progress.views.CourseProgressDynamicView.as_view()), url(r'teachers/$', views.TeacherListView.as_view()), url(r'detail/(?P[0-9A-Fa-f-]+)/$', views.DetailUserView.as_view()), url(r'detail/$', views.DetailUserView.as_view()), @@ -16,6 +18,4 @@ urlpatterns = [ url(r'logout/$', views.LogoutView.as_view()), url(r'reset/$', views.ResetPasswordView.as_view()), url(r'progress_detail/upload/(?P[0-9A-Fa-f-]+)/$', progress.views.UploadCourseProgressUserView.as_view()), - url(r'progress_detail/(?P[0-9A-Fa-f-]+)/$', progress.views.CourseProgressUserView.as_view()), - url(r'progress_dynamic/(?P[0-9A-Fa-f-]+)/$', progress.views.CourseProgressDynamicView.as_view()), ] \ No newline at end of file diff --git a/access/views.py b/access/views.py index d3c8a87..cfcaed5 100644 --- a/access/views.py +++ b/access/views.py @@ -158,8 +158,8 @@ class DetailUserView(APIView): return Response(serialized_user, status=200) @staticmethod - def get(request, pk=None): - if pk is None: + def get(request, out_key=None): + if out_key is None: if request.user.is_authenticated(): serialized_user = UserSelfSerializer(request.user).data serialized_user['is_i'] = True @@ -167,10 +167,10 @@ class DetailUserView(APIView): return Response('anonymous', status=200) if request.user.is_authenticated() and request.user.is_superuser \ - or request.user.is_staff or request.user.out_key == pk: + or request.user.is_staff or request.user.out_key == out_key: try: - user = get_user_model().objects.get(out_key=pk) + user = get_user_model().objects.get(out_key=out_key) except get_user_model().DoesNotExist: return Response("User doesn't exist", status=404) From 1de923780ccf98478ea3f7e4da12d31cfdd7d0b3 Mon Sep 17 00:00:00 2001 From: Marat Date: Sun, 18 Feb 2018 10:04:23 +0000 Subject: [PATCH 12/13] Update Envoy.blade.php --- Envoy.blade.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Envoy.blade.php b/Envoy.blade.php index c145808..6c1bb3d 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -38,6 +38,8 @@ echo '>> Запускаем тесты' ln -nfs {{ $new_release_dir }}/lms/wsgi.py {{ $app_dir }}/configs/{{ $branch }}/wsgi.py echo '>> Создаем симлинк на папку текущего релиза' ln -nfs {{ $new_release_dir }} {{ $app_dir }}/current_{{ $branch }} + echo '>> restart Supervisor' + supervisorctl restart dev: @endif @endtask From 9b4c3563ce136b773d67a17765b69217d05b1540 Mon Sep 17 00:00:00 2001 From: Marat Date: Sun, 18 Feb 2018 10:04:41 +0000 Subject: [PATCH 13/13] Update Envoy.blade.php --- Envoy.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Envoy.blade.php b/Envoy.blade.php index 6c1bb3d..b0de027 100644 --- a/Envoy.blade.php +++ b/Envoy.blade.php @@ -39,7 +39,7 @@ echo '>> Запускаем тесты' echo '>> Создаем симлинк на папку текущего релиза' ln -nfs {{ $new_release_dir }} {{ $app_dir }}/current_{{ $branch }} echo '>> restart Supervisor' - supervisorctl restart dev: + supervisorctl restart {{ $branch }}: @endif @endtask