Skip to content

Commit cf6f1bb

Browse files
Merge pull request #3 from spotify/deployer
Add CloudFlare Resolver Deployer
2 parents f2a0fac + 4ff06df commit cf6f1bb

File tree

7 files changed

+480
-2
lines changed

7 files changed

+480
-2
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Keep .git included (do NOT list it here) so commit SHA is available if needed
2+
3+
# Build outputs
4+
**/target
5+
**/node_modules
6+
7+
# OS/editor files
8+
**/.DS_Store
9+
**/.idea
10+
**/.vscode
11+
12+
# Unneeded runtime data; fetched/generated during build/run
13+
data/*
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Build and Push Deployer Image
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'wasm/**'
7+
- 'wasm-msg/**'
8+
- 'data/**'
9+
pull_request:
10+
paths-ignore:
11+
- 'wasm/**'
12+
- 'wasm-msg/**'
13+
- 'data/**'
14+
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
jobs:
20+
docker:
21+
name: Build and (conditionally) push image
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 30
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Set up QEMU
29+
uses: docker/setup-qemu-action@v3
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to GHCR
35+
if: github.event_name == 'push'
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Docker meta
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ghcr.io/${{ github.repository_owner }}/confidence-cloudflare-deployer
47+
tags: |
48+
type=ref,event=branch
49+
type=ref,event=pr
50+
type=sha
51+
type=raw,value=latest,enable={{is_default_branch}}
52+
53+
- name: Build (and push on main/tags)
54+
uses: docker/build-push-action@v6
55+
with:
56+
context: .
57+
file: ./confidence-cloudflare-resolver/deployer/Dockerfile
58+
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
59+
build-args: |
60+
COMMIT_SHA=${{ github.sha }}
61+
platforms: linux/amd64
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}
64+
65+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## confidence-resolver-rs
1+
# Confidence Rust Flags Resolver
22

33
The Confidence Flag Resolver implemented in Rust, plus example hosts and a Cloudflare Worker build. This workspace compiles the core resolver to native and WebAssembly and demonstrates how to call it from Go, Node.js, Python, and Java.
44

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM rust:1.82
2+
3+
RUN rustup update stable && rustup target add wasm32-unknown-unknown
4+
5+
# Execute next commands in the directory /workspace
6+
WORKDIR /workspace
7+
8+
RUN apt-get update && \
9+
apt install -y protobuf-compiler jq && \
10+
protoc --version && jq --version
11+
12+
# Install curl and other necessary tools
13+
RUN apt-get update && apt-get install -y \
14+
curl \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
ENV NVM_DIR=/root/.nvm
18+
ENV NODE_VERSION=22.12.0
19+
20+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash \
21+
&& . $NVM_DIR/nvm.sh \
22+
&& nvm install $NODE_VERSION \
23+
&& nvm use $NODE_VERSION \
24+
&& nvm alias default $NODE_VERSION \
25+
&& npm install -g npm@latest
26+
27+
# Add Node.js and npm to PATH
28+
ENV PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH"
29+
30+
# Confirm versions
31+
RUN node -v && npm -v
32+
33+
# Install Wrangler CLI using npm
34+
RUN npm install -g wrangler@latest
35+
36+
ENV PATH=/usr/local/bin:$PATH
37+
38+
# Optionally pass the commit SHA at build time
39+
ARG COMMIT_SHA=""
40+
ENV COMMIT_SHA=${COMMIT_SHA}
41+
42+
# Copy entire repository (build context is repo root) into a subdir
43+
# to match script paths (it cds into confidence-resolver-rust)
44+
COPY . .
45+
46+
# Ensure deploy script is executable
47+
RUN chmod +x confidence-cloudflare-resolver/deployer/script.sh
48+
49+
# Default command runs the deployer script
50+
CMD ["./confidence-cloudflare-resolver/deployer/script.sh"]
51+
52+
# Remove sample/runtime data from the copied repo
53+
RUN rm -rf data/*
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# CloudFlare Resolver Worker Deployer
2+
3+
Docker container used to deploy the Confidence Rust resolver to CloudFlare.
4+
5+
# Build the image
6+
7+
From the **root of the repository**, run:
8+
9+
```
10+
docker build -f confidence-cloudflare-resolver/deployer/Dockerfile -t <YOUR_IMAGE_NAME> .
11+
```
12+
13+
# Usage
14+
15+
```
16+
docker run -it \
17+
-e CLOUDFLARE_ACCOUNT_ID='<>’ \
18+
-e CLOUDFLARE_API_TOKEN='<>’ \
19+
-e CONFIDENCE_ACCOUNT_ID='<>' \
20+
-e CONFIDENCE_CLIENT_ID='<>’ \
21+
-e CONFIDENCE_CLIENT_SECRET='<>’ \
22+
-e RESOLVE_TOKEN_ENCRYPTION_KEY='<>' \
23+
-e CONFIDENCE_RESOLVER_STATE_ETAG_URL=‘<>/v1/state:etag' \
24+
image-name
25+
```
26+
27+
The RESOLVE_TOKEN_ENCRYPTION_KEY key has to be a valid AES-128 (16 bytes) key, base64 encoded.
28+
This key is used internally in the resolver, and shouldn't be changed once deployed in production.
29+
30+
The CONFIDENCE_RESOLVER_STATE_ETAG_URL needs to point to the resolver you deployed / are about to deploy.
31+
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.
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.

0 commit comments

Comments
 (0)