El nombre de la imagen sale de la carpeta del servicio y el Dockerfile depende de si es java o web.
Así se puede desplegar sin pom.xml y ubicar el Dockerfile en la raíz cuando el servicio es web.
This commit is contained in:
+42
-11
@@ -3,7 +3,8 @@
|
||||
# Build the native Quarkus image and push it to a remote Docker host
|
||||
# via a temporary registry:2 on the remote, reached through an SSH tunnel.
|
||||
#
|
||||
# - Image name/tag default to pom.xml properties (artifactId and version)
|
||||
# - Image name defaults to the last directory of the service location
|
||||
# - Image tag defaults to the pom.xml version (1.0.0-SNAPSHOT if there is no pom)
|
||||
# - Builds for linux/amd64 by default (cross-compile from arm64 hosts)
|
||||
# - Transfers layers over the tunnel (no external registry required)
|
||||
# - On the remote, durable tags are :latest and vYYYY.MM.DD-HH.MM (UTC) only
|
||||
@@ -11,7 +12,6 @@
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
readonly DOCKERFILE="src/main/docker/Dockerfile"
|
||||
readonly DEFAULT_PLATFORM="linux/amd64"
|
||||
readonly TEMP_REGISTRY_IMAGE="registry:2"
|
||||
readonly SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
|
||||
@@ -22,6 +22,8 @@ IMAGE_TAG=""
|
||||
SSH_KEY=""
|
||||
SSH_CONFIG=""
|
||||
PROJECT_DIR="${PROJECT_DIR:-${SCRIPT_DIR}/..}"
|
||||
APP_TYPE="java"
|
||||
DOCKERFILE=""
|
||||
SKIP_BUILD=0
|
||||
SKIP_VERIFY=0
|
||||
CLEANUP=0
|
||||
@@ -63,16 +65,21 @@ Required:
|
||||
or a bare alias resolved from ~/.ssh/config
|
||||
(e.g. 'prod'). See SSH config aliases below.
|
||||
|
||||
Image identity (defaults read from pom.xml):
|
||||
--name NAME Image repository name
|
||||
--tag TAG Local build tag (from pom.xml by default). On the
|
||||
Image identity:
|
||||
--name NAME Image repository name (default: last directory of
|
||||
the service location)
|
||||
--tag TAG Local build tag (pom.xml version by default, or
|
||||
1.0.0-SNAPSHOT if there is no pom.xml). On the
|
||||
remote only :latest and vYYYY.MM.DD-HH.MM (UTC).
|
||||
|
||||
Working directory (defaults to the parent of the script's directory):
|
||||
--project-dir PATH Project root containing pom.xml
|
||||
--project-dir PATH Service root. The image name is its last directory
|
||||
(override with env PROJECT_DIR)
|
||||
|
||||
Build options:
|
||||
--type java|web Dockerfile location. java (default):
|
||||
src/main/docker/Dockerfile
|
||||
web: Dockerfile at the service root
|
||||
--skip-build Skip docker build, only push an existing image
|
||||
(platform is fixed to ${DEFAULT_PLATFORM})
|
||||
|
||||
@@ -102,6 +109,7 @@ Examples:
|
||||
$(basename "$0") --remote prod # uses 'Host prod' in ~/.ssh/config
|
||||
$(basename "$0") --remote ubuntu@1.2.3.4 --ssh-key ~/.ssh/deploy_ed25519
|
||||
$(basename "$0") --remote deploy@prod --skip-build --tag 2.0.0
|
||||
$(basename "$0") --remote prod --type web
|
||||
$(basename "$0") --remote prod --cleanup
|
||||
/absolute/path/to/test-quarkus/scripts/$(basename "$0") --remote deploy@prod
|
||||
PROJECT_DIR=/srv/proj $(basename "$0") --remote deploy@prod --skip-build
|
||||
@@ -111,16 +119,39 @@ EOF
|
||||
read_pom() {
|
||||
local xpath="$1" fallback="$2" tag="${3:-}"
|
||||
local value=""
|
||||
if [[ ! -f pom.xml ]]; then
|
||||
printf '%s' "$fallback"
|
||||
return 0
|
||||
fi
|
||||
if command -v xmllint >/dev/null 2>&1; then
|
||||
value=$(xmllint --xpath "string($xpath)" pom.xml 2>/dev/null || true)
|
||||
fi
|
||||
if [[ -z "$value" && -n "$tag" ]]; then
|
||||
value=$(grep -E "<${tag}>" pom.xml | head -1 \
|
||||
| sed -E "s:.*<${tag}>(.*)</${tag}>.*:\1:")
|
||||
| sed -E "s:.*<${tag}>(.*)</${tag}>.*:\1:" || true)
|
||||
fi
|
||||
printf '%s' "${value:-$fallback}"
|
||||
}
|
||||
|
||||
# java: src/main/docker/Dockerfile; web: Dockerfile at the service root.
|
||||
resolve_dockerfile() {
|
||||
case "$APP_TYPE" in
|
||||
java) DOCKERFILE="src/main/docker/Dockerfile" ;;
|
||||
web) DOCKERFILE="Dockerfile" ;;
|
||||
*) die "Unknown --type '$APP_TYPE' (use java or web)." ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Last directory of the service location (cwd must already be that directory).
|
||||
image_name_from_location() {
|
||||
local dir
|
||||
dir="$(pwd)"
|
||||
dir="${dir%/}"
|
||||
[[ -n "$dir" && "$dir" != "/" ]] \
|
||||
|| die "Cannot derive image name from project directory."
|
||||
printf '%s' "${dir##*/}"
|
||||
}
|
||||
|
||||
require() {
|
||||
command -v "$1" >/dev/null 2>&1 || die "Required command '$1' not found in PATH."
|
||||
}
|
||||
@@ -382,6 +413,7 @@ while [[ $# -gt 0 ]]; do
|
||||
--ssh-key) SSH_KEY="$2"; shift 2 ;;
|
||||
--ssh-config) SSH_CONFIG="$2"; shift 2 ;;
|
||||
--project-dir) PROJECT_DIR="$2"; shift 2 ;;
|
||||
--type) APP_TYPE="$2"; shift 2 ;;
|
||||
--skip-build) SKIP_BUILD=1; shift ;;
|
||||
--no-verify) SKIP_VERIFY=1; shift ;;
|
||||
--cleanup) CLEANUP=1; shift ;;
|
||||
@@ -391,6 +423,7 @@ while [[ $# -gt 0 ]]; do
|
||||
done
|
||||
|
||||
[[ -z "$REMOTE" ]] && die "Missing --remote USER@HOST[:PORT] (use --help)."
|
||||
resolve_dockerfile
|
||||
|
||||
# ---------- resolve SSH target ----------
|
||||
resolved=$(resolve_ssh_alias "$REMOTE")
|
||||
@@ -411,8 +444,7 @@ if [[ "$CLEANUP" -eq 1 ]]; then
|
||||
if ! cd "${PROJECT_DIR}" 2>/dev/null; then
|
||||
die "Invalid --project-dir: ${PROJECT_DIR}"
|
||||
fi
|
||||
[[ -z "$IMAGE_NAME" ]] \
|
||||
&& IMAGE_NAME=$(read_pom "/*[local-name()='project']/*[local-name()='artifactId']" "test-quarkus" "artifactId")
|
||||
[[ -z "$IMAGE_NAME" ]] && IMAGE_NAME="$(image_name_from_location)"
|
||||
parse_ssh_target
|
||||
build_ssh_args
|
||||
detect_remote_docker
|
||||
@@ -428,7 +460,7 @@ fi
|
||||
PROJECT_DIR="$(pwd)"
|
||||
|
||||
# ---------- defaults ----------
|
||||
[[ -z "$IMAGE_NAME" ]] && IMAGE_NAME=$(read_pom "/*[local-name()='project']/*[local-name()='artifactId']" "test-quarkus" "artifactId")
|
||||
[[ -z "$IMAGE_NAME" ]] && IMAGE_NAME="$(image_name_from_location)"
|
||||
[[ -z "$IMAGE_TAG" ]] && IMAGE_TAG=$(read_pom "/*[local-name()='project']/*[local-name()='version']" "1.0.0-SNAPSHOT" "version")
|
||||
|
||||
IMAGE_REF="${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
@@ -445,7 +477,6 @@ docker info >/dev/null 2>&1 \
|
||||
|| die "Docker daemon is not reachable. Start Docker Desktop (or your daemon) and retry."
|
||||
|
||||
[[ -f "$DOCKERFILE" ]] || die "Dockerfile not found at ${DOCKERFILE}."
|
||||
[[ -f pom.xml ]] || die "pom.xml not found in current directory."
|
||||
|
||||
parse_ssh_target
|
||||
build_ssh_args
|
||||
|
||||
Reference in New Issue
Block a user