sync build tree from private myoffice
This commit is contained in:
+31
-11
@@ -4,6 +4,7 @@
|
|||||||
# GITEA_URL, GITEA_OWNER, GITEA_REPO, RELEASE_TAG (latest|v1.2.3)
|
# GITEA_URL, GITEA_OWNER, GITEA_REPO, RELEASE_TAG (latest|v1.2.3)
|
||||||
# API_DIR (default /opt/myoffice/api)
|
# API_DIR (default /opt/myoffice/api)
|
||||||
# RELEASE_ASSET_URL — optional direct override (skips API resolve)
|
# RELEASE_ASSET_URL — optional direct override (skips API resolve)
|
||||||
|
# LOCAL_RELEASE_TAR — optional local .tar.gz (skips download; used when host pushes asset into CT)
|
||||||
# GITEA_TOKEN — optional for private release downloads
|
# GITEA_TOKEN — optional for private release downloads
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -14,6 +15,7 @@ GITEA_OWNER="${GITEA_OWNER:-}"
|
|||||||
GITEA_REPO="${GITEA_REPO:-myoffice_public}"
|
GITEA_REPO="${GITEA_REPO:-myoffice_public}"
|
||||||
RELEASE_TAG="${RELEASE_TAG:-latest}"
|
RELEASE_TAG="${RELEASE_TAG:-latest}"
|
||||||
RELEASE_ASSET_URL="${RELEASE_ASSET_URL:-}"
|
RELEASE_ASSET_URL="${RELEASE_ASSET_URL:-}"
|
||||||
|
LOCAL_RELEASE_TAR="${LOCAL_RELEASE_TAR:-}"
|
||||||
ASSET_NAME="${ASSET_NAME:-myoffice-publish.tar.gz}"
|
ASSET_NAME="${ASSET_NAME:-myoffice-publish.tar.gz}"
|
||||||
GITEA_TOKEN="${GITEA_TOKEN:-}"
|
GITEA_TOKEN="${GITEA_TOKEN:-}"
|
||||||
|
|
||||||
@@ -69,22 +71,26 @@ resolve_asset_url() {
|
|||||||
echo "$browser_url"
|
echo "$browser_url"
|
||||||
}
|
}
|
||||||
|
|
||||||
download_and_extract() {
|
# Download release asset to a file path (usable on Proxmox host).
|
||||||
local url tar_path staging
|
download_asset_to() {
|
||||||
|
local dest="$1"
|
||||||
|
local url
|
||||||
url=$(resolve_asset_url)
|
url=$(resolve_asset_url)
|
||||||
msg "Downloading release asset: $url"
|
msg "Downloading release asset: $url"
|
||||||
|
curl_auth -o "$dest" "$url"
|
||||||
|
msg "Saved $dest"
|
||||||
|
}
|
||||||
|
|
||||||
|
extract_tar_to_api() {
|
||||||
|
local tar_path="$1"
|
||||||
|
local staging prod shared_prod prod_bak="" shared_bak="" top_count top_dir only
|
||||||
|
|
||||||
mkdir -p "$API_DIR"
|
mkdir -p "$API_DIR"
|
||||||
tar_path="/tmp/${ASSET_NAME}"
|
|
||||||
curl_auth -o "$tar_path" "$url"
|
|
||||||
|
|
||||||
staging=$(mktemp -d /tmp/myoffice-extract.XXXXXX)
|
staging=$(mktemp -d /tmp/myoffice-extract.XXXXXX)
|
||||||
tar -xzf "$tar_path" -C "$staging"
|
tar -xzf "$tar_path" -C "$staging"
|
||||||
rm -f "$tar_path"
|
|
||||||
|
|
||||||
local prod="${API_DIR}/appsettings.Production.json"
|
prod="${API_DIR}/appsettings.Production.json"
|
||||||
local shared_prod="${API_DIR}/appsettings.shared.Production.json"
|
shared_prod="${API_DIR}/appsettings.shared.Production.json"
|
||||||
local prod_bak="" shared_bak=""
|
|
||||||
if [[ -f "$prod" ]]; then
|
if [[ -f "$prod" ]]; then
|
||||||
prod_bak=$(mktemp)
|
prod_bak=$(mktemp)
|
||||||
cp -a "$prod" "$prod_bak"
|
cp -a "$prod" "$prod_bak"
|
||||||
@@ -94,11 +100,9 @@ download_and_extract() {
|
|||||||
cp -a "$shared_prod" "$shared_bak"
|
cp -a "$shared_prod" "$shared_bak"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local top_count top_dir
|
|
||||||
top_count=$(find "$staging" -mindepth 1 -maxdepth 1 | wc -l)
|
top_count=$(find "$staging" -mindepth 1 -maxdepth 1 | wc -l)
|
||||||
top_dir=""
|
top_dir=""
|
||||||
if [[ "$top_count" -eq 1 ]]; then
|
if [[ "$top_count" -eq 1 ]]; then
|
||||||
local only
|
|
||||||
only=$(find "$staging" -mindepth 1 -maxdepth 1 | head -1)
|
only=$(find "$staging" -mindepth 1 -maxdepth 1 | head -1)
|
||||||
if [[ -d "$only" ]]; then
|
if [[ -d "$only" ]]; then
|
||||||
top_dir="$only"
|
top_dir="$only"
|
||||||
@@ -132,6 +136,22 @@ download_and_extract() {
|
|||||||
msg "App extracted to ${API_DIR}"
|
msg "App extracted to ${API_DIR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
download_and_extract() {
|
||||||
|
local tar_path
|
||||||
|
|
||||||
|
if [[ -n "$LOCAL_RELEASE_TAR" && -f "$LOCAL_RELEASE_TAR" ]]; then
|
||||||
|
msg "Using local release tar: $LOCAL_RELEASE_TAR"
|
||||||
|
tar_path="$LOCAL_RELEASE_TAR"
|
||||||
|
extract_tar_to_api "$tar_path"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
tar_path="/tmp/${ASSET_NAME}"
|
||||||
|
download_asset_to "$tar_path"
|
||||||
|
extract_tar_to_api "$tar_path"
|
||||||
|
rm -f "$tar_path"
|
||||||
|
}
|
||||||
|
|
||||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
download_and_extract
|
download_and_extract
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -29,10 +29,11 @@ msg() { echo -e " ==> $*"; }
|
|||||||
|
|
||||||
as_postgres() {
|
as_postgres() {
|
||||||
# Script runs as root in CT; sudo is not installed.
|
# Script runs as root in CT; sudo is not installed.
|
||||||
|
# cd away from /root — postgres cannot access it (harmless but noisy otherwise).
|
||||||
if command -v runuser >/dev/null 2>&1; then
|
if command -v runuser >/dev/null 2>&1; then
|
||||||
runuser -u postgres -- "$@"
|
(cd /tmp && runuser -u postgres -- "$@")
|
||||||
else
|
else
|
||||||
su -s /bin/bash postgres -c "$*"
|
(cd /tmp && su -s /bin/bash postgres -c "$(printf '%q ' "$@")")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -449,6 +449,32 @@ push_install_assets() {
|
|||||||
pct exec "$CTID" -- chmod +x "${dest_dir}/install-in-ct.sh" "${dest_dir}/fetch-release.sh" "${dest_dir}/update.sh"
|
pct exec "$CTID" -- chmod +x "${dest_dir}/install-in-ct.sh" "${dest_dir}/fetch-release.sh" "${dest_dir}/update.sh"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# CT often cannot reach Gitea (isolated LAN). Download release on the Proxmox host, then push in.
|
||||||
|
download_release_on_host() {
|
||||||
|
local host_tar="/tmp/myoffice-publish.tar.gz"
|
||||||
|
local fetch_src
|
||||||
|
|
||||||
|
msg_info "Downloading release on Proxmox host..."
|
||||||
|
if [[ -n "${SCRIPT_DIR}" && -f "${SCRIPT_DIR}/fetch-release.sh" ]]; then
|
||||||
|
fetch_src="${SCRIPT_DIR}/fetch-release.sh"
|
||||||
|
else
|
||||||
|
curl -fsSL "${REPO_RAW_BASE}/proxmox/fetch-release.sh" -o /tmp/fetch-release.sh
|
||||||
|
fetch_src=/tmp/fetch-release.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
GITEA_URL="$GITEA_URL" \
|
||||||
|
GITEA_OWNER="$GITEA_OWNER" \
|
||||||
|
GITEA_REPO="$GITEA_REPO" \
|
||||||
|
RELEASE_TAG="$RELEASE_TAG" \
|
||||||
|
RELEASE_ASSET_URL="$RELEASE_ASSET_URL" \
|
||||||
|
GITEA_TOKEN="$GITEA_TOKEN" \
|
||||||
|
bash -c 'source "'"$fetch_src"'" && download_asset_to "'"$host_tar"'"'
|
||||||
|
|
||||||
|
pct push "$CTID" "$host_tar" "/tmp/myoffice-publish.tar.gz"
|
||||||
|
msg_ok "Release pushed into CT"
|
||||||
|
}
|
||||||
|
|
||||||
run_ct_install() {
|
run_ct_install() {
|
||||||
if [[ -z "${PUBLIC_URL}" ]]; then
|
if [[ -z "${PUBLIC_URL}" ]]; then
|
||||||
PUBLIC_URL="http://${CT_IP}:${API_PORT}"
|
PUBLIC_URL="http://${CT_IP}:${API_PORT}"
|
||||||
@@ -457,6 +483,7 @@ run_ct_install() {
|
|||||||
msg_error "Set GITEA_URL + GITEA_OWNER (and GITEA_REPO), or RELEASE_ASSET_URL, before install."
|
msg_error "Set GITEA_URL + GITEA_OWNER (and GITEA_REPO), or RELEASE_ASSET_URL, before install."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
download_release_on_host
|
||||||
msg_info "Installing PostgreSQL + ASP.NET runtime + Gitea release..."
|
msg_info "Installing PostgreSQL + ASP.NET runtime + Gitea release..."
|
||||||
pct exec "$CTID" -- env \
|
pct exec "$CTID" -- env \
|
||||||
REPO_RAW_BASE="$REPO_RAW_BASE" \
|
REPO_RAW_BASE="$REPO_RAW_BASE" \
|
||||||
@@ -470,6 +497,7 @@ run_ct_install() {
|
|||||||
RELEASE_TAG="$RELEASE_TAG" \
|
RELEASE_TAG="$RELEASE_TAG" \
|
||||||
RELEASE_ASSET_URL="$RELEASE_ASSET_URL" \
|
RELEASE_ASSET_URL="$RELEASE_ASSET_URL" \
|
||||||
GITEA_TOKEN="$GITEA_TOKEN" \
|
GITEA_TOKEN="$GITEA_TOKEN" \
|
||||||
|
LOCAL_RELEASE_TAR="/tmp/myoffice-publish.tar.gz" \
|
||||||
bash /tmp/myoffice-proxmox/install-in-ct.sh
|
bash /tmp/myoffice-proxmox/install-in-ct.sh
|
||||||
msg_ok "Stack installed"
|
msg_ok "Stack installed"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user