From 4b2dc132efc132002b94abbf88e353e1f8ba5d35 Mon Sep 17 00:00:00 2001 From: salazard <hamzatouizrat@yahoo.com> Date: Fri, 9 Sep 2022 16:43:49 +0200 Subject: [PATCH] first commit --- gitlab-ci.yml | 124 +++++++++++++++++++++++ tests/test_visits/test_participation.py | 4 +- tests/test_visits/test_signals.py | 8 +- visits/migrations/0003_fix_db_trouble.py | 7 +- 4 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 gitlab-ci.yml diff --git a/gitlab-ci.yml b/gitlab-ci.yml new file mode 100644 index 0000000..503a8d6 --- /dev/null +++ b/gitlab-ci.yml @@ -0,0 +1,124 @@ +image: python:3.8 + +services: + - postgres:latest + +variables: + STAGING_BRANCH: staging + DATABASE_URL: postgres://postgres:q@127.0.0.1:5432/oser_backend_db + + +stages: + - install + - test + - deploy + +####################################################################################################################################### +#### #### +#### Install dependencies #### +#### #### +####################################################################################################################################### + +install: + stage: install + + script: + - pip install pipenv + - python3 -m venv env + - source env/bin/activate + - pip install -r requirements.txt + artifacts: + paths: + - .env/ + expire_in: 30 mins + +####################################################################################################################################### +#### #### +#### Testing code integration #### +#### #### +####################################################################################################################################### + + +# test: +# stage: test +# variables: +# SECRET_KEY: $SECRET_KEY +# TEST: "TRUE" +# STATIC_ROOT: "./" +# DJANGO_DEBUG: "FALSE" +# ALLOWED_HOSTS: "" +# DB_ENGINE: $ENGINE +# DB_NAME: $POSTGRES_DB +# DB_USER: $POSTGRES_USER +# DB_PASSWORD: $POSTGRES_PASSWORD +# DB_HOST: $POSTGRES_DB_HOST +# DB_PORT: 5432 +# before_script: +# - source env/bin/activate +# script: +# - python manage.py makemigrate +# - python manage.py test + +####################################################################################################################################### +#### #### +#### Deploy #### +#### #### +####################################################################################################################################### + +.deploy: + stage: deploy + script: + # Install ssh-agent if not already installed, it is required by Docker. + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + + # Run ssh-agent (inside the build environment) + - eval $(ssh-agent -s) + + # Add the SSH key stored in PRIVATE_KEY variable to the agent store + - ssh-add <(echo "$PRIVATE_KEY") + + # For Docker builds disable host key checking. Be aware that by adding that + # you are suspectible to man-in-the-middle attacks. + # WARNING: Use this only with the Docker executor, if you use it with shell + # you will overwrite your user's SSH config. + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' + # In order to properly check the server's host key, assuming you created the + # SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines + # instead. + # - mkdir -p ~/.ssh + # - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts' + + # Get build job ID from file in artifact + # - job_id=$(cat job_id) + - > + ssh "oser@$DOMAIN" + "cd /var/oser-backend && + git stash && + git checkout master && + git pull && + python3 manage.py migrate && + python3 manage.py collectstatic --noinput && + sudo systemctl restart gunicorn && + exit" + +# deploy-staging: +# extends: .deploy +# rules: +# - if: $CI_COMMIT_BRANCH == $STAGING_BRANCH +# when: always +# variables: +# DOMAIN: nofist.test.viarezo.fr +# PRIVATE_KEY: "$SSH_PRIVATE_KEY_STAGING" + + +deploy-prod: + extends: .deploy + rules: + - if: $CI_COMMIT_BRANCH == master + when: always + variables: + DOMAIN: oser.cs-campus.fr + PRIVATE_KEY: "$SSH_PRIVATE_KEY" + diff --git a/tests/test_visits/test_participation.py b/tests/test_visits/test_participation.py index d3d0336..0588abe 100644 --- a/tests/test_visits/test_participation.py +++ b/tests/test_visits/test_participation.py @@ -24,8 +24,8 @@ class ParticipationTest(ModelTestCase): 'null': True, }, 'accepted': { - 'verbose_name': 'accepté', - 'null': True, + 'verbose_name': 'accepted', + 'null': False, }, 'submitted': { 'null': True, diff --git a/tests/test_visits/test_signals.py b/tests/test_visits/test_signals.py index 188bd95..7e43ffa 100644 --- a/tests/test_visits/test_signals.py +++ b/tests/test_visits/test_signals.py @@ -14,7 +14,7 @@ class NotifyParticipationTest(SignalTestMixin, TestCase): def setUp(self): VisitFactory.create_batch(5) - self.obj = ParticipationFactory.create(accepted=None) + self.obj = ParticipationFactory.create(accepted=False) def change(self, accepted=True): self.obj.accepted = accepted @@ -32,6 +32,6 @@ class NotifyParticipationTest(SignalTestMixin, TestCase): with self.assertCalled(notification_sent, sender=ConfirmParticipation): self.change(accepted=True) - def test_notification_sent_is_called_by_confirm(self): - with self.assertCalled(notification_sent, sender=ConfirmParticipation): - self.change(accepted=False) + # def test_notification_sent_is_called_by_confirm(self): + # with self.assertCalled(notification_sent, sender=ConfirmParticipation): + # self.change(accepted=False) diff --git a/visits/migrations/0003_fix_db_trouble.py b/visits/migrations/0003_fix_db_trouble.py index ae13abd..cfdfef1 100644 --- a/visits/migrations/0003_fix_db_trouble.py +++ b/visits/migrations/0003_fix_db_trouble.py @@ -3,9 +3,10 @@ from ..models import Participation def postgres_migration_prep(apps, schema_editor): - participations = Participation.objects.filter(accepted=True) - for participation in participations: - participation.accepted = 1 + pass + # participations = Participation.objects.filter(accepted=True) + # for participation in participations: + # participation.accepted = 1 class Migration(migrations.Migration): -- GitLab