Deploying and Configuring Your Custom Service
Previously, you built a Docker image and designed a custom service to use Kyle’s simple Spring Boot application.
Here, you’ll deploy it to Liferay Cloud, add secret environment variables, and see the application in action.
Deploying Your Custom Service to Your UAT Environment
Navigate to your custom service’s directory in your project repository and use the CLI tool to deploy it directly.
lcp deploy
When prompted, enter the number corresponding to your UAT environment.
The service is deployed to your UAT environment, and it appears in the Liferay Cloud console after a delay.
Disabling Basic Authentication in Your UAT Web Server
Disabling basic authentication enables public access to your UAT Liferay instance. Only leave it disabled while you are testing your custom service, and re-enable it afterward.
Disable basic authentication for your UAT environment’s web server so your custom service can send requests to the Liferay instance.
In your project’s repository, open the
webserver/configs/uat/conf.d/liferay.conf
file.Find the line that enforces basic authentication:
auth_basic "Authentication Required";
Comment out this line by adding a
#
character to the beginning of the line.From the
webserver
folder, re-deploy the web server service to your UAT environment:lcp deploy
Choose your UAT environment when prompted.
When your web server service restarts, web traffic to the Liferay instance is enabled and your custom service can send requests to it.
Adding Your Credentials as Secrets
Your service is running, but it can’t authenticate with Liferay yet because it doesn’t have the client ID or client secret to get the OAuth 2 token.
Add the client ID to your new feedback
service as a secret for secure use.
In the Liferay Cloud console, navigate to your UAT environment.
Your new
feedback
service is present in the list of services running.Click Settings from the left-side menu.
In the Secrets tab, click Create New Secret.
Fill in the form to add a new secret for the OAuth 2 client ID:
Name:
oauth2-client-id
Description: Client ID used to authenticate with Liferay.
Value: (Use the client ID you copied from your OAuth 2 profile)
At the bottom of the page, select the
feedback
service and enterOAUTH2_CLIENT_ID
as the environment variable key.Check all of the checkboxes to confirm the impact of the change.
Click Create Secret.
Repeat the process to add the OAuth 2 client secret value.
Click the Back arrow to return to the list of secrets.
Click Create New Secret.
Fill in the form for the OAuth 2 client secret:
Name:
oauth2-client-secret
Description: Client secret used to authenticate with Liferay.
Value: (Use the client secret value you copied from your OAuth 2 profile)
At the bottom of the page, select the
feedback
service and enterOAUTH2_CLIENT_SECRET
as the environment variable key.Check all of the checkboxes to confirm the impact of the change.
Click Create Secret.
Now the OAuth 2 credentials are available to your custom service. Manually restart the service from your Services page to ensure that the service runs with them properly initialized.
Testing the Feedback Counter App
Now your custom service has everything it needs to count feedback submissions. Visit the exposed network endpoint to see how it looks.
From your UAT environment in the Liferay Cloud console, click Network in the left-side menu.
Click the address shown next to your
feedback
service in the list of network endpoints.You set
external: true
in the custom service’sLCP.json
file, so public web traffic is authorized with port 8181.By default, the endpoint listed uses an
https
address. However, your custom service useshttp
. Remove thes
from the URL in your browser’s address bar to access your custom service’s endpoint.Click Fetch Feedback to update the values on the page.
The button triggers a call to the Spring Boot application, which calls Liferay’s object API to get the number of helpful and not helpful responses. The numbers on the page update with the response.
If you submit more responses to the form in your Liferay instance and click the button again, the numbers update to the new totals.
Next, you’ll modify your project’s Jenkins pipeline to add a CI test for your new custom service.