mirror of
https://github.com/fergalmoran/emergelope.git
synced 2025-12-22 09:29:43 +00:00
Added some gcloud stuff
This commit is contained in:
17
.gcloudignore
Normal file
17
.gcloudignore
Normal file
@@ -0,0 +1,17 @@
|
||||
# This file specifies files that are *not* uploaded to Google Cloud Platform
|
||||
# using gcloud. It follows the same syntax as .gitignore, with the addition of
|
||||
# "#!include" directives (which insert the entries of the given .gitignore-style
|
||||
# file at that point).
|
||||
#
|
||||
# For more information, run:
|
||||
# $ gcloud topic gcloudignore
|
||||
#
|
||||
.gcloudignore
|
||||
# If you would like to upload your .git directory, .gitignore file or files
|
||||
# from your .gitignore file, remove the corresponding line
|
||||
# below:
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# Python pycache:
|
||||
__pycache__/
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -89,6 +89,8 @@ venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
.env
|
||||
numbers.json
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
|
||||
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM python:3.6-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN python -m venv venv
|
||||
RUN venv/bin/pip install -r requirements.txt
|
||||
RUN venv/bin/pip install gunicorn
|
||||
|
||||
COPY . /app
|
||||
COPY main.py robots.txt ./
|
||||
RUN chmod +x boot.sh
|
||||
|
||||
ENV FLASK_APP main.py
|
||||
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["./boot.sh"]
|
||||
8
app.yaml
Normal file
8
app.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
runtime: python37
|
||||
api_version: 1
|
||||
|
||||
handlers:
|
||||
- url: /static
|
||||
static_dir: static
|
||||
- url: /.*
|
||||
script: main.app
|
||||
3
boot.sh
Normal file
3
boot.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
source venv/bin/activate
|
||||
exec gunicorn -b :80 --access-logfile - --error-logfile - main:app
|
||||
21
docker-compose.yml
Normal file
21
docker-compose.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
version: '3'
|
||||
services:
|
||||
|
||||
emergelope:
|
||||
container_name: emergelope
|
||||
image: fergalmoran/emergelope
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
VIRTUAL_HOST: ${DOMAINS}
|
||||
LETSENCRYPT_HOST: ${DOMAINS}
|
||||
LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
|
||||
ACCOUNT_SID: ${ACCOUNT_SID}
|
||||
AUTH_TOKEN: ${AUTH_TOKEN}
|
||||
NUMBER_LIST: ${NUMBER_LIST}
|
||||
FROM_NUMBER: ${FROM_NUMBER}
|
||||
CALL_XML: ${CALL_XML}
|
||||
|
||||
networks:
|
||||
default:
|
||||
external:
|
||||
name: ${NETWORK}
|
||||
@@ -1,4 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
from urllib.request import urlopen
|
||||
|
||||
from flask import Flask, jsonify
|
||||
from twilio.rest import Client
|
||||
@@ -11,9 +13,16 @@ to_numbers = os.environ['NUMBER_LIST']
|
||||
from_number = os.environ['FROM_NUMBER']
|
||||
|
||||
|
||||
def parse_json():
|
||||
json_url = urlopen(to_numbers)
|
||||
|
||||
text = json.loads(json_url.read())
|
||||
return text
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def home():
|
||||
return 'EmerGELOPE'
|
||||
return 'Emergelope'
|
||||
|
||||
|
||||
@app.route('/debug')
|
||||
@@ -33,7 +42,8 @@ def debug():
|
||||
def initiate_cluster_fuck():
|
||||
client = Client(account_sid, auth_token)
|
||||
sids = []
|
||||
for number in to_numbers.split(','):
|
||||
numbers = parse_json()
|
||||
for number in numbers:
|
||||
try:
|
||||
sids.append(
|
||||
client.calls.create(
|
||||
@@ -46,7 +56,7 @@ def initiate_cluster_fuck():
|
||||
except:
|
||||
print('Error sending message')
|
||||
|
||||
return sids
|
||||
return "Succeeded"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -1,101 +0,0 @@
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
def to_str(value):
|
||||
return value.decode(sys.getfilesystemencoding())
|
||||
|
||||
|
||||
def execfile(path, global_dict):
|
||||
"""Execute a file"""
|
||||
with open(path, 'r') as f:
|
||||
code = f.read()
|
||||
code = code.replace('\r\n', '\n') + '\n'
|
||||
exec(code, global_dict)
|
||||
else:
|
||||
def to_str(value):
|
||||
return value.encode(sys.getfilesystemencoding())
|
||||
|
||||
|
||||
def log(txt):
|
||||
"""Logs fatal errors to a log file if WSGI_LOG env var is defined"""
|
||||
log_file = os.environ.get('WSGI_LOG')
|
||||
if log_file:
|
||||
f = open(log_file, 'a+')
|
||||
try:
|
||||
f.write('%s: %s' % (datetime.datetime.now(), txt))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
|
||||
def get_wsgi_handler(handler_name):
|
||||
if not handler_name:
|
||||
raise Exception('WSGI_ALT_VIRTUALENV_HANDLER env var must be set')
|
||||
|
||||
if not isinstance(handler_name, str):
|
||||
handler_name = to_str(handler_name)
|
||||
|
||||
module_name, _, callable_name = handler_name.rpartition('.')
|
||||
should_call = callable_name.endswith('()')
|
||||
callable_name = callable_name[:-2] if should_call else callable_name
|
||||
name_list = [(callable_name, should_call)]
|
||||
handler = None
|
||||
last_tb = ''
|
||||
|
||||
while module_name:
|
||||
try:
|
||||
handler = __import__(module_name, fromlist=[name_list[0][0]])
|
||||
last_tb = ''
|
||||
for name, should_call in name_list:
|
||||
handler = getattr(handler, name)
|
||||
if should_call:
|
||||
handler = handler()
|
||||
break
|
||||
except ImportError:
|
||||
module_name, _, callable_name = module_name.rpartition('.')
|
||||
should_call = callable_name.endswith('()')
|
||||
callable_name = callable_name[:-2] if should_call else callable_name
|
||||
name_list.insert(0, (callable_name, should_call))
|
||||
handler = None
|
||||
last_tb = ': ' + traceback.format_exc()
|
||||
|
||||
if handler is None:
|
||||
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
|
||||
|
||||
return handler
|
||||
|
||||
|
||||
activate_this = os.getenv('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS')
|
||||
if not activate_this:
|
||||
raise Exception('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS is not set')
|
||||
|
||||
|
||||
def get_virtualenv_handler():
|
||||
log('Activating virtualenv with %s\n' % activate_this)
|
||||
execfile(activate_this, dict(__file__=activate_this))
|
||||
|
||||
log('Getting handler %s\n' % os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
|
||||
handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
|
||||
log('Got handler: %r\n' % handler)
|
||||
return handler
|
||||
|
||||
|
||||
def get_venv_handler():
|
||||
log('Activating venv with executable at %s\n' % activate_this)
|
||||
import site
|
||||
sys.executable = activate_this
|
||||
old_sys_path, sys.path = sys.path, []
|
||||
|
||||
site.main()
|
||||
|
||||
sys.path.insert(0, '')
|
||||
for item in old_sys_path:
|
||||
if item not in sys.path:
|
||||
sys.path.append(item)
|
||||
|
||||
log('Getting handler %s\n' % os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
|
||||
handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
|
||||
log('Got handler: %r\n' % handler)
|
||||
return handler
|
||||
@@ -1,9 +0,0 @@
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="emergelope.app" />
|
||||
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS"
|
||||
value="D:\home\site\wwwroot\env\Scripts\python.exe" />
|
||||
<add key="pythonpath" value="%SystemDrive%\home\site\wwwroot" />
|
||||
<add key="WSGI_HANDLER" value="virtualenv_proxy.get_venv_handler()" />
|
||||
</appSettings>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user