Skip to content

Conversation

@elibosley
Copy link
Member

@elibosley elibosley commented Apr 4, 2025

Thanks to @s3ppo on Discord for flagging this issue

Summary by CodeRabbit

  • New Features

    • Introduced a dedicated mutation field that centralizes Docker operations via the API.
    • Added a new method for Docker-related mutations in the mutation resolver.
  • Refactor

    • Streamlined Docker container controls by renaming the start/stop operations for improved clarity.
    • Removed legacy fields to provide a more unified mutation interface.
  • Bug Fixes

    • Enhanced error handling during container start/stop operations to ensure consistent behavior.
  • Tests

    • Updated test cases to reflect the new naming and behavior, ensuring reliable Docker operation validations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 4, 2025

Walkthrough

This PR refactors the Docker GraphQL mutations by renaming methods and restructuring the schema. The DockerMutations type methods have been renamed (startContainerstart, stopContainerstop) and now reside under a new root Mutation type via a docker field. Corresponding changes were made in the resolvers, services, and tests to update method calls, annotations, and expectations while removing deprecated methods.

Changes

File(s) Change Summary
api/src/graphql/schema/types/docker/docker.graphql Renamed startContainer/stopContainer to start/stop in DockerMutations, added description comments, removed the mutation extension from Docker, and introduced a new Mutation type with a docker field.
api/src/unraid-api/graph/resolvers/docker/*.ts Renamed resolver methods and corresponding @ResolveField annotations from startContainer/stopContainer to start/stop; removed the legacy mutations method from DockerResolver.
api/src/unraid-api/graph/resolvers/docker/*.spec.ts Updated test cases to replace startContainer/stopContainer with start/stop and removed tests for the deprecated mutations field.
api/src/unraid-api/graph/resolvers/docker/docker.service.ts Renamed service methods from startContainer/stopContainer to start/stop, added a stop timeout (10 seconds) parameter, and explicitly set container state to EXITED after stopping.
api/src/unraid-api/graph/resolvers/mutation/mutation.resolver.ts Added a new docker resolver method returning an object with __typename set to 'DockerMutations'.

Possibly related PRs

Suggested reviewers

  • pujitm
  • mdatelle

Poem

In the realm of code, a change takes flight,
Docker’s new names shine crystal bright.
Old methods retire, a new path unfolds,
Tests and resolvers in harmony told.
Code sings a fresh, refined refrain—
Cheers to progress, with a smile and gain!
🚀✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 6cff4e3 and 53c765e.

📒 Files selected for processing (2)
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts (0 hunks)
  • api/src/unraid-api/graph/resolvers/docker/docker.service.ts (5 hunks)
💤 Files with no reviewable changes (1)
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Test API
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (9)
api/src/unraid-api/graph/resolvers/docker/docker.service.ts (9)

14-14: Good addition of the sleep utility

Adding the sleep import is necessary for implementing the retry mechanism in the stop method.


18-20: Good type extension for better interface definition

Extending the Docker.ContainerListOptions interface provides better type safety and leverages the existing Docker types.


129-157: Excellent extraction of container transformation logic

The new transformContainer method is a good refactoring that encapsulates the container transformation logic into a separate, reusable function. This improves code organization and maintainability.


159-166: Good enhancement to the getContainers method

The updated method signature with additional parameters (all, size, and spread operator for additional options) provides more flexibility while maintaining backward compatibility. Setting useCache default to false is also a sensible choice for ensuring fresh data.


175-177: Clean implementation of parameter passing

The code now properly forwards the new parameters to the Docker client API call.


181-181: Simplified autoStarts assignment

Direct assignment of getAutoStarts result to the class property simplifies the code.


184-184: Good use of the new transformation method

The code now uses the extracted transformContainer method, which makes this section cleaner.


207-207: Clear and concise method renaming

Renaming from startContainer to start makes the method name more concise while maintaining clarity, which aligns with the PR objective to restructure Docker mutations.


218-234: Robust implementation of container stop with retry mechanism

The renamed and enhanced stop method now includes:

  1. A specific timeout for the stop operation (10 seconds)
  2. A retry mechanism that attempts up to 5 times with 500ms delay between attempts
  3. Container list refresh on each attempt
  4. State verification to ensure the container has exited
  5. Improved logging for debugging

This implementation is more resilient against potential issues during container stops.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@elibosley elibosley changed the title fix: move docker mutations to the mutaitons resolver fix: move docker mutations to the mutations resolver Apr 4, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
api/src/unraid-api/graph/resolvers/docker/docker.service.ts (3)

154-154: Fix formatting - remove extra line break.

The static analysis tools have flagged an extra line break that should be removed to comply with the project's style guidelines.

        name: container.Status,
-

    },
🧰 Tools
🪛 GitHub Check: Test API

[failure] 154-154:
Delete

🪛 GitHub Check: Build API

[failure] 154-154:
Delete


160-160: Improve method parameter formatting.

The method parameters should be formatted according to the project's style guidelines, with each parameter on a new line for better readability.

- public async getContainers({ useCache = false, all = true, size = true, ...listOptions }: Partial<ContainerListingOptions> = { useCache: false }): Promise<DockerContainer[]> {
+ public async getContainers(
+     {
+         useCache = false,
+         all = true,
+         size = true,
+         ...listOptions
+     }: Partial<ContainerListingOptions> = { useCache: false }
+ ): Promise<DockerContainer[]> {
🧰 Tools
🪛 GitHub Check: Test API

[failure] 160-160:
Replace {·useCache·=·false,·all·=·true,·size·=·true,·...listOptions·}:·Partial<ContainerListingOptions>·=·{·useCache:·false·} with ⏎········{⏎············useCache·=·false,⏎············all·=·true,⏎············size·=·true,⏎············...listOptions⏎········}:·Partial<ContainerListingOptions>·=·{·useCache:·false·}⏎····

🪛 GitHub Check: Build API

[failure] 160-160:
Replace {·useCache·=·false,·all·=·true,·size·=·true,·...listOptions·}:·Partial<ContainerListingOptions>·=·{·useCache:·false·} with ⏎········{⏎············useCache·=·false,⏎············all·=·true,⏎············size·=·true,⏎············...listOptions⏎········}:·Partial<ContainerListingOptions>·=·{·useCache:·false·}⏎····


222-222: Fix spacing in template expression.

Add a space around the + operator in the template string for consistent formatting.

- this.logger.debug(`Container ${id} state after stop attempt ${i+1}: ${updatedContainer?.state}`);
+ this.logger.debug(`Container ${id} state after stop attempt ${i + 1}: ${updatedContainer?.state}`);
🧰 Tools
🪛 GitHub Check: Test API

[failure] 222-222:
Replace Container·${id}·state·after·stop·attempt·${i+1}:·${updatedContainer?.state} with ⏎················Container·${id}·state·after·stop·attempt·${i·+·1}:·${updatedContainer?.state}⏎············

🪛 GitHub Check: Build API

[failure] 222-222:
Replace Container·${id}·state·after·stop·attempt·${i+1}:·${updatedContainer?.state} with ⏎················Container·${id}·state·after·stop·attempt·${i·+·1}:·${updatedContainer?.state}⏎············

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 7bfeec6 and 6cff4e3.

📒 Files selected for processing (1)
  • api/src/unraid-api/graph/resolvers/docker/docker.service.ts (5 hunks)
🧰 Additional context used
🪛 GitHub Check: Test API
api/src/unraid-api/graph/resolvers/docker/docker.service.ts

[failure] 154-154:
Delete


[failure] 160-160:
Replace {·useCache·=·false,·all·=·true,·size·=·true,·...listOptions·}:·Partial<ContainerListingOptions>·=·{·useCache:·false·} with ⏎········{⏎············useCache·=·false,⏎············all·=·true,⏎············size·=·true,⏎············...listOptions⏎········}:·Partial<ContainerListingOptions>·=·{·useCache:·false·}⏎····


[failure] 222-222:
Replace Container·${id}·state·after·stop·attempt·${i+1}:·${updatedContainer?.state} with ⏎················Container·${id}·state·after·stop·attempt·${i·+·1}:·${updatedContainer?.state}⏎············

🪛 GitHub Check: Build API
api/src/unraid-api/graph/resolvers/docker/docker.service.ts

[failure] 154-154:
Delete


[failure] 160-160:
Replace {·useCache·=·false,·all·=·true,·size·=·true,·...listOptions·}:·Partial<ContainerListingOptions>·=·{·useCache:·false·} with ⏎········{⏎············useCache·=·false,⏎············all·=·true,⏎············size·=·true,⏎············...listOptions⏎········}:·Partial<ContainerListingOptions>·=·{·useCache:·false·}⏎····


[failure] 222-222:
Replace Container·${id}·state·after·stop·attempt·${i+1}:·${updatedContainer?.state} with ⏎················Container·${id}·state·after·stop·attempt·${i·+·1}:·${updatedContainer?.state}⏎············

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Web App
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (5)
api/src/unraid-api/graph/resolvers/docker/docker.service.ts (5)

14-14: New import for enhanced functionality.

The addition of the sleep utility is necessary for the improved retry mechanism in the stop method.


129-158: Good refactoring of container transformation logic.

Extracting the container transformation logic into a dedicated method improves code maintainability and reusability. This transformation can now be used in multiple places without duplicating the logic.

🧰 Tools
🪛 GitHub Check: Test API

[failure] 154-154:
Delete

🪛 GitHub Check: Build API

[failure] 154-154:
Delete


175-179: Good use of the new transformContainer method.

The implementation now uses the extracted transformContainer method, which simplifies this code segment and improves maintainability.


201-210: Method rename aligns with Docker terminology.

Renaming startContainer to start provides better consistency with Docker's native terminology and makes the API more intuitive.


212-226: Excellent enhancement to container stop operation.

The improvements to the stop method are very good:

  1. Adding a 10-second timeout for graceful container shutdown
  2. Implementing a retry mechanism to verify the container has actually stopped
  3. Adding debug logging to help troubleshoot stop operations
  4. Using early return for efficiency when the container has exited

These changes will make container stopping more reliable and easier to debug.

🧰 Tools
🪛 GitHub Check: Test API

[failure] 222-222:
Replace Container·${id}·state·after·stop·attempt·${i+1}:·${updatedContainer?.state} with ⏎················Container·${id}·state·after·stop·attempt·${i·+·1}:·${updatedContainer?.state}⏎············

🪛 GitHub Check: Build API

[failure] 222-222:
Replace Container·${id}·state·after·stop·attempt·${i+1}:·${updatedContainer?.state} with ⏎················Container·${id}·state·after·stop·attempt·${i·+·1}:·${updatedContainer?.state}⏎············

@elibosley elibosley linked an issue Apr 4, 2025 that may be closed by this pull request
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2025

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/1333/dynamix.unraid.net.plg

await container.stop({ t: 10 });
let containers = await this.getContainers({ useCache: false });
let updatedContainer: DockerContainer | undefined;
for (let i = 0; i < 5; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should have messaging here if the attempts exceed the 5 attempts.

@elibosley elibosley merged commit 1bbe7d2 into main Apr 4, 2025
9 checks passed
@elibosley elibosley deleted the fix/docker-mutations-path branch April 4, 2025 16:43
elibosley pushed a commit that referenced this pull request Apr 24, 2025
🤖 I have created a release *beep* *boop*
---


## [4.7.0](v4.6.6...v4.7.0)
(2025-04-24)


### Features

* add basic docker network listing
([#1317](#1317))
([c4fdff8](c4fdff8))
* add permission documentation by using a custom decorator
([#1355](#1355))
([45ecab6](45ecab6))
* basic vm controls ([#1293](#1293))
([bc3ca92](bc3ca92))
* code first graphql
([#1347](#1347))
([f5724ab](f5724ab))


### Bug Fixes

* container names always null
([#1335](#1335))
([8a5b238](8a5b238))
* **deps:** update all non-major dependencies
([#1337](#1337))
([2345732](2345732))
* hide reboot notice for patch releases
([#1341](#1341))
([4b57439](4b57439))
* move docker mutations to the mutations resolver
([#1333](#1333))
([1bbe7d2](1bbe7d2))
* PR build issue
([457d338](457d338))
* remove some unused fields from the report object
([#1342](#1342))
([cd323ac](cd323ac))
* sso unreliable if API outputs more than raw json
([#1353](#1353))
([e65775f](e65775f))
* vms now can detect starting of libvirt and start local hypervisor
([#1356](#1356))
([ad0f4c8](ad0f4c8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query/Mutation dockers start/stop

2 participants