Add tasks to install docker

parent c6d75f79
......@@ -42,3 +42,6 @@ security/*
collect/media/*
log/
backup/
# Other ignores
temp_cron
\ No newline at end of file
......@@ -13,7 +13,9 @@ services:
- web:web
web:
build: .
build:
context: .
dockerfile: docker/Dockerfile.production
expose:
- "8000"
links:
......@@ -22,7 +24,7 @@ services:
env_file: ./docker/env
volumes:
- ./src/:/app/src/
command: bash -c "python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py loaddata src/smi_unb/fixtures/initial_data.json && gunicorn smi_unb.wsgi -b 0.0.0.0:8000"
command: bash -c "inv run_web_container"
postgres:
restart: always
......
......@@ -4,41 +4,49 @@ RUN apt-get update &&\
apt-get install --no-install-recommends --no-install-suggests -y \
\
# Extra deps
cron \
python3-pip
# Base deps
RUN pip3 install \
requests[security] \
django==1.9.8 \
psycopg2==2.6.2 \
gunicorn \
redis==2.10.3 \
RUN pip3 install \
requests[security] \
django==1.9.8 \
psycopg2==2.6.2 \
gunicorn \
redis==2.10.3 \
django-redis==4.8.0 \
numpy \
pandas \
Sphinx \
django-polymorphic \
manuel \
mpld3 \
six \
unipath \
django_cron \
matplotlib \
invoke \
numpy \
pandas \
Sphinx \
django-polymorphic \
manuel \
mpld3 \
six \
unipath \
django_cron \
matplotlib \
djangorestframework
RUN mkdir -p /app
WORKDIR /app
COPY [ \
"setup.py", \
"setup.py", \
"requirements.txt", \
"boilerplate.ini", \
"manage.py", \
"tasks.py", \
"/app/" \
"boilerplate.ini", \
"manage.py", \
"tasks.py", \
"temp_cron", \
"/app/" \
]
COPY src/ /app/src/
ENV PYTHONPATH=src \
SMI_UNB_PRODUCTION=true
\ No newline at end of file
SMI_UNB_PRODUCTION=true
# Setting crontab
RUN crontab temp_cron && rm temp_cron
RUN crontab -l
RUN crontab -r
\ No newline at end of file
......@@ -21,7 +21,7 @@ import sys
sys.path.insert(0, os.path.abspath('../src'))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SMI_UnB.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "smi_unb.settings")
import django
django.setup()
......@@ -58,7 +58,7 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'SMI_UnB'
project = u'smi_unb'
copyright = u'2016, Brenddon Gontijo'
author = u'Brenddon Gontijo'
......
from django_cron import CronJobBase, Schedule
from .synchronization import EnergyMeasurementSynchronizer
class MeasurementsSyncCronJob(CronJobBase):
RUN_EVERY_MINS = 59
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'smi_unb.api.cronjob.MeasurementsSyncCronJob'
def do(self):
e_synchronizer = EnergyMeasurementSynchronizer()
e_synchronizer.perform_all_measurements_sync()
......@@ -120,7 +120,7 @@ class EnergyMeasurementSynchronizer(object):
def __init__(self):
self.buildings = Building.objects.filter(active=True)
def sync_measurements(self):
def perform_all_measurements_sync(self):
query_params = '?last=true'
for building in self.buildings:
......
......@@ -6,7 +6,7 @@ from .utils import DataCollector
class DataCollectCronJob(CronJobBase):
RUN_EVERY_MINS = 0
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'data_reader.cronjob.DataCollectCronJob'
code = 'smi_unb.data_reader.cronjob.DataCollectCronJob'
def do(self):
data_collector = DataCollector()
......
......@@ -100,7 +100,8 @@ MIDDLEWARE_CLASSES = [
]
CRON_CLASSES = [
"data_reader.cronjob.DataCollectCronJob",
"smi_unb.data_reader.cronjob.DataCollectCronJob",
"smi_unb.api.cronjob.MeasurementsSyncCronJob",
]
ROOT_URLCONF = 'smi_unb.urls'
......
import sys
import os
from invoke import run, task
from python_boilerplate.tasks import *
from python_boilerplate.tasks.django import *
@task
def run_web_container(ctx):
run('python3 manage.py makemigrations && \
python3 manage.py migrate && \
python3 manage.py loaddata src/smi_unb/fixtures/initial_data.json && \
gunicorn smi_unb.wsgi -b 0.0.0.0:8000')
@task
def install_master_docker(ctx):
cron_temp_file = 'temp_cron'
if os.path.exists(cron_temp_file):
run('rm %s' % cron_temp_file)
# Setting measurements cron synchronization time to run every 1 hour (0 * * * *)
cron_execution = '0 * * * * cd /app/ && python3 manage.py runcrons ' + \
'smi_unb.api.cronjob.MeasurementsSyncCronJob'
# Creating cron file to be used on docker/Dockerfile.production
run('echo "%s" >> temp_cron' % cron_execution)
# Building docker containers
run('docker-compose build')
# Initializing containers
run('docker-compose up -d')
# Creating a user
run ('docker exec -it smeunb_web_1 python3 manage.py createsuperuser')
# Removing cron_temp_file
run('rm %s' % cron_temp_file)
@task
def configure(ctx):
"""
Instructions for preparing package for development.
"""
def install_slave_docker(ctx):
pass
run("%s -m pip install .[dev] -r requirements.txt" % sys.executable)
@task
def install(ctx):
run('pip3 install -e .')
@task
def collectstatic(ctx):
run('python3 manage.py collectstatic')
@task
def test(ctx):
run('python3 manage.py test smi_unb')
@task
def coverage(ctx, report=False):
run('coverage run manage.py test smi_unb')
if report:
run('coverage report')
else:
run('coverage html')
run('google-chrome htmlcov/index.html')
@task
def start_docker(ctx):
run('docker-compose start')
@task
def stop_docker(ctx):
run('docker-compose stop')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment