Skip to content

Commit

Permalink
Finish 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
samirelanduk committed Jun 10, 2018
1 parent 086ee70 commit 3a3b3d8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 28 deletions.
2 changes: 1 addition & 1 deletion core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

VERSION = "0.4.0"

ALLOWED_HOSTS = ["localhost"]
ALLOWED_HOSTS = []

DEBUG = True

Expand Down
9 changes: 9 additions & 0 deletions core/templates/analytics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-51790964-20"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-51790964-20');
</script>
16 changes: 16 additions & 0 deletions core/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for zincbind project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

application = get_wsgi_application()
72 changes: 46 additions & 26 deletions deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,83 @@
sys.exit()
sitename = sys.argv[1]

# Remove contents of remote source directory
subprocess.call(
"ssh %s 'rm -r ~/%s/source/*'" % (sitename, sitename), shell=True
)

# What branch are we on?
branch = subprocess.check_output("git branch", shell=True).decode()
branch = [line for line in branch.split("\n") if "*" in line][0]
branch = branch.split()[1]
if len(sys.argv) < 3 or sys.argv[2] != "nofiles":
# Remove contents of remote source directory
subprocess.call(
"ssh {} 'rm -r ~/{}/source/* >& /dev/null'".format(sitename, sitename), shell=True
)

# What files is git tracking?
tracked_files = subprocess.check_output(
"git ls-tree %s --name-only" % branch, shell=True
).decode()
tracked_files = filter(bool, tracked_files.split("\n"))
# What files are being tracked by git?
tracked_files = subprocess.check_output("git ls-files", shell=True).decode()
tracked_files = list(filter(bool, tracked_files.split("\n")))

# Push source code to remote
for tracked_file in tracked_files:
# Push source code to remote
commands = []
for file_ in tracked_files:
directory = "/".join(file_.split("/")[:-1])
commands.append("mkdir -p ~/{}/source/{}".format(sitename, directory))
commands = set(commands)
subprocess.call(
"scp -r ./%s %s:~/%s/source/" % (tracked_file, sitename, sitename), shell=True
"ssh {} '{}'".format(sitename, ";".join(commands)), shell=True
)
files = []
for file_ in tracked_files:
subprocess.call(
"scp -r ./{} {}:~/{}/source/{}".format(file_, sitename, sitename, file_), shell=True
)

# Turn off Debug
subprocess.call(
"ssh %s 'sed -i s/\"DEBUG = True\"/\"DEBUG = False\"/g ~/%s/source/zincbind/settings.py'" % (sitename, sitename),
"ssh {} 'sed -i s/\"DEBUG = True\"/\"DEBUG = False\"/g ~/{}/source/core/settings.py'".format(sitename, sitename),
shell=True
)

# Add allowed hosts
subprocess.call(
"ssh %s 'sed -i s/\"ALLOWED_HOSTS = \[\]\"/\"ALLOWED_HOSTS = \[£'%s£', £'www.%s£'\]\"/g ~/%s/source/zincbind/settings.py'" % (sitename, sitename, sitename, sitename),
"ssh {} 'sed -i s/\"ALLOWED_HOSTS = \[\]\"/\"ALLOWED_HOSTS = \[£'{}£', £'www.{}£'\]\"/g ~/{}/source/core/settings.py'".format(sitename, sitename, sitename, sitename),
shell=True
)
subprocess.call(
"ssh %s 'sed -i s/£/\\\"/g ~/%s/source/zincbind/settings.py'" % (sitename, sitename),
"ssh {} 'sed -i s/£/\\\"/g ~/{}/source/core/settings.py'".format(sitename, sitename),
shell=True
)

# Upload the secret settings
# Add google analytics
subprocess.call(
"scp -r ./zincbind/secrets.py %s:~/%s/source/zincbind/secrets.py" % (sitename, sitename), shell=True
"ssh {} 'sed -i s/\"<!--analytics-->\"/\"\{{% include \\\"analytics.html\\\" %\}}\"/g ~/{}/source/core/templates/base.html'".format(sitename, sitename),
shell=True
)

'''# Switch to postgres database remotely
if sitename == "pontefract.io":
subprocess.call(
"ssh {} 'sed -i s/\"= local\"/\"= pontefract\"/g ~/{}/source/core/secrets.py'".format(sitename, sitename),
shell=True
)
else:
subprocess.call(
"ssh {} 'sed -i s/\"= local\"/\"= pomfret\"/g ~/{}/source/core/secrets.py'".format(sitename, sitename),
shell=True
)'''

# Install pip packages
subprocess.call(
"ssh %s '~/%s/env/bin/pip install -r ~/%s/source/requirements.txt'" % (sitename, sitename, sitename),
"ssh {} '~/{}/env/bin/pip install -r ~/{}/source/requirements.txt -r ~/{}/source/requirements-live.txt'".format(sitename, sitename, sitename, sitename),
shell=True
)

# Apply migrations
subprocess.call(
"ssh %s '~/%s/env/bin/python ~/%s/source/manage.py migrate'" % (sitename, sitename, sitename),
"ssh {} '~/{}/env/bin/python ~/{}/source/manage.py migrate'".format(sitename, sitename, sitename),
shell=True
)

# Deploy static files
subprocess.call(
"ssh %s 'cd ~/%s/source && ../env/bin/python manage.py collectstatic --noinput'" % (sitename, sitename),
"ssh {} 'cd ~/{}/source && ../env/bin/python manage.py compilescss'".format(sitename, sitename),
shell=True
)
)
subprocess.call(
"ssh {} 'cd ~/{}/source && ../env/bin/python manage.py collectstatic --noinput'".format(sitename, sitename),
shell=True
)
1 change: 0 additions & 1 deletion requirements-live.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
psycopg2
gunicorn

0 comments on commit 3a3b3d8

Please sign in to comment.