fix(aula-13): reescrever benchmarks eStargz vs GZIP
Benchmarks antigos eram falhos: node hardcoded, imagens diferentes, sem verificação de snapshotter, sem controle de cache, 1 iteração. Novos scripts: - prepare-images.sh: constrói mesma imagem em gzip e estargz - benchmark.sh: múltiplas iterações, detecção de cache hits, verificação de snapshotter, 3 tipos de imagem (nginx/node/postgres) Requer worker node sem cache (node fresh via cluster autoscaler).
This commit is contained in:
127
aula-13/benchmarks/prepare-images.sh
Executable file
127
aula-13/benchmarks/prepare-images.sh
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# Prepara imagens de benchmark em formato GZIP e eStargz
|
||||
# =============================================================================
|
||||
#
|
||||
# Constrói a MESMA imagem em dois formatos de compressão e envia ao registry.
|
||||
# Isso garante que a única variável no benchmark é o formato de compressão.
|
||||
#
|
||||
# Pré-requisitos:
|
||||
# - docker com buildx
|
||||
# - Acesso ao registry (docker login)
|
||||
# - Organização "bench" criada no Gitea
|
||||
#
|
||||
# Uso:
|
||||
# export REGISTRY=gitea.kube.quest
|
||||
# ./prepare-images.sh
|
||||
#
|
||||
# =============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REGISTRY="${REGISTRY:-gitea.kube.quest}"
|
||||
ORG="bench"
|
||||
PLATFORM="linux/arm64" # Hetzner CAX = ARM64
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||
log_success() { echo -e "${GREEN}[OK]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERRO]${NC} $1"; }
|
||||
|
||||
echo ""
|
||||
echo -e "${CYAN}════════════════════════════════════════════════════${NC}"
|
||||
echo -e "${CYAN} Preparando imagens de benchmark (gzip + estargz)${NC}"
|
||||
echo -e "${CYAN}════════════════════════════════════════════════════${NC}"
|
||||
echo ""
|
||||
echo " Registry: ${REGISTRY}"
|
||||
echo " Org: ${ORG}"
|
||||
echo " Platform: ${PLATFORM}"
|
||||
echo ""
|
||||
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
# Pré-requisitos
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
|
||||
if ! command -v docker &>/dev/null; then
|
||||
log_error "docker não encontrado"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Login no registry..."
|
||||
docker login "$REGISTRY" || { log_error "Falha no login"; exit 1; }
|
||||
|
||||
# Criar builder multi-platform se necessário
|
||||
BUILDER_NAME="bench-builder"
|
||||
if ! docker buildx inspect "$BUILDER_NAME" &>/dev/null; then
|
||||
log_info "Criando builder multi-platform..."
|
||||
docker buildx create --name "$BUILDER_NAME" --driver docker-container
|
||||
fi
|
||||
docker buildx use "$BUILDER_NAME"
|
||||
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
# Imagens a construir
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
|
||||
# Cada entrada: nome_local:imagem_base:descrição
|
||||
IMAGES=(
|
||||
"nginx:nginx:1.27-alpine:Web server (~45MB comprimido)"
|
||||
"node:node:22-alpine:Runtime Node.js (~130MB comprimido)"
|
||||
"postgres:postgres:17-alpine:Banco de dados (~100MB comprimido)"
|
||||
)
|
||||
|
||||
TMPDIR=$(mktemp -d)
|
||||
trap "rm -rf $TMPDIR" EXIT
|
||||
|
||||
for entry in "${IMAGES[@]}"; do
|
||||
IFS=':' read -r name base_image base_tag description <<< "$entry"
|
||||
base="${base_image}:${base_tag}"
|
||||
|
||||
echo ""
|
||||
echo -e "${CYAN}────────────────────────────────────────────${NC}"
|
||||
echo -e " ${name} — ${description}"
|
||||
echo -e " Base: ${base}"
|
||||
echo -e "${CYAN}────────────────────────────────────────────${NC}"
|
||||
|
||||
# Dockerfile idêntico para ambos os formatos
|
||||
cat > "${TMPDIR}/Dockerfile" <<EOF
|
||||
FROM ${base}
|
||||
EOF
|
||||
|
||||
# ── GZIP ──
|
||||
log_info "Building ${name}:gzip ..."
|
||||
docker buildx build \
|
||||
--platform "$PLATFORM" \
|
||||
--output "type=image,name=${REGISTRY}/${ORG}/${name}:gzip,push=true,compression=gzip" \
|
||||
-f "${TMPDIR}/Dockerfile" \
|
||||
"${TMPDIR}" --quiet
|
||||
log_success "${REGISTRY}/${ORG}/${name}:gzip"
|
||||
|
||||
# ── eStargz ──
|
||||
log_info "Building ${name}:estargz ..."
|
||||
docker buildx build \
|
||||
--platform "$PLATFORM" \
|
||||
--output "type=image,name=${REGISTRY}/${ORG}/${name}:estargz,push=true,compression=estargz,force-compression=true,oci-mediatypes=true" \
|
||||
-f "${TMPDIR}/Dockerfile" \
|
||||
"${TMPDIR}" --quiet
|
||||
log_success "${REGISTRY}/${ORG}/${name}:estargz"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo -e "${CYAN}════════════════════════════════════════════════════${NC}"
|
||||
echo -e "${GREEN} Imagens prontas para benchmark${NC}"
|
||||
echo -e "${CYAN}════════════════════════════════════════════════════${NC}"
|
||||
echo ""
|
||||
for entry in "${IMAGES[@]}"; do
|
||||
IFS=':' read -r name _ _ _ <<< "$entry"
|
||||
echo " ${REGISTRY}/${ORG}/${name}:gzip"
|
||||
echo " ${REGISTRY}/${ORG}/${name}:estargz"
|
||||
done
|
||||
echo ""
|
||||
echo "Próximo passo: ./benchmark.sh"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user