forked from kobotoolbox/kobocat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
403 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
[uwsgi] | ||
|
||
# directory structure | ||
chdir = /srv/src/kobocat | ||
chdir = $(KOBOCAT_SRC_DIR) | ||
module = onadata.apps.main.wsgi | ||
|
||
# virtualenvs | ||
#home = /home/ubuntu/.virtualenvs/kc | ||
#envdir = /home/ubuntu/env/kc_envdir | ||
logto = $(KOBOCAT_LOGS_DIR)/uwsgi.log | ||
|
||
# process related settings | ||
master = true | ||
processes = 2 | ||
|
||
# | ||
#socket = /home/ubuntu/sockets/kobocat.sock | ||
#chmod-socket = 666 | ||
#vacuum = true | ||
|
||
socket = 0.0.0.0:8000 | ||
#http-socket = 0.0.0.0:8000 | ||
buffer-size = 32768 | ||
harakiri = 120 | ||
|
||
uid = wsgi | ||
gid = wsgi | ||
die-on-term = true | ||
|
||
# uwsgi --socket /home/ubuntu/sockets/kobocat.sock --wsgi-file=/home/ubuntu/src/kobocat/onadata/apps/main/wsgi.py --chmod-socket=666 --chdir=/home/ubuntu/src/kobocat --home=/home/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
if [[ ! -d /srv/pydev_orig ]]; then | ||
echo 'Directory `/srv/pydev_orig` must exist to use PyDev debugger (see `kobo-docker/docker-compose.yml`).' | ||
exit 1 | ||
fi | ||
|
||
cp -a /srv/pydev_orig /srv/pydev | ||
|
||
if [[ -z "${KOBOCAT_PATH_FROM_ECLIPSE_TO_PYTHON_PAIRS}" ]]; then | ||
echo '`KOBOCAT_PATH_FROM_ECLIPSE_TO_PYTHON_PAIRS` must be set to use the PyDev debugger (see `kobo-docker/envfiles/kobocat.txt`).' | ||
exit 1 | ||
fi | ||
|
||
echo 'Setting up PyDev remote debugger path mappings.' | ||
|
||
# Set up the `PATHS_FROM_ECLIPSE_TO_PYTHON` variable from the environment per | ||
# https://github.com/fabioz/PyDev.Debugger/blob/master/pydevd_file_utils.py. | ||
find_string='PATHS_FROM_ECLIPSE_TO_PYTHON = []' | ||
replace_string="\ | ||
import os\n\ | ||
path_map_pair_strings = os.environ['KOBOCAT_PATH_FROM_ECLIPSE_TO_PYTHON_PAIRS'].split('|')\n\ | ||
PATHS_FROM_ECLIPSE_TO_PYTHON = [tuple([pair_element.strip() for pair_element in pair_string.split('->')]) for pair_string in path_map_pair_strings]\n\ | ||
" | ||
escaped_find_sting="$(echo "${find_string}" | sed -e 's/[]\/$*.^|[]/\\&/g')" | ||
escaped_replace_string=$(echo "${replace_string}" | sed -e '/\\n/b; s/[]\/$*.^|[]/\\&/g') | ||
|
||
sed -i "s/${escaped_find_sting}/${escaped_replace_string}/" /srv/pydev/pydevd_file_utils.py | ||
|
||
echo 'Adding `PYTHONPATH` modifications to profile.' | ||
echo 'export PYTHONPATH=${PYTHONPATH}:/srv/pydev' > /etc/profile.d/pydev_debugger.bash.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .docker import deploy | ||
from .legacy import deploy as deploy_legacy | ||
from .legacy import deploy_ref as deploy_ref_legacy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import json | ||
import os | ||
|
||
from fabric.api import cd, env, run, sudo | ||
from fabric.contrib import files | ||
|
||
|
||
SERVICE_NAME = 'kobocat' | ||
GIT_REPO = 'https://github.com/kobotoolbox/{}.git'.format(SERVICE_NAME) | ||
CONTAINER_SRC_DIR_ENV_VAR = '{}_SRC_DIR'.format(SERVICE_NAME.upper()) | ||
UPDATE_STATIC_FILE = '{}/LAST_UPDATE.txt'.format(SERVICE_NAME) | ||
# These must be defined in deployments.json | ||
REQUIRED_SETTINGS = ( | ||
'build_root', # Temporary location for cloning repo; deleted at end | ||
'docker_config_path', # Location must house `docker_compose.yml` | ||
'static_path' # `UPDATE_STATIC_FILE` will be written here | ||
) | ||
|
||
DEPLOYMENTS = {} | ||
IMPORTED_DEPLOYMENTS = {} | ||
deployments_file = os.environ.get('DEPLOYMENTS_JSON', 'deployments.json') | ||
if os.path.exists(deployments_file): | ||
with open(deployments_file, 'r') as f: | ||
IMPORTED_DEPLOYMENTS = json.load(f) | ||
else: | ||
raise Exception("Cannot find {}".format(deployments_file)) | ||
|
||
|
||
def run_no_pty(*args, **kwargs): | ||
# Avoids control characters being returned in the output | ||
kwargs['pty'] = False | ||
return run(*args, **kwargs) | ||
|
||
|
||
def sudo_no_pty(*args, **kwargs): | ||
# Avoids control characters being returned in the output | ||
kwargs['pty'] = False | ||
return sudo(*args, **kwargs) | ||
|
||
|
||
def setup_env(deployment_name): | ||
deployment = DEPLOYMENTS.get(deployment_name, {}) | ||
|
||
if deployment_name in IMPORTED_DEPLOYMENTS: | ||
deployment.update(IMPORTED_DEPLOYMENTS[deployment_name]) | ||
|
||
env.update(deployment) | ||
|
||
for required_setting in REQUIRED_SETTINGS: | ||
if required_setting not in env: | ||
raise Exception('Please define {} in {} and try again'.format( | ||
required_setting, deployments_file)) | ||
|
||
|
||
def deploy(deployment_name, branch='master'): | ||
setup_env(deployment_name) | ||
build_dir = os.path.join(env.build_root, SERVICE_NAME) | ||
with cd(build_dir): | ||
# Start from scratch | ||
run("find -delete") | ||
# Shallow clone the requested branch to a temporary directory | ||
run("git clone --quiet --depth=1 --branch='{}' '{}' .".format( | ||
branch, GIT_REPO)) | ||
# Note which commit is at the tip of the cloned branch | ||
cloned_commit = run_no_pty("git show --no-patch") | ||
with cd(env.docker_config_path): | ||
# Build the image | ||
run("docker-compose build '{}'".format(SERVICE_NAME)) | ||
# Run the new image | ||
run("docker-compose stop '{}'".format(SERVICE_NAME)) | ||
run("docker-compose rm -f '{}'".format(SERVICE_NAME)) | ||
# Don't specify a service name to avoid "Cannot link to a non running | ||
# container" | ||
run("docker-compose up -d") | ||
running_commit = run_no_pty( | ||
"docker exec $(docker-compose ps -q '{service}') bash -c '" | ||
"cd \"${src_dir_var}\" && git show --no-patch'".format( | ||
service=SERVICE_NAME, | ||
src_dir_var=CONTAINER_SRC_DIR_ENV_VAR | ||
) | ||
) | ||
with cd(env.static_path): | ||
# Write the date and running commit to a publicly-accessible file | ||
sudo("(date; echo) > '{}'".format(UPDATE_STATIC_FILE)) | ||
files.append(UPDATE_STATIC_FILE, running_commit, use_sudo=True) | ||
if running_commit != cloned_commit: | ||
raise Exception( | ||
'The running commit does not match the tip of the cloned' | ||
'branch! Make sure docker-compose.yml is set to build from ' | ||
'{}'.format(build_dir) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
onadata/apps/logger/migrations/0002_attachment_filename_length.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import onadata.apps.logger.models.attachment | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('logger', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='attachment', | ||
name='media_file', | ||
field=models.FileField(max_length=380, upload_to=onadata.apps.logger.models.attachment.upload_to), | ||
), | ||
] |
Oops, something went wrong.