|
| 1 | +FROM debian:stable-slim |
| 2 | + |
| 3 | +ENV FLOW_INSTALL_URL=https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh \ |
| 4 | + APP_HOME=/app \ |
| 5 | + SEED_DIR=/seed/state |
| 6 | + |
| 7 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 8 | + curl ca-certificates jq bash openssl netcat-openbsd git \ |
| 9 | + && rm -rf /var/lib/apt/lists/* |
| 10 | + |
| 11 | +# Install Flow CLI |
| 12 | +RUN bash -lc 'curl -fsSL "$FLOW_INSTALL_URL" | bash' \ |
| 13 | + && mv /root/.local/bin/flow /usr/local/bin/flow \ |
| 14 | + && chmod +x /usr/local/bin/flow \ |
| 15 | + && flow version |
| 16 | + |
| 17 | +WORKDIR ${APP_HOME} |
| 18 | +# Bring in your project files (flow.json, contracts/, scripts/, transactions/, etc.) |
| 19 | +COPY . ${APP_HOME} |
| 20 | +RUN chmod +x ${APP_HOME}/scripts/*.sh || true |
| 21 | + |
| 22 | +# ---------- PRE-SEED AT BUILD TIME ---------- |
| 23 | +# Start emulator in background with --persist, wait, seed, then stop. |
| 24 | +RUN bash -lc '\ |
| 25 | + set -euo pipefail; \ |
| 26 | + mkdir -p "$SEED_DIR"; \ |
| 27 | + echo "▶ Start emulator (build-time) with --persist to ${SEED_DIR}"; \ |
| 28 | + flow emulator start --verbose --persist "$SEED_DIR" > /tmp/emulator-build.log 2>&1 & \ |
| 29 | + EM_PID=$!; \ |
| 30 | + echo -n "⏳ Waiting for emulator ... "; \ |
| 31 | + for i in {1..60}; do nc -z 127.0.0.1 3569 && break || { echo -n "."; sleep 1; }; done; echo; \ |
| 32 | + echo "▶ Seeding"; \ |
| 33 | + # Your seed scripts can use `--network emulator` exactly like at runtime: |
| 34 | + [ -x ./local/setup_wallets.sh ] && ./local/setup_wallets.sh || true; \ |
| 35 | + [ -x ./local/setup_emulator.sh ] && ./local/setup_emulator.sh || true; \ |
| 36 | + echo "▶ Stop emulator (build-time)"; \ |
| 37 | + kill $EM_PID && wait $EM_PID || true \ |
| 38 | +' |
| 39 | + |
| 40 | +# ---------- RUNTIME ---------- |
| 41 | +EXPOSE 3569 8080 |
| 42 | +ENV FLOW_EMULATOR_FLAGS="--verbose --persist /seed/state" |
| 43 | + |
| 44 | +# At runtime we just start the emulator that already contains the baked state. |
| 45 | +ENTRYPOINT [ "bash", "-lc", "flow emulator start $FLOW_EMULATOR_FLAGS" ] |
0 commit comments