Exercise 3 - Change code, build, save and deploy the Web-App
Step 1: Open the main.js
file
main.js
fileecho $keycloakurl
echo $authorsurl
echo
cd $ROOT_FOLDER/web-app-cloud/src
nano main.js
Step 2: Change following source code
cd $ROOT_FOLDER/web-app-cloud/src
nano main.js
Replace the [keycloakurl]
with the value, you got before for in Step 1 and save the file. The authors url is only available after the deploment of the Authors service.
let initOptions = {
url: '[keycloakurl]/auth', realm: 'cloudnativestarter', clientId: 'frontend', onLoad: 'login-required'
}
let urls = {
api: 'http://[authorsurl]/api/v1/'
}
store.commit("setAPI", urls);
Step 3: Build and save the "Web-App" container image in the IBM Cloud Container Registry
Now we want to build and save the container image "Web-APP" in the IBM Cloud Container Registry.
Ensure you logon on to IBM Cloud.
REMEMBER: You should know this from the prerequisites.
You can follow the steps in the Access tab, by starting from After your cluster provision .. and inserting the commands into your terminal session.
Logon to the IBM Cloud Container Registry (Ensure you are in the right folders)
Web-APP
cd $ROOT_FOLDER/web-app-cloud ibmcloud cr login
List you namespaces inside the IBM Cloud Container Registry
ibmcloud cr namespaces
Example output:
$ Listing namespaces for account 'Thomas Suedbroecker's Account' in registry 'us.icr.io'... $ $ Namespace $ cloud-native-suedbro
Now upload the code and build the container image inside IBM Cloud Container Registry. We use the information from step 2, where we got the list of namespaces.
Web-APP
$ ibmcloud cr build -f Dockerfile --tag $REGISTRY/$REGISTRY_NAMESPACE/web-app:1 .
Step 4: List the container images to verify the upload.
ibmcloud cr images
Step 5: Apply the deployment of the Web-App
Ensure you are in the
$ROOT_FOLDER/web-app-cloud/deployment
cd $ROOT_FOLDER/web-app-cloud/deployment nano kubernetes.yaml
Open the
../web-app-cloud/deployment/kubernetes.yaml
file with a editor and replace the value for the container image location with the path we got from the IBM Container Registry and just replace theweb-app:1
text, and add following statementimagePullPolicy: Always
and save the file.
Before:
image: web-app:1
Example after the change:
spec:
containers:
- name: web-app
image: de.icr.io/cloud-native-tsuedbro/web-app:1
ports:
- containerPort: 80
restartPolicy: Always
Now we apply the yaml to create the web-app Pod.
kubectl apply -f kubernetes.yaml
Insert this command and verify the output.
kubectl get pods
Example output:
$ NAME READY STATUS RESTARTS AGE $ authors-7b6dd98db-wl9wc 1/1 Running 0 6m9s $ web-app-7b6dd98db-wl9wc 1/1 Running 0 6m9s
Cluster/Workernode IP
echo $workernodeip
Web-APP
NodePort
export webappnodeport=$(kubectl get svc web-app --ignore-not-found --output 'jsonpath={.spec.ports[*].nodePort}')
Open the Web-APP in a browser
export redirecturl=http://${workernodeip}:${webappnodeport} echo $redirecturl
Step 6: Configure the redirect URL in Keycloak
Get the Keycloak URL in your terminal session:
echo $keycloakurl
Open Keycloak your browser
Login admin/admin and open the Cloud Native Starter realm
Select Clients
Open the
authors-client-cloud-native-starter
clientGet the
redirecturl
in your terminal session and copy the URLecho $redirecturl
Insert the
[redirecturl]
Root URL:
[redirecturl]
Valid Redirect URIs:
[redirecturl]
/*[redirecturl]
//
Configure the
Web Origins
Web Origins:
'*'
*
Step 7: Open the Web-App again
Step 8: Logon as user author-cloud-native-starter
and password 1234
.
author-cloud-native-starter
and password 1234
.Last updated
Was this helpful?