java-spring-skills-tracker
java-spring-skills-tracker copied to clipboard
Deploy a containerised Java Spring app on GCP Cloud Run
Java Spring Skills Tracker
A reference project to deploy a containerised Java Spring app onto GCP Cloud Run
An app to track users, their skills and achievements
Run/Build Locally
- In project root directory, run
docker-compose upto start a PostgreSQL database - Then with Maven, select
devprofile and runmaven clean installfollowed bymaven spring-boot:run
Usage
- Once app is running, authenticate user by making a POST request to
http://localhost:8080/loginwith the following body:
{
"username": "admin",
"password": "password"
}
-
From response header, copy the Authorization header bearer token i.e.
Bearer eyJhb...Eyw -
Make a GET request to
http://localhost:8080/api/v1/profileswith an Authorization header with the bearer token as value -
See Postman collection here
Deploy to GCP Cloud Run
- Populate the variables in
terraform.tfvars
region = "europe-west1"
zone = "europe-west1-a"
project = "open-source-apps-001"
# and other variables
- Create GCP resources with Terraform:
cd deploy # change to deploy directory
terraform init # initialises Terraform
terraform apply # deploys GCP stack
terraform destroy # destroys GCP stack
- Build, and push Docker image to Container Registry. Then, deploy to Cloud Run:
docker build -t gcr.io/<your_gcp_project_id>/java-spring-skills-tracker .
docker push gcr.io/<your_gcp_project_id>/java-spring-skills-tracker:latest
gcloud run deploy --image=gcr.io/<your_gcp_project_id>/java-spring-skills-tracker:latest --update-env-vars POSTGRESQL_URL=jdbc:postgresql://<CLOUD-SQL-PUBLIC-IP>:5432/skillsdb,POSTGRESQL_USERNAME=postgres
- Then on Cloud Run console, update
POSTGRESQL_PASSWORD, andJWT_SECRETas secured environment variables. Re-deploy Cloud Run service
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.