diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..e079e7f --- /dev/null +++ b/build.sh @@ -0,0 +1,117 @@ + +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_DIR="${ROOT_DIR}/frappe_repo" + +REGISTRY_IMAGE="git.prothmann.com/christian/erpnexthp" +BUILD_IMAGE="${REGISTRY_IMAGE}:build-local" + +cd "$REPO_DIR" + +# -------------------------------------------------- +# 1. Define applications +# -------------------------------------------------- + +APPS_FILE="$(mktemp)" +trap 'rm -f "$APPS_FILE"' EXIT + +cat > "$APPS_FILE" <<'JSON' +[ + { + "url": "https://github.com/frappe/erpnext", + "branch": "version-16" + }, + { + "url": "https://git.prothmann.com/christian/manufacturing_overview", + "branch": "version-15" + }, + { + "url": "https://git.prothmann.com/christian/label_printing", + "branch": "version-15" + }, + { + "url": "https://git.prothmann.com/christian/manufacturing_utilities", + "branch": "test" + } +] +JSON + +# -------------------------------------------------- +# 2. Build AMD64 production image +# -------------------------------------------------- + +echo "Building ERPNext 16 for linux/amd64..." + +docker buildx build \ + --platform linux/amd64 \ + --pull \ + --load \ + --build-arg FRAPPE_PATH=https://github.com/frappe/frappe \ + --build-arg FRAPPE_BRANCH=version-16 \ + --build-arg "CACHE_BUST=$(date -u +%s)" \ + --secret "id=apps_json,src=${APPS_FILE}" \ + --tag "${BUILD_IMAGE}" \ + --file images/layered/Containerfile \ + . + +# -------------------------------------------------- +# 3. Read ERPNext version from built image +# -------------------------------------------------- + +ERP_VERSION="$( + docker run --rm \ + --platform linux/amd64 \ + --entrypoint /bin/cat \ + "${BUILD_IMAGE}" \ + /home/frappe/frappe-bench/apps/erpnext/erpnext/__init__.py \ + | awk -F '"' '/^__version__ = / {print $2; exit}' +)" + +if [[ ! "$ERP_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "ERROR: Could not determine ERPNext version." + exit 1 +fi + +FINAL_IMAGE="${REGISTRY_IMAGE}:${ERP_VERSION}" + +echo "Detected ERPNext version: ${ERP_VERSION}" + +# -------------------------------------------------- +# 4. Tag and push to Gitea +# -------------------------------------------------- + +docker tag "${BUILD_IMAGE}" "${FINAL_IMAGE}" + +echo "Publishing ${FINAL_IMAGE}..." + +docker push "${FINAL_IMAGE}" + +# -------------------------------------------------- +# 5. Generate official Compose for hyp1 +# -------------------------------------------------- + +echo "Generating production Docker Compose..." + +docker compose \ + --project-name erpnext-16 \ + -f compose.yaml \ + -f overrides/compose.mariadb.yaml \ + -f overrides/compose.redis.yaml \ + config --no-interpolate \ + > "${ROOT_DIR}/docker-compose.yml" + +# Ensure the version stays configurable +if ! grep -q 'CUSTOM_IMAGE' "${ROOT_DIR}/docker-compose.yml"; then + echo "ERROR: Image variables were not preserved." + exit 1 +fi + +echo "" +echo "Build completed successfully." +echo "Image: ${FINAL_IMAGE}" +echo "Compose: ${ROOT_DIR}/docker-compose.yml" +echo "" +echo "Update ERPNEXT_VERSION=${ERP_VERSION} on hyp1." + diff --git a/example.env b/example.env new file mode 100644 index 0000000..e69de29 diff --git a/pull-frappe_repo.sh b/pull-frappe_repo.sh new file mode 100755 index 0000000..5418af8 --- /dev/null +++ b/pull-frappe_repo.sh @@ -0,0 +1 @@ +git -C frappe_repo pull --ff-only