jenkins CICD
This commit is contained in:
1 parent
c5f868a8ef
commit
d710a88d04
20 files changed
+1174
-25
No files matched your search
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ENV_NAME="${1:?Environment is required: dev|test|prod}"
|
||||
FRONTEND_IMAGE="${2:-}"
|
||||
BACKEND_IMAGE="${3:-}"
|
||||
FRONTEND_CHANGED="${4:-false}"
|
||||
BACKEND_CHANGED="${5:-false}"
|
||||
DEPLOY_CONFIG_CHANGED="${6:-false}"
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
COMPOSE_FILE="${ROOT_DIR}/deploy/${ENV_NAME}/docker-compose.yml"
|
||||
ENV_FILE="${ROOT_DIR}/deploy/${ENV_NAME}/.env"
|
||||
|
||||
if [[ ! -f "${COMPOSE_FILE}" ]]; then
|
||||
echo "Missing compose file: ${COMPOSE_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "${ENV_FILE}" ]]; then
|
||||
echo "Missing env file: ${ENV_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if docker compose version >/dev/null 2>&1; then
|
||||
DC_CMD=(docker compose)
|
||||
elif command -v docker-compose >/dev/null 2>&1; then
|
||||
DC_CMD=(docker-compose)
|
||||
else
|
||||
echo "Missing docker compose command. Install docker compose plugin or docker-compose."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Using compose command: ${DC_CMD[*]}"
|
||||
|
||||
if [[ -n "${FRONTEND_IMAGE}" ]]; then
|
||||
export FRONTEND_IMAGE
|
||||
fi
|
||||
|
||||
if [[ -n "${BACKEND_IMAGE}" ]]; then
|
||||
export BACKEND_IMAGE
|
||||
fi
|
||||
|
||||
cd "${ROOT_DIR}"
|
||||
|
||||
services=()
|
||||
if [[ "${FRONTEND_CHANGED}" == "true" ]]; then
|
||||
services+=("hxops-frontend")
|
||||
fi
|
||||
if [[ "${BACKEND_CHANGED}" == "true" ]]; then
|
||||
services+=("hxops-backend")
|
||||
fi
|
||||
|
||||
if [[ ${#services[@]} -eq 0 && "${DEPLOY_CONFIG_CHANGED}" == "true" ]]; then
|
||||
services=("hxops-frontend" "hxops-backend")
|
||||
fi
|
||||
|
||||
if [[ ${#services[@]} -eq 0 ]]; then
|
||||
echo "No service changes detected, skipping deployment."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Deploying environment: ${ENV_NAME}"
|
||||
echo "Services: ${services[*]}"
|
||||
|
||||
"${DC_CMD[@]}" -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" up -d "${services[@]}"
|
||||
|
||||
"${ROOT_DIR}/scripts/healthcheck.sh" "${ENV_NAME}" "${COMPOSE_FILE}" "${ENV_FILE}"
|
||||
Reference in new issue
Block a user