Skip to content

Commit 68ab3c4

Browse files
committed
gha emulator build
1 parent 16af405 commit 68ab3c4

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: 'Build and Push Flow Emulator Image'
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
DOCKER_IMAGE_URL: us-west1-docker.pkg.dev/dl-flow-devex-staging/backend/flow-emulator:${{ github.sha }}
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
steps:
18+
- name: 'Checkout'
19+
uses: 'actions/checkout@v4'
20+
with:
21+
submodules: recursive
22+
token: ${{ secrets.GH_PAT }}
23+
24+
- id: 'auth'
25+
name: 'Authenticate to Google Cloud'
26+
uses: 'google-github-actions/auth@v2'
27+
with:
28+
workload_identity_provider: '${{ vars.BUILDER_WORKLOAD_IDENTITY_PROVIDER }}'
29+
service_account: '${{ vars.BUILDER_SERVICE_ACCOUNT }}'
30+
31+
- name: 'Set up gcloud'
32+
uses: 'google-github-actions/setup-gcloud@v1'
33+
with:
34+
project_id: ${{ vars.GAR_PROJECT_ID }}
35+
36+
- name: 'Build and Push Flow Emulator'
37+
run: |
38+
gcloud auth configure-docker ${{ vars.GAR_REGION }}-docker.pkg.dev
39+
docker build -t "${{ env.DOCKER_IMAGE_URL }}" .
40+
docker push "${{ env.DOCKER_IMAGE_URL }}"

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)