Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wrangler] Added sub commands in the deployments #2607

Merged
merged 14 commits into from
Mar 16, 2023

Conversation

JacobMGEvans
Copy link
Contributor

@JacobMGEvans JacobMGEvans commented Jan 24, 2023

view <deployment-id> will get the details of a deployment, including versioned script, bindings, and usage model information.
This information can be used to help debug bad deployments or get insights on changes between deployments.

rollback <deployment-id> will rollback to a specific deployment in the runtime. This will be useful in situations like recovering from a bad
deployment quickly while resolving issues. This rollback only changes the code in the runtime and doesn't affect any code or configurations
in a developer's local setup.

example of view <deployment-id> output:

	{
    Tag: '',
    Number: 0,
    'Metadata.author_id': 'Picard-Gamma-6-0-7-3',
    'Metadata.author_email': 'picard@vinyard.com',
    'Metadata.source': 'wrangler',
    'Metadata.created_on': '2021-01-01T00:00:00.000000Z',
    'Metadata.modified_on': '2021-01-01T00:00:00.000000Z',
    'resources.script': {
      etag: 'mock-e-tag',
      handlers: [ 'fetch' ],
      last_deployed_from: 'wrangler'
    },
    'resources.bindings': []
  }



  export default {
    async fetch(request) {
      return new Response('Hello World from Deployment 1701-E');
    },
  };

Reviewer has performed the following, where applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

Ticket: Internal

@JacobMGEvans JacobMGEvans requested a review from a team as a code owner January 24, 2023 18:16
@changeset-bot
Copy link

changeset-bot bot commented Jan 24, 2023

🦋 Changeset detected

Latest commit: d3292dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jan 24, 2023

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4438796242/npm-package-wrangler-2607

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/2607/npm-package-wrangler-2607

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4438796242/npm-package-wrangler-2607 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4438796242/npm-package-cloudflare-pages-shared-2607

Note that these links will no longer work once the GitHub Actions artifact expires.

@JacobMGEvans JacobMGEvans marked this pull request as draft January 24, 2023 18:37
@codecov
Copy link

codecov bot commented Jan 24, 2023

Codecov Report

Merging #2607 (d3292dc) into main (6fd0624) will increase coverage by 0.13%.
The diff coverage is 82.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2607      +/-   ##
==========================================
+ Coverage   73.95%   74.09%   +0.13%     
==========================================
  Files         167      167              
  Lines       10299    10418     +119     
  Branches     2748     2785      +37     
==========================================
+ Hits         7617     7719     +102     
- Misses       2682     2699      +17     
Impacted Files Coverage Δ
...ckages/wrangler/src/__tests__/helpers/msw/index.ts 100.00% <ø> (ø)
packages/wrangler/src/create-worker-upload-form.ts 90.65% <ø> (ø)
packages/wrangler/src/metrics/send-event.ts 100.00% <ø> (ø)
.../src/__tests__/helpers/msw/handlers/deployments.ts 69.56% <53.33%> (-30.44%) ⬇️
packages/wrangler/src/deployments.ts 76.19% <80.00%> (+6.80%) ⬆️
packages/wrangler/src/init.ts 93.82% <86.66%> (+0.03%) ⬆️
packages/wrangler/src/index.ts 84.46% <100.00%> (+0.54%) ⬆️
packages/wrangler/src/publish/publish.ts 87.43% <100.00%> (+0.63%) ⬆️

... and 3 files with indirect coverage changes

},
};`;
} else {
scriptContent = "DIDN'T GET SCRIPT CONTENT";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: Create a test for script retrieval failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And failed requests with these scenarios:

"errors": [
    {
      "code": 100146,
      "message": "workers.api.error.deployment_not_found"
    }
  ],
  "messages": []
"errors": [
    {
      "code": 100147,
      "message": "workers.api.error.deployment_too_old"
    }
  ],
  "messages": []
"errors": [
    {
      "code": 100140,
      "message": "Failed to rollback due to external resources being modified (durable-object:<tag>,r2:<name>)"
    }
  ],
  "messages": []

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still TODO?

Copy link
Contributor

@rozenmd rozenmd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that wrangler deployments is starting to actually do stuff, (in a separate PR), can we move the handler and options into its own file or folder, like dev, delete, publish, r2, secret, etc?

JacobMGEvans added a commit to cloudflare/cloudflare-docs that referenced this pull request Jan 31, 2023
Adding general documentation for rollbacks & view on deployments.
Including Rollbacks to deployments platform page.

DEVX-285 & DEVX-284
related #cloudflare/workers-sdk#2607
@JacobMGEvans JacobMGEvans marked this pull request as ready for review February 15, 2023 21:57
@jspspike jspspike force-pushed the jacobmgevans/deployment-view-rollback branch from 0b33a7f to 0cfd522 Compare February 16, 2023 23:32
Comment on lines 1 to 21
export default {
async fetch(request, env, ctx) {
const { pathname } = new URL(request.url);
if (pathname === "/setup") {
await env.DB.exec(
"CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, value TEXT);"
);
return new Response(null, { status: 204 });
} else if (pathname === "/query") {
const rows = await env.DB.prepare("SELECT * FROM test;").all();
return Response.json(rows.results);
}
throw new Error("Not found!");
},
async scheduled(controller, env, ctx) {
const stmt = await env.DB.prepare(
"INSERT INTO test (id, value) VALUES (?, ?)"
);
await stmt.bind(1, "one").run();
},
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't commit this @jspspike , its randomly generated by one of the tests, @rozenmd is this a D1 related test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it.

@petebacondarwin petebacondarwin force-pushed the jacobmgevans/deployment-view-rollback branch from fb54aff to e18d0d4 Compare February 20, 2023 09:30
.changeset/brown-wasps-fail.md Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/deployments.test.ts Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/deployments.test.ts Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/deployments.test.ts Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/deployments.test.ts Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/deployments.test.ts Outdated Show resolved Hide resolved
},
};`;
} else {
scriptContent = "DIDN'T GET SCRIPT CONTENT";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still TODO?

packages/wrangler/src/__tests__/jest.setup.ts Outdated Show resolved Hide resolved
@JacobMGEvans JacobMGEvans changed the title [Feature] Added sub commands in the deployments [Wrangler] Added sub commands in the deployments Feb 23, 2023
@JacobMGEvans JacobMGEvans added the wrangler Relating to the Wrangler CLI tool label Feb 23, 2023
@jspspike jspspike force-pushed the jacobmgevans/deployment-view-rollback branch from d698ee6 to 5e605ae Compare February 27, 2023 16:06
@jspspike jspspike requested a review from a team as a code owner February 27, 2023 16:06
@jspspike jspspike force-pushed the jacobmgevans/deployment-view-rollback branch from f3dcc66 to c157001 Compare February 27, 2023 20:31
@jspspike jspspike force-pushed the jacobmgevans/deployment-view-rollback branch 2 times, most recently from ae166d2 to da6fc75 Compare March 15, 2023 20:30
jspspike and others added 14 commits March 16, 2023 10:30
Added a positional in the 'Deployments' command <deployment-id>.
<deployment-id> will get the details of the deployment, including versioned script, bindings, and usage model information.

changeset added

snapshot for commands updated

removed stray quotes
Created a subcommand on deployments that allows for rolling back a deployment to a previous ID provided.

Changed the command structure to have 2 subcommands view and rollback

Improved the Changeset messaging and combined rollback

Update help messages

Added comfirmation prompt to Rollback

Implemented --yes flag with tests

Updated tests

comfirmation handles non-TTY environments automatically fixed tests to reflect that and removed --yes option

tests breaking in CI

Turn off chalk in tests

Update messaging with new copy for confirm prompt matching dashboard & removing the PUT response in output

snapshots updated

rollback accounts URL
# This is the 1st commit message:

Update rollback fetch call and remove deployments request from publish

# This is the commit message #2:

destructure the one value we want from the result
destructure the one value we want from the result

Have script upload msw always return response body

Update deployment tests

Fixed misc tests

Delete index.js

Added check for request on rollback tests

Fix issue with wrangler version appearing after prompt
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
… specified (#2841)

Co-authored-by: jjohnson <jjohnson@cloudflare.com>
* Add suggested changes and update wrangler docs

* Separate content into option on view command

---------

Co-authored-by: jjohnson <jjohnson@cloudflare.com>
* Add rollback reason

* fixup: Cleanup hanging prompt mocks in deployments tests

* Change structure for rollback commands

---------

Co-authored-by: jjohnson <jjohnson@cloudflare.com>
Co-authored-by: Samuel Macleod <smacleod@cloudflare.com>
@jspspike jspspike force-pushed the jacobmgevans/deployment-view-rollback branch from da6fc75 to d3292dc Compare March 16, 2023 15:30
@jspspike jspspike merged commit 163dccf into main Mar 16, 2023
@jspspike jspspike deleted the jacobmgevans/deployment-view-rollback branch March 16, 2023 20:29
@github-actions github-actions bot mentioned this pull request Mar 16, 2023
jspspike pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Mar 17, 2023
Adding general documentation for rollbacks & view on deployments.
Including Rollbacks to deployments platform page.

DEVX-285 & DEVX-284
related #cloudflare/workers-sdk#2607
@github-actions github-actions bot mentioned this pull request Mar 20, 2023
lrapoport-cf added a commit to cloudflare/cloudflare-docs that referenced this pull request Mar 22, 2023
* Add general documentation for deployment rollbacks & view. Related to cloudflare/workers-sdk#2607

Co-authored-by: jjohnson <jjohnson@cloudflare.com>
Co-authored-by: Adam Murray <admah@users.noreply.github.com>
Co-authored-by: Kate Tungusova <70746074+deadlypants1973@users.noreply.github.com>
Co-authored-by: lrapoport-cf <lrapoport@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wrangler Relating to the Wrangler CLI tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants