mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-25 09:05:50 +00:00
added k8s and docker to the craft ready made code.
This commit is contained in:
parent
768e1ed5e9
commit
a3534b7cb8
5 changed files with 178 additions and 0 deletions
10
Dockerfile
Normal file
10
Dockerfile
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
FROM openjdk:17.0.1-slim
|
||||||
|
WORKDIR /opt
|
||||||
|
ENV PORT 8080
|
||||||
|
ENV POSTGRES_USER petclinic
|
||||||
|
ENV POSTGRES_PASSWORD petclinic
|
||||||
|
ENV POSTGRES_URL jdbc:postgresql://postgres/petclinic
|
||||||
|
ENV JAVA_OPTS "-Dspring.profiles.active=postgres -Xmx2g"
|
||||||
|
EXPOSE 8080
|
||||||
|
COPY target/*.jar /opt/app.jar
|
||||||
|
ENTRYPOINT exec java $JAVA_OPTS -jar app.jar
|
42
Makefile
Normal file
42
Makefile
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
.SILENT: validate docker cluster
|
||||||
|
validate:
|
||||||
|
if ! command which envsubst &> /dev/null; then \
|
||||||
|
echo "gettext is not installed. Please install it first."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
if ! command which minikube &> /dev/null; then \
|
||||||
|
echo "minikube is not installed. Please install it first."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
if ! command which kubectl &> /dev/null; then \
|
||||||
|
echo "kubectl is not installed. Please install it first."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
if ! command which docker &> /dev/null; then \
|
||||||
|
echo "docker is not installed. Please install it first."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
if ! command which md5sum &> /dev/null; then \
|
||||||
|
echo "md5sum is not installed. Please install it first."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker: validate
|
||||||
|
if ! command docker info &> /dev/null; then \
|
||||||
|
echo "docker is not running. Please make sure docker is running."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
cluster: docker
|
||||||
|
if ! command minikube status &> /dev/null; then \
|
||||||
|
minikube config set memory 4096; \
|
||||||
|
minikube start --driver=docker; \
|
||||||
|
fi \
|
||||||
|
|
||||||
|
build: cluster
|
||||||
|
minikube image build -t petclinic:latest .
|
||||||
|
|
||||||
|
deploy: build
|
||||||
|
export RANDOM_PART=$$(hostname | md5sum | cut -c1-30) && \
|
||||||
|
envsubst < kube/petclinic.yaml.tmpl > kube/petclinic.yaml
|
||||||
|
minikube kubectl apply -f kube
|
5
config/contrast_security.yaml
Normal file
5
config/contrast_security.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
api:
|
||||||
|
url: https://intuit.contrastsecurity.com/Contrast
|
||||||
|
api_key:
|
||||||
|
service_key:
|
||||||
|
user_name:
|
55
kube/petclinic.yaml.tmpl
Normal file
55
kube/petclinic.yaml.tmpl
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: petclinic
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: petclinic
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: 8080
|
||||||
|
type: LoadBalancer
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: petclinic
|
||||||
|
labels:
|
||||||
|
app: petclinic
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: petclinic
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: petclinic
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: app
|
||||||
|
image: docker.io/library/petclinic:latest
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: "512Mi"
|
||||||
|
cpu: "500m"
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
env:
|
||||||
|
- name: CONTRAST__APPLICATION__NAME
|
||||||
|
value: "petclinic_$RANDOM_PART"
|
||||||
|
- name: CONTRAST__APPLICATION__LANGUAGE
|
||||||
|
value: "java"
|
||||||
|
# - name: CONTRAST__API__USER_API_KEY
|
||||||
|
# value: ""
|
||||||
|
- name: POSTGRES_URL
|
||||||
|
value: "jdbc:postgresql://postgresql/petclinic"
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
value: "petclinic"
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
value: "petclinic"
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
|
66
kube/postgresql.yaml
Normal file
66
kube/postgresql.yaml
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: postgresql-pvc
|
||||||
|
spec:
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 256Mi
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: postgresql
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: postgresql
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 5432
|
||||||
|
targetPort: 5432
|
||||||
|
type: ClusterIP
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: postgresql
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: postgresql
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: postgresql
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: postgres
|
||||||
|
image: postgres:15.2
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: "512Mi"
|
||||||
|
cpu: "500m"
|
||||||
|
env:
|
||||||
|
- name: POSTGRES_DB
|
||||||
|
value: "petclinic"
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
value: "petclinic"
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
value: "petclinic"
|
||||||
|
ports:
|
||||||
|
- containerPort: 5432
|
||||||
|
volumeMounts:
|
||||||
|
- name: storage
|
||||||
|
mountPath: /data/db
|
||||||
|
imagePullPolicy: Always
|
||||||
|
volumes:
|
||||||
|
- name: storage
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: postgresql-pvc
|
Loading…
Reference in a new issue