Commit 650d7147ee480d159b033470dd8f64bde41ae078
1 parent
e3569528
Exists in
master
Adiciona Makefile
Showing
3 changed files
with
92 additions
and
6 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,79 @@ |
| 1 | +PROJECT_NAME = wikilibras | |
| 2 | +VLIBRAS_NAME = vlibras-wiki | |
| 3 | +PYBOSSA_CONF = /etc/apache2/sites-available/pybossa.conf | |
| 4 | +PROJECT_DIR = $(CURDIR) | |
| 5 | +SED_REPLACE_ALL = sed -i "s/$(1)/$(2)/g" "$(3)" | |
| 6 | +SED_REPLACE_ALL_PATH = sed -i "s\#$(1)\#$(2)\#g" "$(3)" | |
| 7 | + | |
| 8 | +ifndef LOCALHOST | |
| 9 | + ifndef NETWORK_INTERFACE | |
| 10 | + NETWORK_INTERFACE := $(shell ip route | awk '{print $$5; exit}') | |
| 11 | + endif | |
| 12 | + ifdef NETWORK_INTERFACE | |
| 13 | + LOCALHOST := $(shell ip addr list ${NETWORK_INTERFACE} | grep "inet " | cut -d ' ' -f6 | cut -d/ -f1) | |
| 14 | + endif | |
| 15 | +endif | |
| 16 | + | |
| 17 | +ifndef LOCALHOST | |
| 18 | + LOCALHOST := localhost | |
| 19 | +endif | |
| 20 | + | |
| 21 | +install: uninstall config | |
| 22 | + @( \ | |
| 23 | + virtualenv ./env/; \ | |
| 24 | + . ./env/bin/activate; \ | |
| 25 | + pip install -U pip; \ | |
| 26 | + pip install -U uwsgi; \ | |
| 27 | + pip install -U ndg-httpsclient; \ | |
| 28 | + pip install -r requirements.txt; \ | |
| 29 | + ) | |
| 30 | +ifdef PYBOSSA_API_KEY | |
| 31 | + @ curl "http://${LOCALHOST}/${PROJECT_NAME}-backend/create_project" && echo "" | |
| 32 | + @ echo "http://${LOCALHOST}/${PROJECT_NAME}-backend/create_project" | |
| 33 | +endif | |
| 34 | + | |
| 35 | +config: | |
| 36 | + @ $(info Using interface: ${NETWORK_INTERFACE}) | |
| 37 | + @ $(info Using local IP: ${LOCALHOST}) | |
| 38 | + @ cp settings_local.py.tmpl settings_local.py | |
| 39 | + @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},settings_local.py) | |
| 40 | + @ $(call SED_REPLACE_ALL,localhost,${LOCALHOST},settings_local.py) | |
| 41 | +ifdef PYBOSSA_API_KEY | |
| 42 | + @ $(call SED_REPLACE_ALL,my-api-key,${PYBOSSA_API_KEY},settings_local.py) | |
| 43 | +endif | |
| 44 | + @ cp ./contrib/${PROJECT_NAME}.wsgi.tmpl ./contrib/${PROJECT_NAME}.wsgi | |
| 45 | + @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},./contrib/${PROJECT_NAME}.wsgi) | |
| 46 | + @ cp ./contrib/apache/${PROJECT_NAME}.conf.tmpl ./contrib/apache/${PROJECT_NAME}.conf | |
| 47 | + @ $(call SED_REPLACE_ALL,ServerName localhost,ServerName ${LOCALHOST},./contrib/apache/${PROJECT_NAME}.conf) | |
| 48 | + @ $(call SED_REPLACE_ALL,user1,$$USER,./contrib/apache/${PROJECT_NAME}.conf) | |
| 49 | + @ $(call SED_REPLACE_ALL,group1,$$USER,./contrib/apache/${PROJECT_NAME}.conf) | |
| 50 | + @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},./contrib/apache/${PROJECT_NAME}.conf) | |
| 51 | + @ sudo cp -u ${PYBOSSA_CONF} /etc/apache2/sites-available/${VLIBRAS_NAME}.conf | |
| 52 | + @ if grep -q "${PROJECT_NAME}" "/etc/apache2/sites-available/${VLIBRAS_NAME}.conf"; \ | |
| 53 | + then \ | |
| 54 | + echo "A previous WSGI daemon definition for '${PROJECT_NAME}' in: /etc/apache2/sites-available/${VLIBRAS_NAME}.conf"; \ | |
| 55 | + else \ | |
| 56 | + sudo sed -i -e "/Header/,/VirtualHost>/d" /etc/apache2/sites-available/${VLIBRAS_NAME}.conf; \ | |
| 57 | + sudo sed -n -e '/WSGIDaemonProcess/,/VirtualHost>/p' ./contrib/apache/${PROJECT_NAME}.conf | \ | |
| 58 | + sudo tee -a /etc/apache2/sites-available/${VLIBRAS_NAME}.conf > /dev/null; \ | |
| 59 | + fi | |
| 60 | + @ sudo a2dissite pybossa.conf | |
| 61 | + @ sudo a2ensite ${VLIBRAS_NAME}.conf | |
| 62 | + @ sudo apachectl configtest | |
| 63 | + @ sudo service apache2 reload | |
| 64 | + | |
| 65 | +clean: | |
| 66 | + @ find . -regextype posix-awk -regex "(.*.log|.*.pyc)" -type f -print -delete | |
| 67 | + | |
| 68 | +uninstall: clean | |
| 69 | + @ rm -rf ./env/ | |
| 70 | + @ rm -f ./settings_local.py | |
| 71 | + @ rm -f ./contrib/${PROJECT_NAME}.wsgi | |
| 72 | + @ sudo rm -f /etc/apache2/sites-available/${VLIBRAS_NAME}.conf | |
| 73 | + @ sudo rm -f /etc/apache2/sites-enabled/${VLIBRAS_NAME}.conf | |
| 74 | + | |
| 75 | +run: | |
| 76 | + @ ( \ | |
| 77 | + . ./env/bin/activate; \ | |
| 78 | + python main.py; \ | |
| 79 | + ) | ... | ... |
contrib/apache/wikilibras.conf.tmpl
| 1 | 1 | <VirtualHost *:80> |
| 2 | - ServerName localhost | |
| 2 | + ServerName localhost | |
| 3 | 3 | |
| 4 | 4 | WSGIDaemonProcess wikilibras user=user1 group=group1 threads=5 |
| 5 | 5 | WSGIScriptAlias /wikilibras-backend <path-to-project>/contrib/wikilibras.wsgi |
| ... | ... | @@ -19,10 +19,10 @@ |
| 19 | 19 | Require all granted |
| 20 | 20 | </Directory> |
| 21 | 21 | |
| 22 | - Header set Access-Control-Allow-Origin "*" | |
| 22 | + Header set Access-Control-Allow-Origin "*" | |
| 23 | 23 | |
| 24 | - ServerAdmin webmaster@localhost | |
| 24 | + ServerAdmin webmaster@localhost | |
| 25 | 25 | |
| 26 | - ErrorLog ${APACHE_LOG_DIR}/error.log | |
| 27 | - CustomLog ${APACHE_LOG_DIR}/access.log combined | |
| 26 | + ErrorLog ${APACHE_LOG_DIR}/error.log | |
| 27 | + CustomLog ${APACHE_LOG_DIR}/access.log combined | |
| 28 | 28 | </VirtualHost> | ... | ... |
wikilibras.py
| ... | ... | @@ -28,7 +28,14 @@ class Wikilibras: |
| 28 | 28 | |
| 29 | 29 | def __update_project_info(self, project): |
| 30 | 30 | template = self.env.get_template('index.html') |
| 31 | - project.info['task_presenter'] = template.render(server=self.config['HOST_STATIC_FILES_ENDPOINT'], server_backend=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], api_host=self.config['API_HOST'], homepage_url=self.config['HOMEPAGE_URL'], upload_sign_host=self.config['UPLOAD_SIGN_HOST']) | |
| 31 | + project.info['task_presenter'] = template.render( | |
| 32 | + server = self.config['HOST_STATIC_FILES_ENDPOINT'], | |
| 33 | + server_backend = self.config['HOST_ENDPOINT'], | |
| 34 | + app_shortname = self.config['PYBOSSA_APP_SHORT_NAME'], | |
| 35 | + api_host = self.config['API_HOST'], | |
| 36 | + homepage_url = self.config['HOMEPAGE_URL'], | |
| 37 | + upload_sign_host = self.config['UPLOAD_SIGN_HOST'] | |
| 38 | + ) | |
| 32 | 39 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" |
| 33 | 40 | project.info['sched'] = "incremental" |
| 34 | 41 | project.info['published'] = True | ... | ... |