For people who are making mobile applications, managing the various server components and technologies is a challenge.
This post will demonstrate how to use OpenShift Origin to host an instance of Aerogear Unified Push Server and then start development on an Android application on your development machine.
AeroGear Unified Push Server is a project that provides a single service to manage multiple push networks for your mobile applications. OpenShift Origin is a container management platform build on Kubernetes and Docker technologies. Both are Open Source and sponsored by RedHat.
Getting and Starting OpenShift Origin
Before you can use Origin you need to have Docker installed on your computer as well as configure its to use OpenShift’s internal Docker registry. You can do this by passing the following parameter to Docker when the service starts
--insecure-registry 172.30.0.0/16. System specific details can be found here.
You will also need the tool
oc. It can be found on the Origin’s GitHub releases page.
Launching OpenShift Origin
oc cluster up.
Yup that is all you need. Now you can browse to https://127.0.0.1:8443/console and login as developer:developer.
Deploying AeroGear UPS
We will use the Unified Push Server image found on Docker Hub. Reviewing that page we see that it needs two MySQL instances named “unifiedpush” and “keycloak”. We can create those in Origin, deploy UnifiedPush, and then add a route for our Android emulator.
Deploying MySQL containers
oc new-app mysql MYSQL_USER=unifiedpush MYSQL_PASSWORD=unifiedpush MYSQL_DATABASE=keycloak --name=keycloak
oc new-app mysql MYSQL_USER=unifiedpush MYSQL_PASSWORD=unifiedpush MYSQL_DATABASE=unifiedpush --name=unifiedpush
You can watch both systems come online in your console, or view their status with
Deploying AeroGear UnifiedPush
oc new-app aerogear/unifiedpush-wildfly \ UNIFIEDPUSH_PORT_3306_TCP_ADDR=unifiedpush \ UNIFIEDPUSH_PORT_3306_TCP_PORT=3306 \ UNIFIEDPUSH_ENV_MYSQL_DATABASE=unifiedpush \ KEYCLOAK_PORT_3306_TCP_ADDR=keycloak \ KEYCLOAK_PORT_3306_TCP_PORT=3306 \ KEYCLOAK_ENV_MYSQL_DATABASE=keycloak \ UNIFIEDPUSH_ENV_MYSQL_USER=unifiedpush \ UNIFIEDPUSH_ENV_MYSQL_PASSWORD=unifiedpush \ KEYCLOAK_ENV_MYSQL_USER=unifiedpush \ KEYCLOAK_ENV_MYSQL_PASSWORD=unifiedpush \ --name=unifiedpush-wildfly
This command will deploy UnifiedPush and connect it to your MySQL containers. If you are work with Docker then the environment variables we use should be familiar; that is because this is a plain Docker container.
Adding Routes to the UnifiedPush application
By default OpenShift applications are not routable. This means that we can not point a web browser to UnifiedPush to configure it nor can an Android device connect to it to receive push messages. We will add two routes to enable both of these behaviors.
oc expose service unifiedpush-wildfly --hostname=ups.127.0.0.1.nip.io --port=8080-tcp --name=ups-local-unsecured oc expose service unifiedpush-wildfly --hostname=ups.10.0.2.2.nip.io --port=8080-tcp --name=ups-android-unsecured
The first route exposes UPS on the local machine’s IP address 127.0.0.1, and the second exposes on 10.0.2.2 which is the hardcoded IP address for the host of an Android emulator. These hostnames use nip.io to fake the DNS lookup.
Fixing Keycloak Linking
UPS uses an embedded Keycloak server to handle its authentication. Right now there is an issue when the UPS pod starts up it can’t route to Keycloak using the public route. To work around this you will need to use the OpenShift web console to navigate to the unifiedpush-wildfly pod and execute “wget http://localhost:8080/ag-push/index.html” in the terminal after the application loads.
Configuring you Android Push Application
You can follow the HelloPush tutorial here. The only change is you will use “http://ups.10.0.2.2.nip.io/ag-psuh” as your push URL.