📝

コンテナから、Cloudflare Workersにデプロイする

に公開

※多分何年か前に書いたやつです。古いかもしれません。下書き供養です。

環境変数に

apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

をセットする。

https://github.com/cloudflare/wrangler-action/blob/3ea6e3f132caf107faeba789ccb713d57437d2a6/src/index.ts#L164

ciでやってる認証の通仕方と同じようにする

以下のコマンドを叩くとデプロイされます

wrangler deploy

こんな感じでリソースが作成されたら成功です


name = "app"
main = "build/worker/shim.mjs"
compatibility_date = "2024-09-07"
send_metrics = false
# [build]
# command = "worker-build --dev"

[build]
command = "worker-build --release"

wrangler.tomlはこんなふうにしています。

FROM --platform=amd64 node:22.8.0-bullseye

SHELL ["/bin/bash", "-c"]

RUN apt update && apt install -y \
curl wget git pkg-config libssl-dev

# rustは環境構築簡単だが、nodejsは色々buildしないといけなくてだるい。
# rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o installer.sh
RUN sh installer.sh -y

# rustのパスを通す
ENV PATH="/root/.cargo/bin:${PATH}"


RUN npm install -g wrangler
RUN rustup target add wasm32-unknown-unknown

RUN cargo install worker-build wasm-pack
RUN cargo install cargo-binstall
RUN cargo binstall --force --no-confirm cargo-watch cargo-generate

WORKDIR /app/server

dockerfileはこんな感じ

参考:
https://developers.cloudflare.com/workers/wrangler/ci-cd/#cloudflare-account-id

https://developers.cloudflare.com/workers/languages/rust/#4-deploy-your-worker-project

Discussion