diff --git a/.gitignore b/.gitignore index a32ff3df..5d44eda8 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ logs/ /geoip_db/ # dev -./docker-compose.override.yml \ No newline at end of file +./docker-compose.override.yml + +celerybeat-schedule diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..94dda56d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,40 @@ +image: docker:latest + +stages: + - build + - test + - deploy + - clean + + +clean: + stage: clean + script: + - docker-compose -f compose-ci.yml stop + - docker-compose -f compose-ci.yml rm --force gm_app + when: always + + +buid: + stage: build + script: + - docker-compose -f compose-ci.yml build gm_app + when: always + + +test: + stage: test + script: + - docker-compose -f compose-ci.yml run gm_app python manage.py test -v 3 --noinput + when: always + + + +deploy-develop: + stage: deploy + only: + - develop + script: + - fab --roles=develop deploy + environment: + name: Develop \ No newline at end of file diff --git a/apps/account/migrations/0017_merge_20191024_1233.py b/apps/account/migrations/0017_merge_20191024_1233.py new file mode 100644 index 00000000..580f6b2f --- /dev/null +++ b/apps/account/migrations/0017_merge_20191024_1233.py @@ -0,0 +1,14 @@ +# Generated by Django 2.2.4 on 2019-10-24 12:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0016_auto_20191024_0830'), + ('account', '0016_auto_20191024_0833'), + ] + + operations = [ + ] diff --git a/apps/establishment/migrations/0043_establishment_currency.py b/apps/establishment/migrations/0043_establishment_currency.py new file mode 100644 index 00000000..7c324dc4 --- /dev/null +++ b/apps/establishment/migrations/0043_establishment_currency.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.4 on 2019-10-24 13:13 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0022_auto_20191023_1113'), + ('establishment', '0042_establishment_tz'), + ] + + operations = [ + migrations.AddField( + model_name='establishment', + name='currency', + field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='main.Currency', verbose_name='currency'), + ), + ] diff --git a/compose-ci.yml b/compose-ci.yml new file mode 100644 index 00000000..94079822 --- /dev/null +++ b/compose-ci.yml @@ -0,0 +1,79 @@ +version: '2' +services: + db: + build: + context: ./_dockerfiles/db + dockerfile: Dockerfile + hostname: db + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=postgres + ports: + - "5436:5432" + + elasticsearch: + image: elasticsearch:7.3.1 + hostname: elasticsearch + ports: + - 9200:9200 + - 9300:9300 + environment: + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + - discovery.type=single-node + - xpack.security.enabled=false + + # Redis + redis: + image: redis:2.8.23 + ports: + - "6379:6379" + + # Celery + worker: + build: . + command: ./run_celery.sh + environment: + - SETTINGS_CONFIGURATION=local + - DB_NAME=postgres + - DB_USERNAME=postgres + - DB_HOSTNAME=db + - DB_PORT=5432 + - DB_PASSWORD=postgres + links: + - db + - redis + + worker_beat: + build: . + command: ./run_celery_beat.sh + environment: + - SETTINGS_CONFIGURATION=local + - DB_NAME=postgres + - DB_USERNAME=postgres + - DB_HOSTNAME=db + - DB_PORT=5432 + - DB_PASSWORD=postgres + links: + - db + - redis + + # App: G&M + gm_app: + build: . + command: python manage.py runserver 0.0.0.0:8000 + environment: + - SETTINGS_CONFIGURATION=local + - DB_HOSTNAME=db + - DB_PORT=5432 + - DB_NAME=postgres + - DB_USERNAME=postgres + - DB_PASSWORD=postgres + depends_on: + - db + - redis + - worker + - worker_beat + - elasticsearch + ports: + - "8000:8000" diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 00000000..9ad7f871 --- /dev/null +++ b/fabfile.py @@ -0,0 +1,69 @@ +import os # NOQA +from fabric.api import * # NOQA + + + +user = 'gm' + +env.roledefs = { + 'develop': { + 'branch': 'develop', + 'hosts': ['%s@95.213.204.126' % user, ] + } +} + + +env.root = '~/' +env.src = '~/project' + +env.default_branch = 'develop' +env.tmpdir = '~/tmp' + + +def fetch(branch=None): + with cd(env.src): + role = env.roles[0] + run('git pull origin {}'.format(env.roledefs[role]['branch'])) + + +def migrate(): + with cd(env.src): + run('./manage.py migrate') + + +def install_requirements(): + with cd(env.src): + run('pip install -r requirements/base.txt') + + +def touch(): + with cd(env.src): + run('touch ~/%s.touch' % user) + + +def kill_celery(): + """Kill celery workers for $user.""" + with cd(env.src): + run('ps -u %s -o pid,fname | grep celery | (while read a b; do kill -9 $a; done;)' % user) + + +def collectstatic(): + with cd(env.src): + run('./manage.py collectstatic --noinput') + + +def deploy(branch=None): + fetch() + install_requirements() + migrate() + collectstatic() + touch() + kill_celery() + + +def rev(): + """Show head commit.""" + with hide('running', 'stdout'): + with cd(env.src): + commit = run('git rev-parse HEAD') + return local('git show -q %s' % commit) \ No newline at end of file