Skip to content

Commit 35f4535

Browse files
A bit more polish and docs for CF deployer
1 parent 8eaecb5 commit 35f4535

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

confidence-cloudflare-resolver/deployer/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ This key is used internally in the resolver, and shouldn't be changed once deplo
2929

3030
The CONFIDENCE_RESOLVER_STATE_ETAG_URL needs to point to the resolver you deployed / are about to deploy.
3131
The `.../v1/state:etag` is the path used to retrieve the etag if available, ignored otherwise.
32-
The etag value is used to avoid re-deploy the worker if the state hasn't changed since the last deploy.
32+
The etag value is used to avoid re-deploy the worker if the state hasn't changed since the last deploy.
33+
34+
Additional optional variables:
35+
- CONFIDENCE_RESOLVER_STATE_URL: Point to a custom resolver state protobuf file;
36+
- CONFIDENCE_RESOLVER_ALLOWED_ORIGIN: Configure allowed origins in the wrangler used to deploy the resolver;
37+
- FORCE_DEPLOY: Re-deploy the resolver worker, regardless if the state is detected as changed or not.

confidence-cloudflare-resolver/deployer/script.sh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ if test -z "$CONFIDENCE_ACCOUNT_ID"; then
3333
fi
3434

3535
if test -z "$CONFIDENCE_RESOLVER_STATE_URL"; then
36-
echo "CONFIDENCE_RESOLVER_STATE_URL not provided; attempting to fetch via API"
37-
3836
# Ensure jq is available for JSON parsing
3937
if ! command -v jq >/dev/null 2>&1; then
4038
echo "jq is required but not installed. Please install jq (e.g., brew install jq) or provide CONFIDENCE_RESOLVER_STATE_URL"
@@ -101,10 +99,6 @@ if test -z "$CONFIDENCE_RESOLVER_STATE_URL"; then
10199
fi
102100
fi
103101

104-
echo "Starting CloudFlare deployment for $CONFIDENCE_ACCOUNT_ID"
105-
echo "CloudFlare API token: ${CLOUDFLARE_API_TOKEN:0:5}.."
106-
echo "CloudFlare account ID: $CLOUDFLARE_ACCOUNT_ID"
107-
108102
mkdir -p data
109103
RESPONSE_FILE="data/resolver_state_current.pb"
110104
ETAG_TOML=""
@@ -115,21 +109,21 @@ CLIENT_SECRET_TOML=""
115109

116110
EXTRA_HEADER=()
117111

118-
# Try to fetch previous ETag from deployed resolver endpoint if provided
112+
# Try to fetch previous etag from deployed resolver endpoint if provided
119113
PREV_ETAG=""
120114
PREV_DEPLOYER_VERSION=""
121115
if [ -n "$CONFIDENCE_RESOLVER_STATE_ETAG_URL" ]; then
122-
echo "🌐 Fetching previous ETag from $CONFIDENCE_RESOLVER_STATE_ETAG_URL"
116+
echo "🌐 Fetching etag and git version from $CONFIDENCE_RESOLVER_STATE_ETAG_URL"
123117
ETAG_BODY_TMP=$(mktemp)
124118
ETAG_STATUS=$(curl -sS -w "%{http_code}" -o "$ETAG_BODY_TMP" "$CONFIDENCE_RESOLVER_STATE_ETAG_URL") || ETAG_STATUS="000"
125119
if [ "$ETAG_STATUS" = "200" ]; then
126120
if command -v jq >/dev/null 2>&1 && grep -q '^[[:space:]]*{' "$ETAG_BODY_TMP"; then
127121
PREV_ETAG=$(jq -r '.etag // empty' "$ETAG_BODY_TMP") || PREV_ETAG=""
128122
PREV_DEPLOYER_VERSION=$(jq -r '.version // empty' "$ETAG_BODY_TMP") || PREV_DEPLOYER_VERSION=""
129123
if [ -n "$PREV_ETAG" ]; then
130-
echo "⤵️ Previous ETag from resolver: $PREV_ETAG"
124+
echo "⤵️ Previous etag from resolver: $PREV_ETAG"
131125
else
132-
echo "️Resolver returned empty ETag"
126+
echo "️ Resolver returned empty ETag"
133127
fi
134128
if [ -n "$PREV_DEPLOYER_VERSION" ]; then
135129
echo "⤵️ Previous Resolver Version from resolver: $PREV_DEPLOYER_VERSION"
@@ -140,13 +134,13 @@ if [ -n "$CONFIDENCE_RESOLVER_STATE_ETAG_URL" ]; then
140134
PREV_ETAG=$(tr -d '\r' < "$ETAG_BODY_TMP")
141135
PREV_ETAG=$(echo -n "$PREV_ETAG" | tr -d '\n')
142136
if [ -n "$PREV_ETAG" ]; then
143-
echo "⤵️ Previous ETag from resolver: $PREV_ETAG"
137+
echo "⤵️ Previous etag from resolver: $PREV_ETAG"
144138
else
145139
echo "⚠️ Resolver returned empty ETag"
146140
fi
147141
fi
148142
else
149-
echo "❌ Could not fetch ETag from resolver (HTTP $ETAG_STATUS)"
143+
echo "❌ Could not fetch etag from resolver (HTTP $ETAG_STATUS)"
150144
fi
151145
rm -f "$ETAG_BODY_TMP"
152146
fi
@@ -167,7 +161,7 @@ else
167161
fi
168162

169163

170-
# If version changed, force download to bypass ETag and ensure fresh deploy
164+
# If version changed, force download to bypass etag and ensure fresh deploy
171165
if [ -n "$PREV_DEPLOYER_VERSION" ] && [ -n "$DEPLOYER_VERSION" ] && [ "$PREV_DEPLOYER_VERSION" != "$DEPLOYER_VERSION" ]; then
172166
echo "☑️ Deployer version changed ($PREV_DEPLOYER_VERSION -> $DEPLOYER_VERSION); forcing state download and redeploy"
173167
FORCE_DEPLOY=1
@@ -192,7 +186,7 @@ if [ "$HTTP_STATUS" = "304" ]; then
192186
exit 0
193187
elif [ "$HTTP_STATUS" = "200" ]; then
194188
echo "✅ Download of resolver state successful"
195-
# Extract ETag and normalize
189+
# Extract etag and normalize
196190
ETAG_RAW=$(awk -F': ' 'tolower($1)=="etag"{print $2}' "$TMP_HEADER" | tr -d '\r')
197191
rm -f "$TMP_HEADER"
198192
# Normalize ETag: drop weak prefix and surrounding quotes, then escape for TOML
@@ -235,14 +229,18 @@ echo "🚀 All files successfully created and verified"
235229

236230
cd confidence-cloudflare-resolver
237231

232+
echo "🏁 Starting CloudFlare deployment for $CONFIDENCE_ACCOUNT_ID"
233+
echo "☁️ CloudFlare API token: ${CLOUDFLARE_API_TOKEN:0:5}.."
234+
echo "☁️ CloudFlare account ID: $CLOUDFLARE_ACCOUNT_ID"
235+
236+
238237
if [ -n "$CLOUDFLARE_ACCOUNT_ID" ]; then
239238
# Remove existing account_id line if present
240239
sed -i.tmp '/^account_id *= *.*$/d' wrangler.toml
241240
tmpfile=$(mktemp)
242241
echo "account_id = \"$CLOUDFLARE_ACCOUNT_ID\"" > "$tmpfile"
243242
cat wrangler.toml >> "$tmpfile"
244243
mv "$tmpfile" wrangler.toml
245-
echo "✅ account_id set to \"$CLOUDFLARE_ACCOUNT_ID\" in wrangler.toml"
246244
else
247245
echo "⚠️ CLOUDFLARE_ACCOUNT_ID environment variable is not set. This is required if the CloudFlare API token is of type Account, while User tokens with the correct permissions don't need this env variable set"
248246
fi

0 commit comments

Comments
 (0)