Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions docker/Dockerfile.fly
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
FROM python:3.12-slim

# Cache busting argument (set during build to force fresh layers)
ARG CACHEBUST=4

# Use CACHEBUST to invalidate cache when needed (this layer changes when CACHEBUST changes)
RUN echo "Cache bust: $CACHEBUST" > /tmp/cachebust

# Install system dependencies including nginx
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
Expand All @@ -20,17 +14,24 @@ RUN apt-get update && apt-get install -y --no-install-recommends \

WORKDIR /opt/dagster/app

# Copy requirements and install Python dependencies
# Copy requirements and install Python dependencies (these change less frequently)
COPY requirements.txt requirements-dashboard.txt ./
RUN pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir -r requirements-dashboard.txt

# Copy application code
# Cache busting argument (set during build to force fresh layers)
ARG CACHEBUST=5

# Use CACHEBUST to invalidate cache when needed (this layer changes when CACHEBUST changes)
# This must come BEFORE copying application code to ensure fresh code on force rebuild
RUN echo "Cache bust: $CACHEBUST" > /tmp/cachebust

# Copy application code (this will now be invalidated by CACHEBUST when force rebuilding)
COPY anomstack ./anomstack
COPY dashboard ./dashboard
COPY metrics ./metrics

# Capture git commit hash for version info
# Capture git commit hash for version info (must be after code copy to track the right version)
ARG ANOMSTACK_BUILD_HASH
ENV ANOMSTACK_BUILD_HASH=${ANOMSTACK_BUILD_HASH}

Expand Down
11 changes: 9 additions & 2 deletions metrics/examples/iss_location/iss_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ def ingest():
res = requests.get(url, timeout=10).json()
ts = pd.to_datetime(int(res["timestamp"]), unit="s")
pos = res["iss_position"]

lat = float(pos["latitude"])
lon = float(pos["longitude"])

metrics = [
["iss_latitude", float(pos["latitude"])],
["iss_longitude", float(pos["longitude"])],
["iss_latitude", lat],
["iss_longitude", lon],
["latlong_avg", (lat + lon) / 2],
["latlong_sum", lat + lon],
["latlong_diff", lat - lon],
]
df = pd.DataFrame(metrics, columns=["metric_name", "metric_value"])
df["metric_timestamp"] = ts
Expand Down
14 changes: 12 additions & 2 deletions scripts/deployment/deploy_fly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ if [[ -n "$TEMP_ENV_FILE" && -f "$TEMP_ENV_FILE" ]]; then
echo "🧹 Cleaned up temporary configuration file"
fi

# Always ensure ANOMSTACK_BUILD_HASH is set correctly
if [[ -n "$GIT_COMMIT_HASH" ]]; then
all_secrets+=("ANOMSTACK_BUILD_HASH=$GIT_COMMIT_HASH")
echo "🏷️ Adding build hash to secrets: $GIT_COMMIT_HASH"
fi

Comment on lines +216 to +221
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Bug: GIT_COMMIT_HASH used before it’s defined, so the early secret is never set.

At this point GIT_COMMIT_HASH hasn’t been initialized (it’s defined at Lines 244–250), so [[ -n "$GIT_COMMIT_HASH" ]] is always false and ANOMSTACK_BUILD_HASH never gets added to all_secrets. This breaks the intended “early emission” of the build hash.

Fix options (pick one):

  • Preferred: move the “capture git commit hash” block (Lines 244–250) up above this section, then keep this early secret injection.
  • Minimal: remove this early block and set ANOMSTACK_BUILD_HASH after computing the hash (before fly secrets set) to avoid an extra release.

Apply removal of the no-op block now:

-if [[ -n "$GIT_COMMIT_HASH" ]]; then
-    all_secrets+=("ANOMSTACK_BUILD_HASH=$GIT_COMMIT_HASH")
-    echo "🏷️  Adding build hash to secrets: $GIT_COMMIT_HASH"
-fi

Then, immediately after computing GIT_COMMIT_HASH (current Lines 244–250), add:

# Ensure build hash is included in the single secrets operation
if [[ -n "$GIT_COMMIT_HASH" ]]; then
    all_secrets+=("ANOMSTACK_BUILD_HASH=$GIT_COMMIT_HASH")
    echo "🏷️  Adding build hash to secrets: $GIT_COMMIT_HASH"
fi
🤖 Prompt for AI Agents
In scripts/deployment/deploy_fly.sh around lines 216-221, remove the no-op early
check that tests GIT_COMMIT_HASH before it is defined; then immediately after
the block that computes GIT_COMMIT_HASH (around lines 244-250) add a guarded
append to all_secrets that checks the newly computed GIT_COMMIT_HASH and, if
non-empty, adds ANOMSTACK_BUILD_HASH to all_secrets and echoes the added build
hash so the single fly secrets operation includes the build hash.

# Set all secrets in one command to minimize releases
if [[ ${#all_secrets[@]} -gt 0 ]]; then
echo "🔐 Setting ${#all_secrets[@]} environment variables as Fly secrets in single operation..."
Expand Down Expand Up @@ -249,8 +255,8 @@ if [[ "$FORCE_REBUILD" == "true" ]]; then
echo "🔄 Force rebuild enabled - using aggressive cache busting..."
echo "🎯 Cache bust value: $CACHEBUST_VALUE"

# Use multiple cache busting strategies:
# 1. --no-cache: Skip Docker layer cache
# Force rebuild with multiple strategies:
# 1. --no-cache: Skip Docker layer cache entirely
# 2. CACHEBUST build arg: Force rebuild of layers that use it
# 3. ANOMSTACK_BUILD_HASH build arg: Include git commit hash in container
# 4. --dockerfile: Explicit dockerfile path to avoid confusion
Expand All @@ -260,6 +266,10 @@ if [[ "$FORCE_REBUILD" == "true" ]]; then
--build-arg ANOMSTACK_BUILD_HASH="$GIT_COMMIT_HASH" \
--dockerfile docker/Dockerfile.fly \
-a "$APP_NAME"

# After deployment, manually update the secret to ensure consistency
echo "🔄 Updating ANOMSTACK_BUILD_HASH secret to match deployed version..."
fly secrets set ANOMSTACK_BUILD_HASH="$GIT_COMMIT_HASH" -a "$APP_NAME"
else
echo "⚡ Standard deployment (with caching)..."
fly deploy \
Expand Down