From 782a130bb9cc5babd71d3e5acf8d687596bcc954 Mon Sep 17 00:00:00 2001 From: Daniel Arroyo Date: Thu, 24 Sep 2026 22:54:45 -0300 Subject: [PATCH] build: deploy several Quarkus services from one project list Add deploy-services.sh so a single command runs build-and-push.sh for every path in a project file, keeps going after a failure, and reports which services failed. --- README.md | 4 + scripts/README.md | 25 ++++ scripts/deploy-services.sh | 260 +++++++++++++++++++++++++++++++++++++ 3 files changed, 289 insertions(+) create mode 100755 scripts/deploy-services.sh diff --git a/README.md b/README.md index 1ee2d65..518ef23 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,10 @@ remote Docker daemon. No external registry is required. ./scripts/build-and-push.sh --remote deploy@prod.example.com ``` +To push every service in one project, pass that project's list file to +`./scripts/deploy-services.sh`. It runs `build-and-push.sh` once per path and +reports any failures at the end. See `scripts/README.md` for the list format. + The script reads `artifactId` and `version` from `pom.xml` for the local build tag and image name, builds for `linux/amd64`, and verifies the deploy on the remote. On the remote, durable tags are only: diff --git a/scripts/README.md b/scripts/README.md index 889a3eb..41fce91 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -196,3 +196,28 @@ Comprueba que la primera línea del log sea `Image: test-quarkus:1.0.0-SNAPSHOT` ``` Opcional: instala `xmllint` para que el script lea el POM con XPath (`libxml2-utils` en Debian/Ubuntu). + +## `deploy-services.sh` + +Script independiente, en el mismo directorio que `build-and-push.sh`. No lo modifica: lo ejecuta una vez por cada servicio de un archivo de lista. Si un servicio falla, sigue con el resto y al terminar indica cuáles fallaron. El código de salida es `1` si alguno falló. + +No hay lista por defecto. `--services` es obligatorio, así cada proyecto puede tener su propio archivo. + +```shell +./scripts/deploy-services.sh --remote prod --services /srv/proyecto-a/services.txt +./scripts/deploy-services.sh --remote prod --services /srv/proyecto-b/services.txt --skip-build +``` + +Formato del archivo: una ruta por línea. Se ignoran las líneas vacías y las que empiezan por `#`. Una ruta relativa se resuelve desde el directorio del archivo de lista, no desde el directorio donde lanzas el script. + +```text +# /srv/proyecto-a/services.txt +./api +./worker +``` + +Cada ruta es la raíz de un servicio Quarkus (`pom.xml` y `src/main/docker/Dockerfile`). El nombre y el tag de la imagen salen del `pom.xml` de ese servicio. + +Se reenvían a cada servicio: `--ssh-key`, `--ssh-config`, `--skip-build`, `--no-verify` y `--cleanup`. No se aceptan `--name`, `--tag` ni `--project-dir`. + +Ctrl+C interrumpe el lote. Ayuda: `./scripts/deploy-services.sh --help`. diff --git a/scripts/deploy-services.sh b/scripts/deploy-services.sh new file mode 100755 index 0000000..cb0b3c9 --- /dev/null +++ b/scripts/deploy-services.sh @@ -0,0 +1,260 @@ +#!/usr/bin/env bash +# +# Run scripts/build-and-push.sh once per service listed in a project file. +# Continues after a failure and prints a summary when the batch finishes. +# +# The list path is required (--services). Relative service paths are resolved +# against the directory that contains that file, not the caller's cwd. + +set -euo pipefail +IFS=$'\n\t' + +readonly SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)" +readonly BUILD_SCRIPT="${SCRIPT_DIR}/build-and-push.sh" + +SERVICES_FILE="" +REMOTE="" +forward_args=() + +# ---------- logging ---------- +if [[ -t 1 ]]; then + readonly C_INFO=$'\033[0;36m' + readonly C_OK=$'\033[0;32m' + readonly C_WARN=$'\033[0;33m' + readonly C_ERR=$'\033[0;31m' + readonly C_RESET=$'\033[0m' +else + readonly C_INFO="" C_OK="" C_WARN="" C_ERR="" C_RESET="" +fi + +log() { printf '%s[INFO]%s %s\n' "$C_INFO" "$C_RESET" "$*"; } +ok() { printf '%s[OK]%s %s\n' "$C_OK" "$C_RESET" "$*"; } +warn() { printf '%s[WARN]%s %s\n' "$C_WARN" "$C_RESET" "$*" >&2; } +err() { printf '%s[ERROR]%s %s\n' "$C_ERR" "$C_RESET" "$*" >&2; } +die() { err "$*"; exit 1; } + +on_error() { + local exit_code=$? + err "Script aborted on line ${BASH_LINENO[0]} (exit ${exit_code})." + exit "$exit_code" +} +trap on_error ERR + +# ---------- helpers ---------- +usage() { + cat <