Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #44 from alphagov/paas-redirects-153091168
Browse files Browse the repository at this point in the history
[#153091168] Deploy to www.(system domain)
  • Loading branch information
LeePorte authored Dec 15, 2017
2 parents 0c5b93e + 4d41c0f commit 4a044f5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ node_modules

# PaaS authentication file
Staticfile.auth

modified_manifest.yml
3 changes: 3 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ applications:
instances: 2
env:
APP_ENV: production
DESKPRO_API_KEY:
DESKPRO_TEAM_ID: '1'
DESKPRO_ENDPOINT: 'https://gaap.deskpro.com'
14 changes: 14 additions & 0 deletions release/generate-manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require 'yaml'

cf_system_dns_root = ENV['CF_API'].sub('https://api.', '')

manifest = YAML.load($stdin.read)
manifest['applications'].each { |app|
app['env']['DESKPRO_API_KEY'] = ENV['DESKPRO_API_KEY']
app['routes'] ||= []
app['routes'] << { 'route' => 'www.' + cf_system_dns_root }
app['routes'] << { 'route' => 'paas-product-page.cloudapps.digital' }
}
puts manifest.to_yaml
25 changes: 7 additions & 18 deletions release/push
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@
set -eu

echo "Creating manifest"
DESKPRO_API_KEY=`cat "../secrets/$SECRETS_FILE" | awk '/deskpro_api_key/ { print $2 }'`
ruby -ryaml -e "
env = {
'DESKPRO_API_KEY' => '${DESKPRO_API_KEY}',
'DESKPRO_TEAM_ID' => '1',
'DESKPRO_ENDPOINT' => 'https://gaap.deskpro.com',
}
manifest = YAML.load_file('manifest.yml')
manifest['applications'].each { |app|
app['env'] = {} unless app['env']
app['env'].merge!(env)
}
File.write('manifest.yml', manifest.to_yaml)
"
export DESKPRO_API_KEY=`cat "../secrets/$SECRETS_FILE" | awk '/deskpro_api_key/ { print $2 }'`
export CF_API
release/generate-manifest \
< manifest.yml \
> modified_manifest.yml

echo "Deploy with zero downtime"
cf blue-green-deploy paas-product-page

echo "Delete left over app"
cf delete -f paas-product-page-old
cf zero-downtime-push paas-product-page \
-f modified_manifest.yml
42 changes: 42 additions & 0 deletions spec/release_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'open3'

describe "generating a manifest" do
let(:dir) { Pathname(File.absolute_path(__dir__) + '/..') }
let(:manifest_template) { dir.join('manifest.yml').read }

let(:new_manifest) {
cmd = dir.join('release', 'generate-manifest')

stdout, stderr, status = Open3.capture3(
{
'DESKPRO_API_KEY' => 'my-great-deskpro-api-key',
'CF_API' => 'https://api.foo.bar.baz',
},
cmd.to_s,
stdin_data: manifest_template
)

expect(stderr).to be_empty
YAML.load(stdout)
}

it "adds a www.SYSTEM_DOMAIN route" do
expect(new_manifest['applications'][0]['routes']).
to include({ 'route' => 'www.foo.bar.baz' })
end

it "adds the cloudapps.digital route" do
expect(new_manifest['applications'][0]['routes']).
to include({ 'route' => 'paas-product-page.cloudapps.digital' })
end

it "sets the DeskPro API key" do
expect(new_manifest['applications'][0]['env']['DESKPRO_API_KEY']).
to eq('my-great-deskpro-api-key')
end

it "preserves the existing env" do
expect(new_manifest['applications'][0]['env']['DESKPRO_TEAM_ID']).
to eq('1')
end
end

0 comments on commit 4a044f5

Please sign in to comment.