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
2 changes: 1 addition & 1 deletion .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:
AUTHKEY=$(curl -fsSL -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"capabilities":{"devices":{"create":{"reusable":false,"ephemeral":true,"preauthorized":true,"tags":["tag:prodzilla-preview"]}}},"expirySeconds":3600}' \
-d '{"capabilities":{"devices":{"create":{"reusable":true,"ephemeral":true,"preauthorized":true,"tags":["tag:prodzilla-preview"]}}},"expirySeconds":3600}' \
https://api.tailscale.com/api/v2/tailnet/-/keys | jq -r .key)
echo "::add-mask::$AUTHKEY"

Expand Down
33 changes: 27 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,41 @@ ARG RUST_VERSION=1.85
FROM node:20-slim AS frontend-build
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm ci
RUN --mount=type=cache,target=/root/.npm npm ci
COPY frontend/ ./
RUN npm run build

# Build Rust binary
FROM rust:${RUST_VERSION}-slim-bookworm AS build

# Rust build base with cargo-chef preinstalled
FROM lukemathwalker/cargo-chef:latest-rust-${RUST_VERSION} AS chef
WORKDIR /app
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends libssl-dev pkg-config \
&& rm -rf /var/lib/apt/lists/*

# Generate the dependency recipe. Only Cargo.toml/Cargo.lock content
# (via recipe.json) determines the cook cache key downstream.
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

RUN apt-get update -y && apt-get install -y libssl-dev pkg-config
# Cook deps, then build the binary. Keep target/ in the layer (so the cooked
# deps live in a cacheable Docker layer) and use BuildKit cache mounts only
# for cargo's registry/git, which speeds up cold-cache fetches. Pin the
# target dir explicitly because the cargo-chef base image overrides
# CARGO_TARGET_DIR to a project-name-derived path under /tmp.
FROM chef AS build
ENV CARGO_TARGET_DIR=/app/target
COPY --from=planner /app/recipe.json recipe.json
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
--mount=type=cache,target=/usr/local/cargo/git,sharing=locked \
cargo chef cook --release --recipe-path recipe.json

COPY . .
COPY --from=frontend-build /app/frontend/dist ./frontend/dist
RUN cargo build --locked --release --target-dir target && cp ./target/release/prodzilla /bin/prodzilla
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
--mount=type=cache,target=/usr/local/cargo/git,sharing=locked \
cargo build --locked --release --bin prodzilla \
&& cp ./target/release/prodzilla /bin/prodzilla

FROM debian:bookworm-slim AS final

Expand Down
6 changes: 3 additions & 3 deletions scripts/preview-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ SOCK=/tmp/tailscaled.sock

tailscaled \
--tun=userspace-networking \
--state=mem: \
--state=/tmp/tailscale-state \
--socket="$SOCK" &

i=0
until tailscale --socket="$SOCK" status >/dev/null 2>&1; do
until [ -S "$SOCK" ]; do
i=$((i + 1))
if [ $i -gt 50 ]; then
echo "tailscaled did not become ready within 10s" >&2
echo "tailscaled socket did not appear within 10s" >&2
exit 1
fi
sleep 0.2
Expand Down
Loading