This purpose of this project is to act as a guide for Spring applications deployed to Cloud Foundry environments.
- Clone project and navigate to root directory where the project was cloned.
mkdir /Users/$(whoami)/Dev/
cd /Users/$(whoami)/Dev/
git clone https://github.com/rpdedeus/pcfspring
cd pcfspring
- Ensure Postgres database is running.
psql
# CREATE DATABABASE pcfspring
- Build and test.
./mvnw clean package
- Run project locally.
export DB_URL=jdbc:postgresql://localhost:5432/pcfspring
export DB_UN=postgres
export DB_PW=password
./mvnw spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=cloud"
- Create cloud foundry account
- Download cf cli and follow instructions on the page.
- Create database service.
- Connect to DB from local client (optional).
View available services
cf marketplace
Create an instance of the ElephantSQL's service using the free tier called "turtle":
cf create-service elephantsql turtle rd-pcfspring-db
View service details using cf cli. Copy the dashboard URL to your clipboard.
cf service rd-pcfspring-db
Make sure you are logged into the pivotal web console and go to the dashboard URL acquired from the previous step. From the ElephantSQL dashboard, acquire, connection URL, username and password.
Use the credentials from the "Create a service" section, to create a database connection using your favorite client.
- Login to cf cli.
cf login -a https://api.run.pivotal.io
-
Open the manifest file. Change the value of the "name" key to something of you liking. This value has to be unique.
-
From the project's root directory, issue the command to push the applications.
cf push --no-start
- Set environment variables.
Set environment variables using the following format:
cf set-env APP_NAME ENV_VAR_NAME ENV_VAR_VALUE
cf set-env rd-pcfspring DB_UN <actual_user_name>
cf set-env rd-pcfspring DB_PW <actual_password>
cf set-env rd-pcfspring DB_URL <actual_url>
- Start application.
cf start rd-pcfspring
Use actuator endpoint to validate that the application responds to requests.
https://rd-pcfspring.cfapps.io/actuator/health
Replace rd-pcfspring with you own app name.
cf run-task rd-pcfspring "ls -la"
- Tail logs
cf logs rd-pcfspring
- Validate app status
View all apps in the current org/space
cf apps
or
View specific app in the current org/space
cf app rd-pcfspring
- ssh into container
cf ssh rd-pcfspring