82 lines
3.5 KiB
Bash
Executable File
82 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds the branding-patched ERPNext image (see Dockerfile) and tags it to
|
|
# match whatever CUSTOM_IMAGE/CUSTOM_TAG this deployment's .env expects.
|
|
#
|
|
# Usage (from the sightbox/ project root or from here — either works):
|
|
# ./erpnext-image/build.sh
|
|
#
|
|
# Re-run this any time ERPNEXT_VERSION in .env changes — the Dockerfile's
|
|
# own grep checks fail the build loudly if erpnext/hooks.py no longer
|
|
# matches what this patch expects (e.g. after a version bump reworded it),
|
|
# rather than silently shipping an unpatched image.
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ROOT_ENV="${SCRIPT_DIR}/../.env"
|
|
|
|
# Preserve any value a caller already exported (e.g. scripts/prod.sh setting
|
|
# a registry path) before sourcing .env below — .env's own CUSTOM_IMAGE/
|
|
# CUSTOM_TAG/PULL_POLICY lines are plain assignments, not conditional
|
|
# defaults (docker compose reads this same file directly, so it can't use
|
|
# bash's ${VAR:=default} syntax), and would otherwise silently clobber a
|
|
# caller's override the moment it's sourced.
|
|
_PRESET_CUSTOM_IMAGE="${CUSTOM_IMAGE:-}"
|
|
_PRESET_CUSTOM_TAG="${CUSTOM_TAG:-}"
|
|
_PRESET_PULL_POLICY="${PULL_POLICY:-}"
|
|
|
|
if [ -f "$ROOT_ENV" ]; then
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "$ROOT_ENV"
|
|
set +a
|
|
fi
|
|
|
|
[ -n "$_PRESET_CUSTOM_IMAGE" ] && CUSTOM_IMAGE="$_PRESET_CUSTOM_IMAGE"
|
|
[ -n "$_PRESET_CUSTOM_TAG" ] && CUSTOM_TAG="$_PRESET_CUSTOM_TAG"
|
|
[ -n "$_PRESET_PULL_POLICY" ] && PULL_POLICY="$_PRESET_PULL_POLICY"
|
|
|
|
ERPNEXT_VERSION="${ERPNEXT_VERSION:?Set ERPNEXT_VERSION in .env first (see .env.example)}"
|
|
CUSTOM_IMAGE="${CUSTOM_IMAGE:-sightbox-erpnext}"
|
|
CUSTOM_TAG="${CUSTOM_TAG:-${ERPNEXT_VERSION}-branded}"
|
|
FULL_TAG="${CUSTOM_IMAGE}:${CUSTOM_TAG}"
|
|
|
|
# A bare local tag (no "/" at all, e.g. "sightbox-erpnext") means "local dev
|
|
# only" — build for this machine's own architecture so it runs immediately,
|
|
# nothing to push. A registry path always has at least one "/"
|
|
# (host/owner/name or owner/name).
|
|
if [[ "${CUSTOM_IMAGE}" != */* ]]; then
|
|
echo "Building ${FULL_TAG} (local dev, host architecture) from frappe/erpnext:${ERPNEXT_VERSION}"
|
|
docker build \
|
|
--build-arg "ERPNEXT_VERSION=${ERPNEXT_VERSION}" \
|
|
-t "${FULL_TAG}" \
|
|
"${SCRIPT_DIR}"
|
|
echo
|
|
echo "Built ${FULL_TAG}."
|
|
echo "Set in .env (see .env.example):"
|
|
echo " CUSTOM_IMAGE=${CUSTOM_IMAGE}"
|
|
echo " CUSTOM_TAG=${CUSTOM_TAG}"
|
|
echo "Then: docker compose up -d --force-recreate configurator backend frontend websocket queue-short queue-long scheduler"
|
|
exit 0
|
|
fi
|
|
|
|
# A registry path: build specifically for linux/amd64, the real Dokploy VPS
|
|
# target — confirmed the hard way: a plain `docker build` on an Apple
|
|
# Silicon Mac produces an arm64-only image with no amd64 manifest entry, so
|
|
# the (amd64) VPS fails to pull it ("no matching manifest for linux/amd64").
|
|
# buildx --platform forces the amd64 target regardless of this machine's
|
|
# own architecture (via QEMU emulation if needed); --push uploads the
|
|
# result directly, since a cross-platform buildx result can't be loaded
|
|
# into the local `docker images` store the way a same-arch build can.
|
|
echo "Building ${FULL_TAG} for linux/amd64 (Dokploy VPS target) from frappe/erpnext:${ERPNEXT_VERSION}"
|
|
docker buildx build \
|
|
--platform linux/amd64 \
|
|
--build-arg "ERPNEXT_VERSION=${ERPNEXT_VERSION}" \
|
|
-t "${FULL_TAG}" \
|
|
--push \
|
|
"${SCRIPT_DIR}"
|
|
|
|
echo
|
|
echo "Built and pushed ${FULL_TAG}."
|
|
echo "Then: redeploy in Dokploy, or docker compose up -d --force-recreate configurator backend frontend websocket queue-short queue-long scheduler"
|