-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Added bundler and install scripts (for dev) #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,9 @@ check: | |
|
|
||
| serve: | ||
| uv run --frozen python3 -m server.main | ||
|
|
||
| bundle: | ||
| ./scripts/bundler.sh | ||
|
|
||
| install: | ||
| ./scripts/install.sh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| BINARY_NAME="tiles" | ||
| DIST_DIR="dist" | ||
| SERVER_DIR="server" | ||
| TARGET="release" | ||
|
|
||
| VERSION=$(grep '^version' Cargo.toml | head -1 | awk -F'"' '{print $2}') | ||
| OS=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
| ARCH=$(uname -m) | ||
| OUT_NAME="${BINARY_NAME}-v${VERSION}-${ARCH}-${OS}" | ||
|
|
||
| echo "🚀 Building ${BINARY_NAME} (${TARGET} mode)..." | ||
| cargo build --${TARGET} | ||
|
|
||
| mkdir -p "${DIST_DIR}/tmp" | ||
| cp "target/${TARGET}/${BINARY_NAME}" "${DIST_DIR}/tmp/" | ||
| cp -r "${SERVER_DIR}" "${DIST_DIR}/tmp/" | ||
|
|
||
| rm -rf "${DIST_DIR}/tmp/server/__pycache__" | ||
| rm -rf "${DIST_DIR}/tmp/server/.venv" | ||
|
|
||
| echo "📦 Creating ${OUT_NAME}.tar.gz..." | ||
| tar -czf "${DIST_DIR}/${OUT_NAME}.tar.gz" -C "${DIST_DIR}/tmp" . | ||
|
|
||
| rm -rf "${DIST_DIR}/tmp" | ||
|
|
||
| echo "✅ Bundle created: ${DIST_DIR}/${OUT_NAME}.tar.gz" | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ENV="dev" # prod is another env, try taking it from github env | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REPO="tilesprivacy/tilekit" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # VERSION="${TILES_VERSION:-latest}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VERSION="0.1.0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INSTALL_DIR="$HOME/.local/bin" # CLI install location | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SERVER_DIR="$HOME/.local/share/tiles/server" # Python server folder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TMPDIR="$(mktemp -d)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OS=$(uname -s | tr '[:upper:]' '[:lower:]') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ARCH=$(uname -m) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log() { echo -e "\033[1;36m$*\033[0m"; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err() { echo -e "\033[1;31m$*\033[0m" >&2; exit 1; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "🔍 Checking Python..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! command -v python3 >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "⚠️ Python 3.10+ not found." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$OS" == "darwin" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "Installing via Homebrew..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| brew install python || err "Could not install Python automatically. Please install manually." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif [[ -f /etc/debian_version ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "Installing via apt..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo apt-get update -y && sudo apt-get install -y python3 python3-venv | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err "Please install Python manually: https://www.python.org/downloads/" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainPython version not validated despite "3.10+" requirement. The log message mentions "Python 3.10+" but the script only checks if Apply this diff to add version validation: echo "🔍 Checking Python..."
if ! command -v python3 >/dev/null 2>&1; then
log "⚠️ Python 3.10+ not found."
+ # Install Python
if [[ "$OS" == "darwin" ]]; then
log "Installing via Homebrew..."
brew install python || err "Could not install Python automatically. Please install manually."
elif [[ -f /etc/debian_version ]]; then
log "Installing via apt..."
sudo apt-get update -y && sudo apt-get install -y python3 python3-venv
else
err "Please install Python manually: https://www.python.org/downloads/"
fi
+fi
+
+# Validate Python version
+PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")' 2>/dev/null || echo "0.0")
+REQUIRED_VERSION="3.10"
+if ! python3 -c "import sys; exit(0 if sys.version_info >= (3, 10) else 1)" 2>/dev/null; then
+ err "Python ${REQUIRED_VERSION}+ is required, but found ${PYTHON_VERSION}. Please upgrade."
fi🏁 Script executed: #!/bin/bash
# Examine the full install.sh file to understand context
cat scripts/install.shLength of output: 2245 🏁 Script executed: #!/bin/bash
# Search for Python version requirements in the repository
rg -n "3\.10|python" --type=toml --type=txt --type=yaml -C2 | head -50Length of output: 2587 🏁 Script executed: #!/bin/bash
# Check if there's a uv.lock or pyproject.toml with Python version spec
fd -e toml -e lock | xargs ls -la 2>/dev/null | head -20Length of output: 333 Python version not validated despite 3.10+ requirement. The script checks only if Apply the suggested diff to add version validation after the installation block: +# Validate Python version
+PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")' 2>/dev/null || echo "0.0")
+REQUIRED_VERSION="3.10"
+if ! python3 -c "import sys; exit(0 if sys.version_info >= (3, 10) else 1)" 2>/dev/null; then
+ err "Python ${REQUIRED_VERSION}+ is required, but found ${PYTHON_VERSION}. Please upgrade."
+fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "🔍 Checking uv..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! command -v uv >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "⬇️ Installing uv..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl -LsSf https://astral.sh/uv/install.sh | sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export PATH="$HOME/.local/bin:$PATH" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Piping remote script to shell without verification poses security risk. Downloading and executing Consider adding checksum verification or at least document this security consideration: log "⬇️ Installing uv..."
# Note: This downloads and executes a script from the internet.
# For enhanced security, consider verifying checksums.
curl -LsSf https://astral.sh/uv/install.sh | shAlternatively, download the script first, verify its checksum, then execute it. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "⬇️ Downloading Tiles (${VERSION}) for ${ARCH}-${OS}..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$ENV" == "prod" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TAR_URL="https://github.com/${REPO}/releases/download/${VERSION}/tiles-v${VERSION}-${ARCH}-${OS}.tar.gz" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl -fsSL -o "${TMPDIR}/tiles.tar.gz" "$TAR_URL" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Installer suppose to ran from tilekit root folder after running the bundler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mv "dist/tiles-v${VERSION}-${ARCH}-${OS}.tar.gz" "${TMPDIR}/tiles.tar.gz" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Using Apply this diff: # Installer suppose to ran from tilekit root folder after running the bundler
- mv "dist/tiles-v${VERSION}-${ARCH}-${OS}.tar.gz" "${TMPDIR}/tiles.tar.gz"
+ cp "dist/tiles-v${VERSION}-${ARCH}-${OS}.tar.gz" "${TMPDIR}/tiles.tar.gz" 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Validate tarball exists before proceeding. In dev mode, the script assumes the bundled tarball exists but doesn't verify it. If the bundler wasn't run or failed, the Apply this diff to add validation: if [[ "$ENV" == "prod" ]]; then
TAR_URL="https://github.com/${REPO}/releases/download/${VERSION}/tiles-v${VERSION}-${ARCH}-${OS}.tar.gz"
curl -fsSL -o "${TMPDIR}/tiles.tar.gz" "$TAR_URL"
else
# Installer suppose to ran from tilekit root folder after running the bundler
+ TARBALL="dist/tiles-v${VERSION}-${ARCH}-${OS}.tar.gz"
+ if [[ ! -f "$TARBALL" ]]; then
+ err "Tarball not found at $TARBALL. Run 'just bundle' first."
+ fi
- mv "dist/tiles-v${VERSION}-${ARCH}-${OS}.tar.gz" "${TMPDIR}/tiles.tar.gz"
+ cp "$TARBALL" "${TMPDIR}/tiles.tar.gz"
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "⬇️ Installing tiles..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Lets point to tile repo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tar -xzf "${TMPDIR}/tiles.tar.gz" -C "${TMPDIR}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "📦 Installing tiles binary to ${INSTALL_DIR}..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p "${INSTALL_DIR}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install -m 755 "${TMPDIR}/tiles" "${INSTALL_DIR}/tiles" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "📦 Installing Python server to ${SERVER_DIR}..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p "${SERVER_DIR}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cp -r "${TMPDIR}/server"/* "${SERVER_DIR}/" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "🔧 Setting up Python environment..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cd "${SERVER_DIR}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uv sync --frozen || err "Dependency setup failed." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rm -rf "${TMPDIR}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "✅ Tiles installed successfully!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "👉 Make sure ${INSTALL_DIR} is in your PATH." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate VERSION extraction and handle edge cases.
The version extraction assumes a specific format in Cargo.toml and does not validate the result. If the pattern fails to match or the field is malformed, VERSION will be empty, leading to a malformed tarball name.
Apply this diff to add validation:
VERSION=$(grep '^version' Cargo.toml | head -1 | awk -F'"' '{print $2}') +if [[ -z "$VERSION" ]]; then + echo "❌ Error: Could not extract version from Cargo.toml" >&2 + exit 1 +fi📝 Committable suggestion
🤖 Prompt for AI Agents