Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and deploy static site #142

Merged
merged 21 commits into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ media
.env
.gunicorn
.envrc
dist/
*.pem
.netlify
79 changes: 64 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ manage := $(python) manage.py
fixture_apps := music news shows
fixture := hth/jahhills.json

webapp := jahhills_staging
webapp_dir := webapps/$(webapp)
webapp_branch := $(shell git rev-parse --abbrev-ref HEAD)
webapp_process := $(notdir $(CURDIR))
keyfile := .localhost-key.pem
certfile := .localhost.pem
certnames := localhost $(HOST)

# This and `make deploy` have been replaced by `netlify deploy`
# Leaving them in as an example for rsync-based deployment
webhost := webfaction:webapps/jahhills_static

.PHONY: update
update:
Expand Down Expand Up @@ -45,16 +48,62 @@ css:
docs:
make -C docs html

# Serving via https:// to ensure that Cloudinary URLS are https://
.PHONY: serve-wsgi
serve-wsgi: $(keyfile) $(certfile)
$(bin)/gunicorn \
--env DEBUG=False \
--env DJANGO_SETTINGS_MODULE=hth.settings \
--bind $(HOST):$(PORT) \
--keyfile $(keyfile) \
--certfile $(certfile) \
--workers 4 \
--access-logfile - \
--error-logfile - \
hth.wsgi:application

# See macOS gotcha: https://github.com/FiloSottile/mkcert/issues/199
$(keyfile):
mkcert -key-file $(keyfile) -cert-file $(certfile) $(certnames)

# Inspired by https://apex.sh/blog/post/pre-render-wget/
# Using --max-redirect=0 to catch missing trailing slashes,
# which cause redirects, which yield spurious .html files
wget := wget --no-verbose \
--directory-prefix=dist \
--no-host-directories \
--adjust-extension \
--retry-connrefused \
--max-redirect=0

server := https://$(HOST):$(PORT)

.PHONY: html
html: 404
$(wget) --recursive --level=inf --execute robots=off $(server)

# Ignoring expected 404 error from wget, but letting others through
.PHONY: 404
404:
error=`$(wget) --content-on-error $(server)/404 2>&1` ;\
code=$$? ;\
[[ $$error =~ "ERROR 404" ]] || ( echo $$error; exit $$code )

.PHONY: dist
dist:
set -e ;\
rm -rf dist ;\
make update ;\
make serve-wsgi & make html ;\
kill % ; wait

.PHONY: serve-dist
serve-dist:
$(python) -m http.server \
--directory dist \
--bind $(HOST) $(PORT)

.PHONY: deploy
deploy:
ssh webfaction 'bash -l -c "\
cd $(webapp_dir) && \
git fetch && \
git checkout $(webapp_branch) && \
git merge --ff-only && \
make update restart"'

.PHONY: restart
restart:
supervisorctl restart $(webapp_process)
supervisorctl status $(webapp_process)
rsync --archive --compress --verbose \
dist/ $(webhost)
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Launched on April 12, 2016, in conjunction with the band's fifth album, [A Band

As with the [first iteration](http://github.com/bhrutledge/hallelujahthehills.com), this is an exercise in using the framework. This time around, the focus is on [test-driven development](http://www.obeythetestinggoat.com/), [best practices](http://twoscoopspress.org/collections/everything/products/two-scoops-of-django-1-11), and [YAGNI](http://en.wikipedia.org/wiki/You_aren't_gonna_need_it). Launched as an [MVP](https://en.wikipedia.org/wiki/Minimum_viable_product), with enhancements and bugs across the stack tracked in [GitHub Issues](https://github.com/bhrutledge/jahhills.com/issues).

Deployed as a [static site](https://github.com/bhrutledge/jahhills.com/pull/142) to minimize server requirements.

Anyone is welcome to [explore the data](./data/README.md).

## Getting Started
Expand All @@ -32,10 +34,10 @@ Recompile CSS on Sass changes with `make css`.

## Production infrastructure

- Hosted on [Webfaction](https://www.webfaction.com)
- Managed by [Supervisor](http://supervisord.org/index.html)
- HTTPS via [Let's Encrypt](https://letsencrypt.org)
- Monitoring via [UptimeRobot](https://uptimerobot.com)
- Domain registered on [Namecheap](https://www.namecheap.com/) (w/ DNS and email forwarding)
- Static site hosted on [Netlify](https://www.netlify.com/)
- Media hosted on [Cloudinary](https://cloudinary.com/)
- Monitored with [UptimeRobot](https://uptimerobot.com)

## Deployment

Expand All @@ -45,6 +47,10 @@ Dump local content changes with `make dumpdata`.

Commit and push to GitHub.

Update web host and restart server with `make deploy webapp=jahhills`.
Build the static site with `make dist`.

View the static site with `netlify dev`.

Deploy and publish the static site with `netlify deploy`.

Publish the data with `make -C data publish`.
96 changes: 48 additions & 48 deletions hth/jahhills.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions hth/static/css/socicon.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
@font-face {
font-family: "socicon";
src:url("fonts/socicon.eot");
src:url("fonts/socicon.eot?#iefix") format("embedded-opentype"),
url("fonts/socicon.woff") format("woff"),
src:url("fonts/socicon.woff") format("woff"),
url("fonts/socicon.ttf") format("truetype"),
url("fonts/socicon.svg#socicon") format("svg");
font-weight: normal;
Expand Down
3 changes: 3 additions & 0 deletions hth/static/css/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hth/static/css/styles.css.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions hth/static/sass/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
}
}

&-footer {
margin-top: $large-spacing;
clear: both;
}

@include media($xlarge-screen) {
@include outer-container($xlarge-max-width);

Expand Down
2 changes: 1 addition & 1 deletion hth/templates/home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block main_content %}
<figure class="hero-img large-spacing">
<a href="/music/im-you"><img src="{% cloudinary_url 'hth_iu_photo_banner.jpg' %}" alt="Press photo banner image"></a>
<a href="/music/im-you/"><img src="{% cloudinary_url 'hth_iu_photo_banner.jpg' %}" alt="Press photo banner image"></a>
</figure>

<section id="news" class="container">
Expand Down
4 changes: 4 additions & 0 deletions hth/templates/music/release_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ <h3 class="content-title">
</article>
{% endfor %}
</div>

<div class="container-footer">
<a href="{% url 'song_list' %}">All songs and lyrics</a>
</div>
</article>
{% endblock %}
4 changes: 2 additions & 2 deletions hth/templates/music/song_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ <h1 class="container-header">Songs</h1>

{% for song in song_list %}
<article class="content song">
<h3 class="content-header content-title">
<p class="content-title">
{% if song.has_details %}
<a href="{{ song.get_absolute_url }}">{{ song.title }}</a>
{% else %}
{{ song.title }}
{% endif %}
</h3>
</p>
</article>
{% endfor %}
</article>
Expand Down
8 changes: 0 additions & 8 deletions hth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic.base import RedirectView

from . import views

Expand All @@ -13,13 +12,6 @@
url(r'^news/', include('hth.news.urls')),
url(r'^live/', include('hth.shows.urls')),
url(r'^', include('hth.music.urls')),

url(r'^calendar',
RedirectView.as_view(pattern_name='gig_list', permanent=True)),
url(r'^music/releases/(?P<path>.*)',
RedirectView.as_view(url='/music/%(path)s', permanent=True)),
url(r'^music/songs/(?P<path>.*)',
RedirectView.as_view(url='/songs/%(path)s', permanent=True)),
]

if settings.MEDIA_URL and settings.MEDIA_ROOT:
Expand Down
37 changes: 37 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[build]
publish = "dist/"

[dev]
port = 8000

[[redirects]]
from = "/calendar/*"
to = "/live/"

[[redirects]]
from = "/music/releases/*"
to = "/music/:splat"

[[redirects]]
from = "/music/songs/*"
to = "/songs/:splat"

[[redirects]]
from = "/iu-advance"
to = "/music/im-you/"

[[redirects]]
from = "/abistfo"
to = "/music/a-band-is-something-to-figure-out/"

[[redirects]]
from = "/hyedse"
to = "/music/have-you-ever-done-something-evil/"

[[redirects]]
from = "/nokwhn"
to = "/music/no-one-knows-what-happens-next/"

[[redirects]]
from = "/portrait"
to = "/music/portrait/"
20 changes: 0 additions & 20 deletions start.sh

This file was deleted.