workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: GitHub action failing with environment

Open gijo-varghese opened this issue 1 year ago • 10 comments

What version of Wrangler are you using?

2.0.23

What operating system are you using?

Mac

Describe the Bug

I'm using GitHub actions to deploy workers to different environments. But I'm getting an error as follows (though the worker is deployed correctly).

Using API Token authentication
$ Running: wrangler publish --env staging
 ⛅️ wrangler 2.0.23 
--------------------
▲ [WARNING] Processing wrangler.toml configuration:

    - 😶 Ignored: "type":
      Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
    - Deprecation: "zone_id":
      This is unnecessary since we can deduce this from routes directly.
    - Unexpected fields found in top-level field: "format"


Total Upload: 8.24 KiB / gzip: 2.46 KiB
Worker ID:  optimizer-staging
Worker ETag:  3a3a8f22a65093324d091b67d22dad172e5fd555289bf604b8b226290fcd9fe3
Uploaded optimizer-staging (0.61 sec)

✘ [ERROR] A request to the Cloudflare API (/accounts/xyz/workers/scripts/optimizer-staging/routes) failed.

 workers.api.error.duplicate_route [code: 10020]

wrangler.toml

name = "optimizer"
type = "javascript"
format = "service-worker"
main = "./src/index.js"

account_id = "abc"
zone_id = "xyz"
compatibility_date = "2022-04-13"
usage_model = "bundled"

[env.production]
name = "optimizer-production"
route = { pattern = "*/*", zone_id = "xyz" }

[env.staging]
name = "optimizer-staging"
route = { pattern = "*/*", zone_id = "xyz" }

deploy.yml

name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v3
      - name: Publish
        uses: cloudflare/[email protected]
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          command: publish --env staging

gijo-varghese avatar Jul 30 '22 13:07 gijo-varghese

The error code specifies what's going on here, you're trying to deploy the worker to the same route in both production and staging environments, which is not what you probably want.

threepointone avatar Jul 30 '22 13:07 threepointone

@threepointone tried different route, but same error.

wrangler.toml

name = "optimizer"
type = "javascript"
format = "service-worker"
main = "./src/index.js"

account_id = "abc"
zone_id = "xyz"
compatibility_date = "2022-04-13"
usage_model = "bundled"

[env.production]
name = "optimizer-production"
route = { pattern = "*/*", zone_id = "xyz" }

[env.staging]
name = "optimizer-staging"
route = { pattern = "*example.com/*", zone_id = "xyz" }

gijo-varghese avatar Jul 30 '22 13:07 gijo-varghese

It's possible that you've already deployed another worker to those routes. You'll have to remove them from the dashboard before publishing with wrangler again.

threepointone avatar Jul 30 '22 13:07 threepointone

@threepointone tried deleting, but still no luck. I'm using the same .toml file with buddy.works, and it deploys fine!

gijo-varghese avatar Jul 30 '22 13:07 gijo-varghese

You'll have to check, that's what the error means. There's a worker already deployed to the route.

threepointone avatar Jul 30 '22 15:07 threepointone

@threepointone, what if I want to overwrite/update? The worker in production cannot be deleted.

gijo-varghese avatar Jul 30 '22 15:07 gijo-varghese

You can deploy a worker with the same name to that route. I'm suggesting you change the staging one to another route that doesn't overlap with the production one.

threepointone avatar Jul 30 '22 15:07 threepointone

I deleted the entire staging worker and its routes. Still not working.

gijo-varghese avatar Jul 30 '22 16:07 gijo-varghese

I can't help you debug a usage problem here I'm afraid. This is definitely not a wrangler issue though. I'd recommend asking in discord, with more details of the wrangler.toml without substitutions.

threepointone avatar Jul 30 '22 16:07 threepointone

Also I would check that you don't happen to have another completely separate worker wired up to the same route.

petebacondarwin avatar Jul 30 '22 16:07 petebacondarwin

Let us know if you were able to get support in the Discord.

https://discord.gg/cloudflaredev

JacobMGEvans avatar Aug 15 '22 16:08 JacobMGEvans