Tuesday, May 6, 2025

Optimizing SpringBoot App Deployment with Layers

Stop copying around your dependencies over and over again!!  Most of the time only the application classes change.  Rebuilds should only push the changes! 

Sample docker file for layered extraction of java libraries.  What this does:

  1. extracts your fat spring-boot-generated JAR into separate layer directories
  2. from here, creates a docker image layer by layer
  3. typically only the application/ docker layer will have changed - the rest will load from docker cache

FROM openjdk:17.0.1-jdk-slim as builder

WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=tools -jar application.jar extract --layers --launcher

FROM openjdk:17.0.1-jdk-slim
WORKDIR application
COPY --from=builder /application/application/dependencies/ ./
COPY --from=builder /application/application/spring-boot-loader/ ./
COPY --from=builder /application/application/snapshot-dependencies/ ./
COPY --from=builder /application/application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]


Saturday, March 15, 2025

Working with JHipster Apps

Work in Progress

These have become super sophisticated.

Here are some tips to get started.



Add support for saving a list of objects:

@PostMapping("/products")

public List<ProductDTO> add(@Valid @RequestBody List<ProductDTO> productDTOs) throws URISyntaxException {

        List<ProductDTO> result = productService.saveAll(productDTOs);

        return result;

}

public List<ProductDTO> saveAll(List<ProductDTO> products) {
    return productRepository.saveAll(products); 

}

 add


Wednesday, February 5, 2025

Kubectl Cheat Sheet

Using kubectl within minikube.

----------------------------------------------------------------------
Minikube Installation
----------------------------------------------------------------------

# from the minikube project page
curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64

sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64

ll /usr/local/bin/minikube 

alias kubectl='minikube kubectl --' 

----------------------------------------------------------------------

Cluster Inspection
----------------------------------------------------------------------

kubectl get pods
kubectl get pods -A
kubectl get services 
kubectl get services hello-minikube

kubectl describe pod headlamp-57fb76fcdb-f6bsl
kubectl describe pod headlamp-57fb76fcdb-f6bsl --namespace headlamp


# Show deployed container digests for all pods

kubectl get pods --namespace=mynmspc -o=jsonpath='{range .items[*]}{"\n"}{.metadata.namespace}{","}{.metadata.name}{","}{range .status.containerStatuses[*]}{.image}{", "}{.imageID}{", "}{end}{end}' | sort

----------------------------------------------------------------------
Minikube Control
----------------------------------------------------------------------

minikube [start|stop|pause|unpause]

----------------------------------------------------------------------

Add-Ons and Services
----------------------------------------------------------------------

minikube addons list
# install
minikube addons enable headlamp

# run addon with name
minikube service headlamp -n headlamp

# run addon
minikube service hello-minikube

# open browser to endpoint, when available from addon
minikube addons open <name>

# run addon when mk starts
minikube start --addons <name1> --addons <name2>

----------------------------------------------------------------------
Deploy Service
----------------------------------------------------------------------

kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0

kubectl expose deployment hello-minikube --type=NodePort --port=8080

kubectl get services hello-minikube

kubectl port-forward service/hello-minikube 7080:8080

----------------------------------------------------------------------
Headlamp Setup
----------------------------------------------------------------------

# install addon - see above
minikube addons enable headlamp

# run addon with name
minikube service headlamp -n headlamp

# get login token
kubectl create token headlamp-admin -n kube-system

# metrics-server helps w/admin
#  uses image registry.k8s.io/metrics-server/metrics-server:v0.7.2
minikube addons enable metrics-server

# See for setup instructions
https://headlamp.dev/docs/latest/installation


~                                                    



Saturday, February 1, 2025

New User Setup Script

Adding a new linux user.

----------------------------------------------------------------------
Basic Ubuntu Script
----------------------------------------------------------------------

#!/bin/bash

USERNAME=$1

# Add user and groups
echo "adding user account: $USERNAME"
sudo adduser $USERNAME
sudo usermod -a -G mygroup $USERNAME

# Add sudo (centOS may require wheel group instead)
sudo usermod -a -G sudo $USERNAME

# Download user PKI cert from remote repo - uses server cert
sudo mkdir -p /home/$USERNAME/.ssh
sudo wget -T 90 -t 1 --certificate=/local/server/cert.pem -0 /home/$USERNAME/.ssh/authorized_keys --no-check-certificate https://keyserver/raw/ds/$USERNAME

# Add starter env
sudo cp -p /home/sample/.bashrc /home/$USERNAME/.

# Set perms
sudo chmod -R 700 /home/$USERNAME
sudo chown -R $USERNAME:$USERNAME /home/$USERNAME