Skip to content

Commit 8528c51

Browse files
committed
Merge pull request alphagov#153 from alphagov/emergency_publishing
Emergency publishing
2 parents 886ddd8 + 1eee7e5 commit 8528c51

File tree

3 files changed

+80
-34
lines changed

3 files changed

+80
-34
lines changed

campaigns.py

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,89 @@
66

77
from jinja2 import Template
88

9-
import vm
9+
import app
10+
11+
12+
env['eagerly_disconnect'] = True
13+
14+
15+
APPLICATIONS = ['frontend', 'static']
16+
CAMPAIGN_CLASSES = ['red', 'black', 'green']
17+
1018

1119
def validate_classes(campaign_class):
1220
"""Checks that the campaign class is valid"""
13-
if campaign_class in ['red', 'black', 'green']:
21+
if campaign_class in CAMPAIGN_CLASSES:
1422
return campaign_class
15-
raise Exception, "Invalid class %s, valid values are 'red', 'black', 'green'" % campaign_class
23+
raise Exception, "Invalid class {}, valid values are {}".format(campaign_class, CAMPAIGN_CLASSES)
1624

1725

1826
@runs_once
19-
def homepage_template():
20-
"""Promotes a campaign to the homepage of GOV.UK"""
21-
context = {
22-
'heading': prompt("Heading for campaign:"),
23-
'extra_info': prompt("Extra information for campaign:"),
24-
'more_info': prompt("Link for more information:"),
25-
'campaign_class': prompt("Campaign class:", validate=validate_classes)
27+
def set_context():
28+
env['context'] = {
29+
'heading': prompt("Heading for campaign:", 'heading'),
30+
'extra_info': prompt("Extra information for campaign:", 'extra_info'),
31+
'more_info': prompt("Link for more information:", 'more_info'),
32+
'campaign_class': prompt("Campaign class:", 'campaign_class', validate=validate_classes)
2633
}
2734

28-
template = Template("""<div id="campaign" class="{{ campaign_class }}">
29-
<div class="campaign-inner">
30-
<h1>{{ heading|e }}</h1>
31-
<p>{{ extra_info|e }}</p>
32-
<a href="{{ more_info|e }}">More information</a>
33-
</div>
34-
</div>""")
35-
env['template_contents'] = template.render(context)
3635

37-
print "Template contents:\n%s" % env['template_contents']
36+
def template(app):
37+
if app == 'frontend':
38+
template = Template("""<div id="campaign" class="{{ campaign_class }}">
39+
<div class="campaign-inner">
40+
<h1>{{ heading|e }}</h1>
41+
<p>{{ extra_info|e }}</p>
42+
<a href="{{ more_info|e }}">More information</a>
43+
</div>
44+
</div>""")
45+
elif app == 'static':
46+
template = Template("""<p>{{ heading|e }}<br />
47+
{{ extra_info|e }}</p>
48+
<a href="#" class="right">{{ more_info|e }}</a>""")
49+
50+
env['template_contents'] = template.render(env.context)
51+
3852

3953
@task
4054
@roles('class-frontend')
41-
def deploy_to_homepage():
42-
execute(homepage_template)
55+
def deploy_banner(application):
56+
execute(template, application)
57+
if application == 'frontend':
58+
remote_filename = '/var/apps/frontend/app/views/root/_campaign_notification.html.erb'
59+
elif application == 'static':
60+
remote_filename = "/var/apps/static/app/views/notifications/banner_{}.erb".format(env.campaign_class)
61+
content = env['template_contents']
62+
put(StringIO.StringIO(content), remote_filename, use_sudo=True, mirror_local_mode=True)
63+
sudo('chown deploy:deploy %s' % remote_filename)
64+
execute(app.reload, application)
4365

44-
contents = env['template_contents']
66+
def remove_banner(application):
67+
if application == 'frontend':
68+
remote_filenames = ['/var/apps/frontend/app/views/root/_campaign_notification.html.erb']
69+
elif application == 'static':
70+
remote_filenames = ["/var/apps/static/app/views/notifications/banner_%s.erb" % i for i in CAMPAIGN_CLASSES]
71+
content = ''
72+
for remote_filename in remote_filenames:
73+
put(StringIO.StringIO(content), remote_filename, use_sudo=True, mirror_local_mode=True)
74+
sudo('chown deploy:deploy %s' % remote_filename)
75+
execute(app.reload, application)
4576

46-
remote_filename = '/var/apps/frontend/app/views/root/_campaign_notification.html.erb'
47-
put(StringIO.StringIO(contents), remote_filename, use_sudo=True, mirror_local_mode=True)
48-
sudo('chown deploy:deploy %s' % remote_filename)
49-
execute(vm.reload_unicorn, name='frontend')
5077

5178
@task
5279
@roles('class-frontend')
53-
def remove_from_homepage():
54-
remote_filename = '/var/apps/frontend/app/views/root/_campaign_notification.html.erb'
55-
put(StringIO.StringIO(''), remote_filename, use_sudo=True, mirror_local_mode=True)
56-
sudo('chown deploy:deploy %s' % remote_filename)
57-
execute(vm.reload_unicorn, name='frontend')
80+
def deploy_emergency_banner():
81+
"""Deploy an emergency banner to GOV.UK"""
82+
execute(set_context)
83+
for application in APPLICATIONS:
84+
# Black banners are only placed on the homepage i.e.'frontend'.
85+
# Don't deploy a black banner to the static application.
86+
if not (env.campaign_class == 'black' and application == 'static'):
87+
deploy_banner(application)
88+
89+
@task
90+
@roles('class-frontend')
91+
def remove_emergency_banner():
92+
"""Remove all banners from GOV.UK"""
93+
for application in APPLICATIONS:
94+
remove_banner(application)

cdn.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
@roles('class-cache')
99
def fastly_purge(*args):
1010
"Purge items from Fastly, eg \"/one,/two,/three\". Wildcards not supported."
11-
govuk_fastly = 'http://www-gov-uk.map.fastly.net'
12-
hostnames_to_purge = ['www.gov.uk', 'assets.digital.cabinet-office.gov.uk']
11+
if env.environment == 'production':
12+
hostnames_to_purge = ['www.gov.uk', 'assets.digital.cabinet-office.gov.uk']
13+
elif env.environment == 'staging':
14+
# FIXME - Staging Fastly service should point to non alphagov.co.uk
15+
# domains and amended here after the miration to Carrenza
16+
hostnames_to_purge = ['www.staging.alphagov.co.uk', 'assets.staging.alphagov.co.uk']
17+
1318
for path in args:
1419
if "*" in path:
1520
abort("Sorry, purging paths containing wildcards is not supported "
@@ -18,7 +23,7 @@ def fastly_purge(*args):
1823
% path)
1924
for govuk_path in args:
2025
for hostname in hostnames_to_purge:
21-
run("curl -s -X PURGE -H 'Host: {0}' {1}{2} | grep 'ok'".format(hostname, govuk_fastly, govuk_path.strip()))
26+
run("curl -s -X PURGE {0}{1} | grep 'ok'".format(hostname, govuk_path.strip()))
2227

2328
@task
2429
def purge_all(*args):

fabfile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,25 @@ def help(name):
231231
@task
232232
def production():
233233
"""Select production environment"""
234+
env['environment'] = 'production'
234235
_set_gateway('production.alphagov.co.uk')
235236

236237
@task
237238
def production_migration():
238239
"""Select production migration environment"""
240+
env['environment'] = 'production'
239241
_set_gateway('publishing.service.gov.uk')
240242

241243
@task
242244
def staging():
243245
"""Select staging environment"""
246+
env['environment'] = 'staging'
244247
_set_gateway('staging.publishing.service.gov.uk')
245248

246249
@task
247250
def preview():
248251
"""Select preview environment"""
252+
env['environment'] = 'preview'
249253
_set_gateway('preview.alphagov.co.uk')
250254

251255
@task

0 commit comments

Comments
 (0)