prepare docker network
docker network create catalog-network
build jar
./gradlew bootJar
build docker image
docker build -t catalog-service .
prepare docker DB container
$ docker run -d --name polar-postgres --net catalog-network -e POSTGRES_USER=user -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=polardb_catalog -p 5432:5432 postgres:14.4
run container catalog-service in catalog-network
$ docker run -d --name catalog-service --net catalog-network -p 9001:9001 -e SPRING_DATASOURCE_URL=jdbc:postgresql://polar-postgres:5432/polardb_catalog -e SPRING_PROFILES_ACTIVE=testdata catalog-service
remove containers:
docker rm -f catalog-service polar-postgres
build and publish image
./gradlew bootBuildImage --imageName=ghcr.io/balanici/catalog-service --publishImage -PregistryUrl=ghcr.io -PregistryUsername=<your_github_username> -PregistryToken=<your_github_token>
Commands used during learn:
minikube start --profile polar
minikube image load catalog-service --profile polar load image from local into minikube
kubectl apply -f k8s/deployment.yml
kubectl apply -f k8s/service.yml
kubectl get svc -l app=catalog-service
kubectl port-forward service/catalog-service 9001:80
# from root dir
tilt up #to up with tilt
tilt down
#when deployment is running with tilt you can see it with octant
octant # will open octant dashboard localhost:7777
# evaluate k8s manifests
kubeval --strict -d k8s
For further reference, please consider the following sections:
- Official Gradle documentation
- Spring Boot Gradle Plugin Reference Guide
- Create an OCI image
- Spring Web
The following guides illustrate how to use some features concretely:
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
These additional references should also help you: