A reference project to deploy a containerised Java Spring app onto GCP Cloud Run
An app to track users, their skills and achievements
- In project root directory, run
docker-compose up
to start a PostgreSQL database - Then with Maven, select
dev
profile and runmaven clean install
followed bymaven spring-boot:run
- Once app is running, authenticate user by making a POST request to
http://localhost:8080/login
with 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/profiles
with an Authorization header with the bearer token as value -
See Postman collection here
- Populate the variables in
terraform.tfvars
project = <GCP-PROJECT-ID>
credentials_filepath = <PATH-TO-GCP-SERVICE-ACCOUNT>
bucket_name = <STATIC-SITE-BUCKET-NAME>
# 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_SECRET
as secured environment variables. Re-deploy Cloud Run service
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.