2

I would like to create a fallback route (*) with the Swisscom CloudFoundry solution. My current applications are all mapped to a URL like this:

https://sample-application.scapp.io

When an application is deploying or stopped, I'm getting a 404 routing error:

404 Not Found: Requested route ('sample-application.scapp.io') does not exist.

I want to prevent this, by falling back to another application. Using * as the host should define such a fallback route (see docs). Deploying the fallback application with the following manifest, however, throws an error:

Manifest:

---
path: .
instances: 1
buildpack: nodejs_buildpack
applications:
- name: fallback-app-165615
  domain: scapp.io
  host: '*'
  memory: 128M
  disk_quota: 1024M

Error:

Erstellen von Route *.scapp.io... OK

FEHLGESCHLAGEN Serverfehler, Statuscode: 400, Fehlercode: 210003, Nachricht: The host is taken: *


As it is obvious, that *.scapp.io might be unavailable, I still would like to reroute my offline applications to a fallback page. Is this possible by using a second subdomain (e.g. my-application.company-name.scapp.io) or is there any other way to achieve this?

ssc-hrep3
  • 15,024
  • 7
  • 48
  • 87

2 Answers2

5

You cannot achieve this when using a shared domain (shared domains are domains provided by your service provider). But you can easily do this by using your own domain. e.g. my-app1.my-domain.com -> *.my-domain.com or you can use a subdomain on your own domain: e.g. my-app.clolud.my-domain.com -> *.cloud.my-domain.com

If you want to stick to the shared domain you can use route services to achieve the error page. https://docs.cloudfoundry.org/services/route-services.html

Lafunamor
  • 753
  • 3
  • 8
  • Thanks! I solved it by using my own `my-domain.com` and creating a wildcard route `*.my-domain.com` which is routing to a fallback application. The application `myapp.my-domain.com` has an acutal CNAME link to `myapp.scapp.io`. – ssc-hrep3 Nov 22 '17 at 16:06
2

Usually, a green-blue-deployment is done by using a second app instance. You could do it like that:

./cf login -a "https://api.lyra-836.appcloud.swisscom.com" -u "${APC_USERNAME}" -p "${APC_PASSWORD}" -o "${APC_ORGANIZATION}" -s "${APC_SPACE}"

# make sure routes will be ready
./cf create-route "${APC_SPACE}" scapp.io --hostname mytest-app
./cf create-route "${APC_SPACE}" scapp.io --hostname mytest-app-blue-green
sleep 2

# secure working app
./cf rename mytest_app mytest_app_old || true
./cf unmap-route mytest_app_old scapp.io --hostname mytest-app-blue-green || true
sleep 2

# push new app
./cf push mytest_app_new --no-route
./cf map-route mytest_app_new scapp.io --hostname mytest-app-blue-green
./cf map-route mytest_app_new applicationcloud.io --hostname mytest-app-blue-green
sleep 5

# test app
response=$(curl -sIL -w "%{http_code}" -o /dev/null "mytest-app-blue-green.scapp.io")
if [[ "${response}" != "200" ]]; then
    ./cf delete -f mytest_app_new || true
    echo "App did not respond as expected, HTTP [${response}]"
    exit 1
fi

# finish blue-green deployment of app
./cf delete -f mytest_app || true
./cf rename mytest_app_new mytest_app
./cf map-route mytest_app scapp.io --hostname mytest-app
./cf unmap-route mytest_app scapp.io --hostname mytest-app-blue-green || true
./cf delete -f mytest_app_old

# show status
./cf apps
./cf app mytest_app

./cf logout
any
  • 81
  • 2
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Clijsters Nov 22 '17 at 13:44
  • Thank you for your feedback. What is missing from your point of view? The code snippet has comments inside. – any Nov 22 '17 at 13:51
  • Did you carefully read the linked question __and__ its answers? – Clijsters Nov 22 '17 at 14:04
  • Yes, I did. But my answer is obvious, that's why I ask what you are missing - then I can try to improve it :-). – any Nov 22 '17 at 14:32
  • Thanks for your answer! I actually solved it by using a maintenance fallback app instead of rerouting during the deploy process. – ssc-hrep3 Nov 22 '17 at 16:08